# pankajgurav005/full-stack-nestjs-nextjs architecture

> Architecture diagram of the GitHub repository pankajgurav005/full-stack-nestjs-nextjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pankajgurav005/full-stack-nestjs-nextjs
- Repository: https://github.com/pankajgurav005/full-stack-nestjs-nextjs

## Overview

1. This repository is a two-tier fullstack app: a NestJS backend in `backend/` and a Next.js frontend in `frontend/`. The main architectural boundary is the HTTP API between them; the frontend consumes backend endpoints for authentication and user/profile flows.

2. The backend is modular NestJS. `app.module.ts` wires together feature modules such as `auth`, `users`, `roles`, `hello`, plus infrastructure like `database.module.ts`. This suggests a standard controller/service/module layering with shared cross-cutting concerns in `src/common` and `src/utils`.

3. Data persistence is MongoDB via Mongoose. The backend contains schemas for `users`, `refreshtoken`, and `roles`, so the core domain model is centered on user accounts, role assignment, and token storage/rotation. `config/database.module.ts` is the main database boundary.

4. Authentication is a major subsystem. The `auth` module contains controller, service, DTOs, and JWT-related constants, while `common/guards/at.guard.ts` and `rt.guard.ts` indicate access-token and refresh-token protection. The presence of `get-current-user*` decorators shows authenticated requests are expected to inject identity context into handlers.

5. User management is separated from auth. The `users` module owns user-related controllers/services, creation DTOs, and the user and refresh-token schemas. In practice, auth handles sign-in/sign-up and token issuance, while users handles persistent user profile operations and may support role-based access control.

6. Roles are modeled as a first-class module with its own schema and controller. That implies authorization is not just JWT-based but also role-aware, with role data stored server-side and likely consulted by guards or service logic before serving protected resources.

7. Cross-cutting backend infrastructure includes logging, mail, exception handling, and middleware. `common/service/logger.service.ts`, `loggermiddleware.service.ts`, and `mail.service.ts` show operational concerns around request logging and outbound email. `utils/http-exception.filter.ts` centralizes error shaping, which matters for API consistency across modules.

8. There is a seeding path for initial data. `src/seeder/seeder.ts` and `users.seeder.ts` indicate bootstrap scripts that populate the database, likely for test/demo environments or first-run setup. This is relevant to the architecture because it sits outside the request path but influences initial system state.

9. The backend also includes sample and test-oriented endpoints: `hello` appears to be a lightweight health/demo module, while `backend/test` and the `*.spec.ts` files show unit and e2e coverage with Jest. The repo also includes Docker-related files and multiple `.env.*` variants, so deployment/configuration is environment-driven.

10. The frontend uses Next.js App Router. Pages are organized by route segments such as `signin`, `signup`, `noaccess`, and a protected area under `app/(protected)`. The protected layout wraps authenticated views like `profile` and `about`, which means route grouping is used to separate public and authenticated UI shells.

11. Frontend state and API integration are centralized. `redux/store.js`, `slice.js`, and `providers.js` indicate a Redux-based client state layer, while `utils/api.js` is the likely HTTP client boundary to the NestJS backend. `common/Modalmanager.js` and the shared components in `app/components` suggest UI state like dialogs is managed outside individual pages.

12. The UI composition is split into reusable layout components and page-level views. `Header`, `Sidebar`, and `Modal` form shared presentation scaffolding, while global styles are handled through `globals.css`, `styles/global.css`, and Tailwind config. That makes the frontend architecture more shell-and-pages than a deeply nested component tree.

13. End-to-end, the main user flow is: public signup/login page on the frontend → API call to backend auth endpoints → backend validates credentials, persists or reads user data in MongoDB, issues tokens, and applies role/user guards for protected routes → frontend renders protected pages based on auth state. The `noaccess` page suggests authorization failures are handled explicitly in the UI.

14. For an architecture diagram, the key boxes are: Next.js public/protected UI, Redux/API client, NestJS API layer, auth/users/roles modules, MongoDB schemas, and auxiliary services for logging, mail, seeding, and exception handling. The strongest boundaries are frontend vs backend, auth vs domain modules, and request handling vs infrastructure concerns.

