# nishargshah/nextjs-fullstack-typescript-boilerplate architecture

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

- Interactive diagram: https://gitdiagram.com/nishargshah/nextjs-fullstack-typescript-boilerplate
- Repository: https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate

## Overview

##### Project type and purpose
- This is a full‑stack web application built on Next.js (v13+ with the App Router), React and TypeScript.
- The frontend and backend live in one monolithic Next.js codebase: UI pages, API routes, middleware, state management, and mocks.
- It uses React Query for server‑state, Zustand for client‑state, cookie‐based auth flows, plus Docker and GitHub Actions for CI/CD.

##### File structure
- Top‑level “src/app” holds all React pages and Next.js API route handlers:
– src/app/(public) & (auth) → public vs. protected page layouts and routes
– src/app/api → Next.js serverless functions grouped under “auth”, “protected” and shared utils/mocks
- src/api contains client‑side HTTP wrappers (axios.ts, endpoints.ts, catchAsync.ts) used by React Query and features.
- src/features drives the presentation–API boundary: hooks + typed API functions per domain (auth, users, profile).
- src/store & src/providers host global client‑state (Zustand slices, providers).
- config, constants, lib, utils provide cross‑cutting code.
- Middleware (middleware.ts) sits at the Next.js edge.
- Dev tools: Dockerfile, GitHub Actions workflow, pnpm workspace, ESLint/Prettier, Husky + lint‑staged.

##### Insights from the README
- It confirms the stack: Next.js, TS, React Query, Zustand, cookie auth, fully typed, strict linting, Docker + GH Actions.
- Emphasis on pre‑commit hooks, coding standards, pnpm usage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser / Client Zone
    subgraph "Browser / Client"
        UI["UI Pages"]:::frontend
        State["Zustand State Management"]:::frontend
        Query["React Query & Axios Wrapper"]:::frontend
        Cookie["Auth Cookie Store"]:::frontend
    end

    %% Next.js Server Zone
    subgraph "Next.js Server"
        SSR["SSR/SSG Rendering"]:::backend
        MW["Middleware (Auth Checks)"]:::backend

        subgraph "API Routes"
            AL["/api/auth/login"]:::backend
            PM["/api/(protected)/user/profile/me"]:::backend
            PO["/api/(protected)/user/profile/logout"]:::backend
            UR["/api/(protected)/users"]:::backend
            RI["/api/route.ts"]:::backend
        end

        subgraph "Shared Server Logic"
            GB["getBody()"]:::shared
            GU["getUserData()"]:::shared
            SR["sendRes()"]:::shared
            SE["sendError()"]:::shared
            CS["Constants"]:::shared
            TS["Types"]:::shared
            MU["Mock Users Data"]:::shared
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MD["Mock Data Module"]:::shared
    end

    %% DevOps & Tooling
    subgraph "DevOps & Tooling"
        DF["Dockerfile"]:::devops
        GH["GitHub Actions CI/CD"]:::devops
        LT["ESLint/Prettier/Husky"]:::devops
    end

    %% Interactions
    UI -->|"render via"| SSR
    SSR -->|"delivers HTML"| UI
    UI -->|"calls"| Query
    Query -->|"POST /login"| AL
    Query -->|"GET /user/profile/me"| PM
    Query -->|"POST /user/profile/logout"| PO
    Query -->|"GET /users"| UR
    AL -->|"uses"| GB
    AL -->|"uses"| CS
    AL -->|"uses"| TS
    AL -->|"responds via"| SR
    AL -->|"errors via"| SE
    PM -->|"uses"| GU
    PM -->|"uses"| TS
    PM -->|"responds via"| SR
    UR -->|"uses"| MU
    UR -->|"responds via"| SR
    PO -->|"uses"| GU
    PO -->|"responds via"| SR

    MW -->|"intercepts"| AL
    MW -->|"intercepts"| PM
    MW -->|"intercepts"| UR
    MW -->|"intercepts"| PO

    MU -->|"source for"| GU
    MD -->|"provides mocks for"| MU

    SR -->|"returns JSON"| Query
    SE -->|"returns error"| Query

    AL -->|"sets auth cookie"| Cookie
    Cookie -->|"sent with"| AL
    Cookie -->|"sent with"| PM
    Cookie -->|"sent with"| PO

    DF --> GH
    GH --> LT

    %% Click Events
    click UI "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/tree/master/src/app"
    click State "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/store/index.ts"
    click Query "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/api/axios.ts"
    click AL "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/auth/login/route.ts"
    click PM "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/(protected)/user/profile/me/route.ts"
    click PO "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/(protected)/user/profile/logout/route.ts"
    click UR "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/(protected)/users/route.ts"
    click RI "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/route.ts"
    click GB "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/functions/getBody.ts"
    click GU "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/functions/getUserData.ts"
    click SR "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/functions/sendRes.ts"
    click SE "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/functions/sendError.ts"
    click CS "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/constants/index.ts"
    click TS "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/types/index.ts"
    click MU "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/blob/master/src/app/api/_/mock/users.ts"
    click DF "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/tree/master/Dockerfile"
    click GH "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/tree/master/.github/workflows"
    click LT "https://github.com/nishargshah/nextjs-fullstack-typescript-boilerplate/tree/master/.husky/pre-commit"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3B82F6,color:#0C4A6E
    classDef backend fill:#D1FAE5,stroke:#10B981,color:#065F46
    classDef shared fill:#FEF3C7,stroke:#FBBF24,color:#92400E
    classDef devops fill:#E5E7EB,stroke:#6B7280,color:#1F2937
```
