# doanlequocphong/nextjs-v13 architecture

> Architecture diagram of the GitHub repository doanlequocphong/nextjs-v13, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/doanlequocphong/nextjs-v13
- Repository: https://github.com/doanlequocphong/nextjs-v13

## Overview

##### Project type and purpose
- This is a Next.js–based full-stack web application.
- It serves React pages (SSR/SSG) under `src/pages/*.tsx` and provides simple API endpoints as server-side functions under `src/pages/api/*.ts`.
- It includes Docker/Docker Compose configurations for containerized development and deployment.

##### File structure
- Top-level config and orchestration:
- `.env.example`, `Dockerfile`, `docker-compose.yml`, `next.config.js`, `tsconfig.json`, linting & ignore files.
- Application code under `src/`:
- `src/pages/` – React pages (`index.tsx`) and API routes (`api/hello.ts`).
- `src/styles/` – CSS modules and global styles.
- `public/` holds static assets (images, favicons, etc.).
- Scripts and dependencies in `package.json`.

##### README for additional insights
- Describes dev workflow (`npm run dev`), automatic page refresh, file-based routing, API route mapping, and Next.js font-optimization.
- Mentions Vercel as the intended deployment target but also provides Docker support.

a. Main components
- User’s Web Browser (Client)
- Next.js Server
– Page Renderer (SSR/SSG)
– API Function Runner (Node.js Lambdas)
- Static Asset Server (serving `/public` files)
- Docker/Container Orchestrator (in dev or on-prem)
- External Deployment Platform (e.g., Vercel or any Docker host)
b. Relationships and interactions
1. Client → HTTP GET `/` or other page → Next.js Server
2. Next.js Server → Page Renderer → returns HTML/CSS/JS
3. Page (in browser) may fetch JSON → HTTP GET `/api/hello` → API Function Runner → returns JSON
4. Static assets requested → served directly from `public/`
5. All services run in one container (via Docker Compose) or N-1 containers on Vercel
c. Architectural patterns/design principles
- File-based routing (pages vs API routes)
- SSR/SSG hybrid rendering model
- Separation of concerns: UI layer vs business logic in API routes
- Containerization for environment consistency
d. Key technologies/frameworks
- Next.js (React, SSR/SSG, API routes)
- Node.js (runtime for API routes)
- TypeScript (static typing)
- CSS Modules & global CSS (styling)
- Docker & Docker Compose (containerization)
- Vercel (cloud hosting)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        Browser["Web Browser"]:::frontend
        PageRenderer["Page Renderer (SSR/SSG)"]:::frontend
        Styling["Styling Layer (CSS Modules & Global Styles)"]:::frontend
    end

    subgraph "Backend Layer"
        NextServer["Next.js Server"]:::backend
        APIRunner["API Function Runner"]:::backend
        StaticAssets["Static Asset Server"]:::backend
    end

    subgraph "Infrastructure"
        Build["Build (npm build)"]:::infra
        Docker["Docker / Container Orchestrator"]:::infra
        Deployment["Deployment Platform (Vercel / Docker Host)"]:::infra
        Docs["Documentation"]:::infra
    end

    Browser -->|"GET /"| NextServer
    NextServer -->|"render/page"| PageRenderer
    PageRenderer -->|"HTML/CSS/JS"| Browser
    Browser -->|"GET /api/hello"| APIRunner
    APIRunner -->|"JSON"| Browser
    Browser -->|"GET /static asset"| StaticAssets
    StaticAssets -->|"asset"| Browser
    Build -->|"Docker Image"| Docker
    Docker -->|"run Next.js"| NextServer
    Docker -->|"run API"| APIRunner
    Docs -->|"guidance"| Docker
    Docs -->|"guidance"| NextServer

    click NextServer "https://github.com/doanlequocphong/nextjs-v13/blob/main/next.config.js"
    click NextServer "https://github.com/doanlequocphong/nextjs-v13/blob/main/tsconfig.json"
    click NextServer "https://github.com/doanlequocphong/nextjs-v13/blob/main/package.json"
    click PageRenderer "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/pages/index.tsx"
    click PageRenderer "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/pages/_app.tsx"
    click PageRenderer "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/pages/_document.tsx"
    click APIRunner "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/pages/api/hello.ts"
    click StaticAssets "https://github.com/doanlequocphong/nextjs-v13/tree/main/public/"
    click Styling "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/styles/Home.module.css"
    click Styling "https://github.com/doanlequocphong/nextjs-v13/blob/main/src/styles/globals.css"
    click Docker "https://github.com/doanlequocphong/nextjs-v13/tree/main/Dockerfile"
    click Docker "https://github.com/doanlequocphong/nextjs-v13/blob/main/Dockerfile.npm"
    click Docker "https://github.com/doanlequocphong/nextjs-v13/blob/main/docker-compose.yml"
    click Docker "https://github.com/doanlequocphong/nextjs-v13/blob/main/README_DOCKER.md"
    click Docs "https://github.com/doanlequocphong/nextjs-v13/blob/main/README.md"
    click Docs "https://github.com/doanlequocphong/nextjs-v13/blob/main/README_GIT.md"

    classDef frontend fill:#D6EAF8,stroke:#3498DB,color:#154360
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#145A32
    classDef infra fill:#FCF3CF,stroke:#F39C12,color:#7E5109
```