Main entry points: [`frontend/utils/api.js`](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/utils/api.js) (API client), [`backend/src/app.module.ts`](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/app.module.ts) (App module), [`backend/src/auth/auth.module.ts`](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/auth/auth.module.ts) (Auth module), [`backend/src/users/users.module.ts`](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/users.module.ts) (Users module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App Router<br/>Next.js UI shell"]
  node_frontend_public["Public pages<br/>route pages<br/>[page.js]"]
  node_frontend_protected["Protected area<br/>route group"]
  node_frontend_profile["Profile<br/>protected page<br/>[page.js]"]
  node_frontend_about["About<br/>protected page<br/>[page.js]"]
  node_frontend_auth_pages["Auth pages<br/>signin/signup<br/>[page.js]"]
  node_frontend_noaccess["No access<br/>error page<br/>[page.js]"]
  node_frontend_shell["Shared shell<br/>layout/components"]
  node_frontend_state["Client state<br/>redux store<br/>[store.js]"]
  node_frontend_api["API client<br/>HTTP client<br/>[api.js]"]
end

subgraph group_backend["Backend"]
  node_backend_main["Nest bootstrap<br/>entrypoint<br/>[main.ts]"]
  node_backend_app["App module<br/>module composition<br/>[app.module.ts]"]
  node_backend_auth["Auth module<br/>JWT auth<br/>[auth.module.ts]"]
  node_backend_users["Users module<br/>user domain<br/>[users.module.ts]"]
  node_backend_roles["Roles module<br/>authorization domain<br/>[roles.module.ts]"]
  node_backend_db[("Database module<br/>MongoDB/Mongoose<br/>[database.module.ts]")]
  node_backend_common["Common layer<br/>guards/filters/services"]
  node_backend_exception["Exception filter<br/>error handling"]
  node_backend_seeder["Seeder<br/>bootstrap data<br/>[seeder.ts]"]
  node_backend_hello["Hello module<br/>demo endpoint<br/>[hello.module.ts]"]
  node_backend_user_schema[("User schema<br/>mongoose schema<br/>[user.schema.ts]")]
  node_backend_token_schema[("Refresh token<br/>mongoose schema")]
  node_backend_role_schema[("Role schema<br/>mongoose schema<br/>[roles.schema.ts]")]
end

node_frontend_public -->|"auth requests"| node_frontend_api
node_frontend_auth_pages -->|"credentials"| node_frontend_api
node_frontend_profile -->|"profile fetch"| node_frontend_api
node_frontend_state -->|"dispatches"| node_frontend_api
node_frontend_protected -->|"wraps"| node_frontend_shell
node_frontend_app -->|"contains"| node_frontend_public
node_frontend_app -->|"contains"| node_frontend_protected
node_frontend_protected -->|"serves"| node_frontend_profile
node_frontend_protected -->|"serves"| node_frontend_about
node_frontend_noaccess -.->|"auth state"| node_frontend_api
node_backend_main -->|"boots"| node_backend_app
node_backend_app -->|"connects"| node_backend_db
node_backend_app -->|"imports"| node_backend_auth
node_backend_app -->|"imports"| node_backend_users
node_backend_app -->|"imports"| node_backend_roles
node_backend_app -->|"imports"| node_backend_hello
node_backend_auth -->|"reads/writes"| node_backend_user_schema
node_backend_auth -->|"issues/rotates"| node_backend_token_schema
node_backend_users -->|"owns"| node_backend_user_schema
node_backend_users -->|"stores"| node_backend_token_schema
node_backend_roles -->|"owns"| node_backend_role_schema
node_backend_auth -->|"uses"| node_backend_common
node_backend_users -->|"uses"| node_backend_common
node_backend_roles -->|"uses"| node_backend_common
node_backend_app -->|"global filter"| node_backend_exception
node_backend_seeder -->|"seeds"| node_backend_user_schema
node_backend_seeder -->|"seeds"| node_backend_role_schema
node_frontend_api -->|"HTTP API"| node_backend_auth
node_frontend_api -->|"HTTP API"| node_backend_users
node_frontend_api -.->|"HTTP API"| node_backend_roles

click node_frontend_app "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app"
click node_frontend_public "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/page.js"
click node_frontend_protected "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app/(protected)"
click node_frontend_profile "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/(protected)/profile/page.js"
click node_frontend_about "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/(protected)/about/page.js"
click node_frontend_auth_pages "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/signin/page.js"
click node_frontend_noaccess "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/noaccess/page.js"
click node_frontend_shell "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app/components"
click node_frontend_state "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/redux/store.js"
click node_frontend_api "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/utils/api.js"
click node_backend_main "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/main.ts"
click node_backend_app "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/app.module.ts"
click node_backend_auth "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/auth/auth.module.ts"
click node_backend_users "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/users.module.ts"
click node_backend_roles "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/roles/roles.module.ts"
click node_backend_db "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/config/database.module.ts"
click node_backend_common "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/backend/src/common"
click node_backend_exception "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/utils/http-exception.filter.ts"
click node_backend_seeder "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/seeder/seeder.ts"
click node_backend_hello "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/hello/hello.module.ts"
click node_backend_user_schema "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/schemas/user.schema.ts"
click node_backend_token_schema "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/schemas/refreshtoken.schema.ts"
click node_backend_role_schema "https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/roles/schemas/roles.schema.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_public,node_frontend_protected,node_frontend_profile,node_frontend_about,node_frontend_auth_pages,node_frontend_noaccess,node_frontend_shell,node_frontend_state,node_frontend_api toneBlue
class node_backend_main,node_backend_app,node_backend_auth,node_backend_users,node_backend_roles,node_backend_db,node_backend_common,node_backend_exception,node_backend_seeder,node_backend_hello,node_backend_user_schema,node_backend_token_schema,node_backend_role_schema toneAmber
```

## Components

### Frontend

Next.js App Router UI and client state

- [App Router](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app): Next.js UI shell · Public and protected route structure · `frontend/app`
- [Public pages](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/page.js): route pages · Signin, signup, and landing entry points · `frontend/app/page.js`
- [Protected area](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app/(protected)): route group · Authenticated app shell for guarded views · `frontend/app/(protected)`
- [Profile](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/(protected)/profile/page.js): protected page · Authenticated user profile view · `frontend/app/(protected)/profile/page.js`
- [About](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/(protected)/about/page.js): protected page · Protected informational page · `frontend/app/(protected)/about/page.js`
- [Auth pages](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/signin/page.js): signin/signup · Login and registration screens · `frontend/app/signin/page.js`
- [No access](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/app/noaccess/page.js): error page · UI for authorization failures · `frontend/app/noaccess/page.js`
- [Shared shell](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/frontend/app/components): layout/components · Header, sidebar, modal, and protected layout · `frontend/app/components`
- [Client state](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/redux/store.js): redux store · Redux store, slice, and providers · `frontend/redux/store.js`
- [API client](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/frontend/utils/api.js): HTTP client · Frontend boundary to backend endpoints · `frontend/utils/api.js`

### Backend

NestJS API, domain modules, and infrastructure

- [Nest bootstrap](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/main.ts): entrypoint · Application startup and global wiring · `backend/src/main.ts`
- [App module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/app.module.ts): module composition · Top-level Nest module assembly · `backend/src/app.module.ts`
- [Auth module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/auth/auth.module.ts): JWT auth · Sign-in, token issuance, and auth controllers/services · `backend/src/auth/auth.module.ts`
- [Users module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/users.module.ts): user domain · User profile and account persistence logic · `backend/src/users/users.module.ts`
- [Roles module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/roles/roles.module.ts): authorization domain · Role data and role-aware access control · `backend/src/roles/roles.module.ts`
- [Database module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/config/database.module.ts): MongoDB/Mongoose · Persistence wiring and connection setup · `backend/src/config/database.module.ts`
- [Common layer](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/tree/main/backend/src/common): guards/filters/services · Shared decorators, guards, logging, and mail · `backend/src/common`
- [Exception filter](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/utils/http-exception.filter.ts): error handling · Centralized HTTP error shaping · `backend/src/utils/http-exception.filter.ts`
- [Seeder](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/seeder/seeder.ts): bootstrap data · Initial database population scripts · `backend/src/seeder/seeder.ts`
- [Hello module](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/hello/hello.module.ts): demo endpoint · Lightweight sample or health-style module · `backend/src/hello/hello.module.ts`
- [User schema](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/schemas/user.schema.ts): mongoose schema · Persistent user account model · `backend/src/users/schemas/user.schema.ts`
- [Refresh token](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/users/schemas/refreshtoken.schema.ts): mongoose schema · Stored refresh token model · `backend/src/users/schemas/refreshtoken.schema.ts`
- [Role schema](https://github.com/pankajgurav005/full-stack-nestjs-nextjs/blob/main/backend/src/roles/schemas/roles.schema.ts): mongoose schema · Stored role model · `backend/src/roles/schemas/roles.schema.ts`

## Connections

- Public pages → API client: auth requests · Public screens submit sign-in and sign-up calls
- Auth pages → API client: credentials · Authentication forms call backend auth endpoints
- Profile → API client: profile fetch · Protected views load user data from the API
- Client state → API client: dispatches · Redux state is fed by API responses
- Protected area → Shared shell: wraps · Protected route group uses shared app shell
- App Router → Public pages: contains · App router contains public entry routes
- App Router → Protected area: contains · App router contains authenticated routes
- Protected area → Profile: serves · Protected area includes profile page
- Protected area → About: serves · Protected area includes about page
- No access → API client: auth state · No-access page reflects authorization outcome
- Nest bootstrap → App module: boots · Entry point starts the Nest application
- App module → Database module: connects · App module wires database infrastructure
- App module → Auth module: imports · Top-level composition includes auth module
- App module → Users module: imports · Top-level composition includes users module
- App module → Roles module: imports · Top-level composition includes roles module
- App module → Hello module: imports · Top-level composition includes hello module
- Auth module → User schema: reads/writes · Auth uses user records for sign-in and signup
- Auth module → Refresh token: issues/rotates · Auth manages refresh token lifecycle
- Users module → User schema: owns · Users module owns persistent user model
- Users module → Refresh token: stores · Users module manages refresh token storage
- Roles module → Role schema: owns · Roles module owns role model
- Auth module → Common layer: uses · Auth depends on guards and decorators
- Users module → Common layer: uses · Users depend on shared request context helpers
- Roles module → Common layer: uses · Roles may rely on guards and shared middleware
- App module → Exception filter: global filter · Application applies centralized error handling
- Seeder → User schema: seeds · Bootstrap data populates users
- Seeder → Role schema: seeds · Bootstrap data populates roles
- API client → Auth module: HTTP API · Frontend consumes backend auth endpoints
- API client → Users module: HTTP API · Frontend consumes user/profile endpoints
- API client → Roles module: HTTP API · Frontend may consume role-aware endpoints
