CodebaseSrc
(app)
Next.js 16 App Router entry point providing routing, layouts, pages, server actions, and API endpoints.
App Directory (app/)
Next.js 16 App Router entry point providing routing, layouts, pages, server actions, and API endpoints.
Purpose
Defines the user-facing application structure using the Next.js App Router:
- File-based routing (folders become URL paths)
- Server and client component orchestration
- Server actions for form handling
- API routes for REST endpoints
- Layouts for shared UI structure
Structure
The app directory is organized by feature and route:
app/
βββ layout.tsx # Root layout (theme, nav, header, footer)
βββ page.tsx # Home page (/)
βββ actions/ # Server actions (geocoding, bulk processing)
βββ api/ # API routes (system status, testing endpoints)
βββ lookup/ # Single address lookup page (/lookup)
βββ bulk/ # Bulk address processing page (/bulk)
βββ test-api/ # API testing interface (/test-api)
βββ system-status/ # System health monitoring (/system-status)
Next.js App Router Concepts
File Conventions
layout.tsx: Shared UI wrapper for route segmentspage.tsx: Unique page content for a routeroute.ts: API endpoints (GET, POST, etc.)loading.tsx: Loading UI during data fetchingerror.tsx: Error boundary for route segment
Server vs Client Components
- Server Components (default): Render on server, can directly access backend resources
- Client Components (
"use client"): Interactive UI with hooks, event handlers, browser APIs
Server Actions
Functions marked with "use server" that run on the server but can be called from client components:
- Type-safe client-to-server communication
- Form handling with progressive enhancement
- No manual API route setup required
Routes
The application provides these user-facing pages:
/- Landing page with feature overview/lookup- Single address lookup with autocomplete/bulk- Bulk address processing (up to 1,000 addresses)/test-api- API testing interface for developers/system-status- Real-time health monitoring dashboard
API Endpoints
REST endpoints for programmatic access:
GET /api/system-status- Health check and cache statisticsGET /api/system-status?checkApis=true- Deep health check with external API verification
Architecture Integration
The app layer sits at the top of the clean architecture:
App Router (Presentation)
β calls
Server Actions / Pages
β executes
Domain Use Cases
β depends on
Ports (interfaces)
β implemented by
Adapters (NJ API, Cache, HTTP)
Key Features
- SSR/SSG: Server-side rendering and static generation for performance
- Streaming: Progressive page rendering with React Server Components
- Parallel Routes: Simultaneous page segments with independent loading states
- Intercepting Routes: Modal-like overlays without page navigation
- Route Groups: Organize routes without affecting URL structure
- Metadata API: SEO-friendly page metadata and Open Graph tags
Development
Creating New Routes
- Create a folder in
app/matching the desired URL path - Add
page.tsxfor the page content - Optionally add
layout.tsxfor shared UI - Add
loading.tsxfor loading states - Add
error.tsxfor error boundaries
Adding Server Actions
- Create action file in
app/actions/with"use server"directive - Export async functions that return serializable data
- Import and call from client components with
useTransitionor form actions
Creating API Routes
- Create
route.tsin desired path (e.g.,app/api/foo/route.tsβ/api/foo) - Export HTTP method handlers:
GET,POST,PUT,DELETE, etc. - Return
NextResponse.json()with typed data
Testing
- E2E Tests: Playwright tests in
src/__tests__/e2e/navigate actual routes - Integration Tests: Server action tests verify form handling
- Unit Tests: Page component tests with React Testing Library
Related Documentation
- actions/ - Server actions for form handling
- api/ - API route handlers
- Domain Use Cases - Business logic called by actions
- Components - React components used in pages