# sanju1098/fullstack-authentication-system architecture

> Architecture diagram of the GitHub repository sanju1098/fullstack-authentication-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sanju1098/fullstack-authentication-system
- Repository: https://github.com/sanju1098/fullstack-authentication-system

## Overview

This is a React frontend backed by an Express authentication API, with DummyJSON supplying credential verification and upstream tokens. The main workflow runs from login through frontend auth state, backend validation and session creation, then cookie-backed session restoration, refresh/retry, protected dashboard access, and logout. The graph preserves the distinct UI, request, API, session, and provider stages. Some listed modules were not excerpted; relationships involving them are included only where the README or SOURCE INDEX supports them.

Main entry points: [`src/context/AuthContext.tsx`](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/context/AuthContext.tsx) (Auth state), [`backend-server/src/controllers/auth.controller.ts`](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/controllers/auth.controller.ts) (Auth controllers), [`src/services/api.ts`](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/api.ts) (API client), [`backend-server/src/routes/auth.routes.ts`](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/routes/auth.routes.ts) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend experience"]
  node_app_routes["App routes<br/>[AppRoutes.tsx]"]
  node_login_page["Login page<br/>[Login.tsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_protected_routes["Route guards<br/>[ProtectedRoute.tsx]"]
  node_loader["Session loader<br/>[Loader.tsx]"]
end

subgraph group_client_auth["Client authentication"]
  node_auth_hook["Auth hook<br/>[useAuth.ts]"]
  node_auth_context["Auth state<br/>[AuthContext.tsx]"]
  node_frontend_auth["Auth requests<br/>[auth.service.ts]"]
  node_api_client["API client<br/>[api.ts]"]
  node_token_store["Token store<br/>[token.store.ts]"]
  node_auth_types["Auth types<br/>[auth.types.ts]"]
end

subgraph group_backend_api["Backend API"]
  node_express_server["API server<br/>[server.ts]"]
  node_auth_routes["Auth routes<br/>[auth.routes.ts]"]
  node_validation["Login validation"]
  node_auth_schema["Login schema<br/>[auth.schema.ts]"]
  node_auth_controller["Auth controllers<br/>[auth.controller.ts]"]
  node_auth_service["Provider service<br/>[auth.service.ts]"]
  node_error_middleware["Error handling"]
end

subgraph group_backend_state["Backend session state"]
  node_cookie_utils["Cookie handling<br/>[cookies.ts]"]
  node_session_store[("Session store<br/>[session.store.ts]")]
end

node_user(("User"))
node_dummyjson["DummyJSON auth"]

node_user -->|"submits credentials"| node_login_page
node_login_page -->|"uses auth"| node_auth_hook
node_auth_hook -->|"reads state"| node_auth_context
node_auth_context -->|"calls auth requests"| node_frontend_auth
node_auth_context -->|"sets failure handler"| node_api_client
node_auth_context -->|"clears tokens"| node_token_store
node_frontend_auth -->|"sends requests"| node_api_client
node_frontend_auth -->|"uses types"| node_auth_types
node_auth_context -->|"uses types"| node_auth_types
node_api_client -->|"calls API"| node_auth_routes
node_api_client -->|"notifies auth failure"| node_auth_context
node_app_routes -->|"routes to"| node_login_page
node_app_routes -->|"guards access"| node_protected_routes
node_protected_routes -->|"checks auth"| node_auth_hook
node_protected_routes -->|"renders loading"| node_loader
node_app_routes -->|"routes to"| node_dashboard
node_dashboard -->|"reads auth"| node_auth_hook
node_express_server -->|"mounts routes"| node_auth_routes
node_express_server -->|"registers errors"| node_error_middleware
node_auth_routes -->|"validates login"| node_validation
node_validation -->|"checks schema"| node_auth_schema
node_auth_routes -->|"dispatches requests"| node_auth_controller
node_auth_controller -->|"calls services"| node_auth_service
node_auth_controller -->|"creates and rotates sessions"| node_session_store
node_auth_controller -->|"sets and clears cookies"| node_cookie_utils
node_auth_service -->|"authenticates and refreshes"| node_dummyjson

click node_app_routes "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/routes/AppRoutes.tsx"
click node_login_page "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/pages/auth/Login.tsx"
click node_dashboard "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/pages/dashboard/Dashboard.tsx"
click node_protected_routes "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/routes/ProtectedRoute.tsx"
click node_loader "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/components/common/Loader.tsx"
click node_auth_hook "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/hooks/useAuth.ts"
click node_auth_context "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/context/AuthContext.tsx"
click node_frontend_auth "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/auth.service.ts"
click node_api_client "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/api.ts"
click node_token_store "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/token.store.ts"
click node_auth_types "https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/types/auth.types.ts"
click node_express_server "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/server.ts"
click node_auth_routes "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/routes/auth.routes.ts"
click node_validation "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/middleware/validate.middleware.ts"
click node_auth_schema "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/schemas/auth.schema.ts"
click node_auth_controller "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/controllers/auth.controller.ts"
click node_auth_service "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/services/auth.service.ts"
click node_cookie_utils "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/utils/cookies.ts"
click node_session_store "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/utils/session.store.ts"
click node_error_middleware "https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/middleware/error.middleware.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_app_routes,node_login_page,node_dashboard,node_protected_routes,node_loader,node_user toneBlue
class node_auth_hook,node_auth_context,node_frontend_auth,node_api_client,node_token_store,node_auth_types toneAmber
class node_express_server,node_auth_routes,node_validation,node_auth_schema,node_auth_controller,node_auth_service,node_error_middleware toneMint
class node_cookie_utils,node_session_store toneRose
class node_dummyjson toneIndigo
```

## Components

### Frontend experience

- [App routes](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/routes/AppRoutes.tsx): `src/routes/AppRoutes.tsx`
- [Login page](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/pages/auth/Login.tsx): `src/pages/auth/Login.tsx`
- [Dashboard](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/pages/dashboard/Dashboard.tsx): `src/pages/dashboard/Dashboard.tsx`
- [Route guards](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/routes/ProtectedRoute.tsx): `src/routes/ProtectedRoute.tsx`
- [Session loader](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/components/common/Loader.tsx): `src/components/common/Loader.tsx`

### Client authentication

- [Auth hook](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/hooks/useAuth.ts): `src/hooks/useAuth.ts`
- [Auth state](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/context/AuthContext.tsx): `src/context/AuthContext.tsx`
- [Auth requests](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/auth.service.ts): `src/services/auth.service.ts`
- [API client](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/api.ts): `src/services/api.ts`
- [Token store](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/services/token.store.ts): `src/services/token.store.ts`
- [Auth types](https://github.com/sanju1098/fullstack-authentication-system/blob/main/src/types/auth.types.ts): `src/types/auth.types.ts`

### Backend API

- [API server](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/server.ts): `backend-server/src/server.ts`
- [Auth routes](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/routes/auth.routes.ts): `backend-server/src/routes/auth.routes.ts`
- [Login validation](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/middleware/validate.middleware.ts): `backend-server/src/middleware/validate.middleware.ts`
- [Login schema](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/schemas/auth.schema.ts): `backend-server/src/schemas/auth.schema.ts`
- [Auth controllers](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/controllers/auth.controller.ts): `backend-server/src/controllers/auth.controller.ts`
- [Provider service](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/services/auth.service.ts): `backend-server/src/services/auth.service.ts`
- [Error handling](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/middleware/error.middleware.ts): `backend-server/src/middleware/error.middleware.ts`

### Backend session state

- [Cookie handling](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/utils/cookies.ts): `backend-server/src/utils/cookies.ts`
- [Session store](https://github.com/sanju1098/fullstack-authentication-system/blob/main/backend-server/src/utils/session.store.ts): `backend-server/src/utils/session.store.ts`

### Other components

- **User**
- **DummyJSON auth**

## Connections

- User → Login page: submits credentials (evidence: `README.md`)
- Login page → Auth hook: uses auth (evidence: `src/pages/auth/Login.tsx`)
- Auth hook → Auth state: reads state (evidence: `src/hooks/useAuth.ts`)
- Auth state → Auth requests: calls auth requests (evidence: `src/context/AuthContext.tsx`)
- Auth state → API client: sets failure handler (evidence: `src/context/AuthContext.tsx`)
- Auth state → Token store: clears tokens (evidence: `src/context/AuthContext.tsx`)
- Auth requests → API client: sends requests (evidence: `src/services/auth.service.ts`)
- Auth requests → Auth types: uses types (evidence: `src/services/auth.service.ts`)
- Auth state → Auth types: uses types (evidence: `src/context/AuthContext.tsx`)
- API client → Auth routes: calls API (evidence: `README.md`)
- API client → Auth state: notifies auth failure (evidence: `src/context/AuthContext.tsx`)
- App routes → Login page: routes to (evidence: `src/routes/AppRoutes.tsx`)
- App routes → Route guards: guards access (evidence: `src/routes/AppRoutes.tsx`)
- Route guards → Auth hook: checks auth (evidence: `src/routes/ProtectedRoute.tsx`)
- Route guards → Session loader: renders loading (evidence: `src/routes/ProtectedRoute.tsx`)
- App routes → Dashboard: routes to (evidence: `src/routes/AppRoutes.tsx`)
- Dashboard → Auth hook: reads auth (evidence: `src/pages/dashboard/Dashboard.tsx`)
- API server → Auth routes: mounts routes (evidence: `backend-server/src/server.ts`)
- API server → Error handling: registers errors (evidence: `backend-server/src/server.ts`)
- Auth routes → Login validation: validates login (evidence: `backend-server/src/routes/auth.routes.ts`)
- Login validation → Login schema: checks schema (evidence: `backend-server/src/middleware/validate.middleware.ts`)
- Auth routes → Auth controllers: dispatches requests (evidence: `backend-server/src/routes/auth.routes.ts`)
- Auth controllers → Provider service: calls services (evidence: `backend-server/src/controllers/auth.controller.ts`)
- Auth controllers → Session store: creates and rotates sessions (evidence: `backend-server/src/controllers/auth.controller.ts`)
- Auth controllers → Cookie handling: sets and clears cookies (evidence: `backend-server/src/controllers/auth.controller.ts`)
- Provider service → DummyJSON auth: authenticates and refreshes (evidence: `backend-server/src/services/auth.service.ts`)
