# sriyakat/nodejs-auth-system architecture

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

- Interactive diagram: https://gitdiagram.com/sriyakat/nodejs-auth-system
- Repository: https://github.com/sriyakat/nodejs-auth-system

## Overview

This is an Express authentication and product-management API. Clients register, log in, and use access tokens to reach protected profile, admin, and product endpoints; product operations return records through the API. Authentication includes password hashing, token issuance and refresh-token persistence, logout, and password reset. Product CRUD is a separate domain branch, with admin-only writes. The graph follows the sampled route, controller, service, repository, and database layers; product-repository behavior is represented from its indexed database reference, while unsampled details are omitted.

Main entry points: [`src/modules/auth/auth.routes.js`](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.routes.js) (Auth routes), [`src/app.js`](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/app.js) (Express app), [`src/modules/product/product.routes.js`](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.routes.js) (Product routes), [`src/config/db.js`](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/config/db.js) (SQL connection pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_server["HTTP server<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
end

subgraph group_authentication["Authentication"]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_auth_validation["Input validation<br/>[auth.validation.js]"]
  node_auth_controller["Auth controller<br/>[auth.controller.js]"]
  node_auth_service["Auth service<br/>[auth.service.js]"]
  node_auth_middleware["Token and role guards<br/>[auth.middleware.js]"]
end

subgraph group_products["Product management"]
  node_product_routes["Product routes<br/>[product.routes.js]"]
  node_product_controller["Product controller"]
  node_product_service["Product service<br/>[product.service.js]"]
end

subgraph group_persistence["Persistence"]
  node_auth_repository["Auth repository<br/>[auth.repository.js]"]
  node_product_repository["Product repository"]
  node_db_config["SQL connection pool<br/>[db.js]"]
end

node_client(("API client"))
node_sql_server[("SQL Server")]

node_client -->|"sends HTTP"| node_app
node_server -->|"listens on"| node_app
node_app -->|"mounts auth"| node_auth_routes
node_app -->|"mounts products"| node_product_routes
node_auth_routes -->|"validates input"| node_auth_validation
node_auth_routes -->|"dispatches handlers"| node_auth_controller
node_auth_routes -->|"guards routes"| node_auth_middleware
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"executes auth actions"| node_auth_repository
node_auth_repository -->|"uses SQL pool"| node_db_config
node_product_routes -->|"dispatches handlers"| node_product_controller
node_product_routes -->|"guards routes"| node_auth_middleware
node_product_controller -->|"calls"| node_product_service
node_product_service -->|"executes product actions"| node_product_repository
node_product_repository -->|"uses SQL pool"| node_db_config
node_db_config -->|"connects to"| node_sql_server

click node_server "https://github.com/sriyakat/nodejs-auth-system/blob/main/server.js"
click node_app "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/app.js"
click node_auth_routes "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.routes.js"
click node_auth_validation "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.validation.js"
click node_auth_controller "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.controller.js"
click node_auth_service "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.service.js"
click node_auth_middleware "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/middleware/auth.middleware.js"
click node_auth_repository "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.repository.js"
click node_product_routes "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.routes.js"
click node_product_controller "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.controller.js"
click node_product_service "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.service.js"
click node_product_repository "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.repository.js"
click node_db_config "https://github.com/sriyakat/nodejs-auth-system/blob/main/src/config/db.js"

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_server,node_app,node_client toneBlue
class node_auth_routes,node_auth_validation,node_auth_controller,node_auth_service,node_auth_middleware,node_sql_server toneAmber
class node_product_routes,node_product_controller,node_product_service toneMint
class node_auth_repository,node_product_repository,node_db_config toneRose
```

## Components

### API runtime

- [HTTP server](https://github.com/sriyakat/nodejs-auth-system/blob/main/server.js): `server.js`
- [Express app](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/app.js): `src/app.js`

### Authentication

- [Auth routes](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.routes.js): `src/modules/auth/auth.routes.js`
- [Input validation](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.validation.js): `src/modules/auth/auth.validation.js`
- [Auth controller](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.controller.js): `src/modules/auth/auth.controller.js`
- [Auth service](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.service.js): `src/modules/auth/auth.service.js`
- [Token and role guards](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/middleware/auth.middleware.js): `src/middleware/auth.middleware.js`

### Product management

- [Product routes](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.routes.js): `src/modules/product/product.routes.js`
- [Product controller](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.controller.js): `src/modules/product/product.controller.js`
- [Product service](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.service.js): `src/modules/product/product.service.js`

### Persistence

- [Auth repository](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/auth/auth.repository.js): `src/modules/auth/auth.repository.js`
- [Product repository](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/modules/product/product.repository.js): `src/modules/product/product.repository.js`
- [SQL connection pool](https://github.com/sriyakat/nodejs-auth-system/blob/main/src/config/db.js): `src/config/db.js`

### Other components

- **API client**
- **SQL Server**

## Connections

- API client → Express app: sends HTTP (evidence: `src/app.js`)
- HTTP server → Express app: listens on (evidence: `server.js`)
- Express app → Auth routes: mounts auth (evidence: `src/app.js`)
- Express app → Product routes: mounts products (evidence: `src/app.js`)
- Auth routes → Input validation: validates input (evidence: `src/modules/auth/auth.routes.js`)
- Auth routes → Auth controller: dispatches handlers (evidence: `src/modules/auth/auth.routes.js`)
- Auth routes → Token and role guards: guards routes (evidence: `src/modules/auth/auth.routes.js`)
- Auth controller → Auth service: calls (evidence: `src/modules/auth/auth.controller.js`)
- Auth service → Auth repository: executes auth actions (evidence: `src/modules/auth/auth.service.js`)
- Auth repository → SQL connection pool: uses SQL pool (evidence: `src/modules/auth/auth.repository.js`)
- Product routes → Product controller: dispatches handlers (evidence: `src/modules/product/product.routes.js`)
- Product routes → Token and role guards: guards routes (evidence: `src/modules/product/product.routes.js`)
- Product controller → Product service: calls (evidence: `src/modules/product/product.controller.js`)
- Product service → Product repository: executes product actions (evidence: `src/modules/product/product.service.js`)
- Product repository → SQL connection pool: uses SQL pool (evidence: `src/modules/product/product.repository.js`)
- SQL connection pool → SQL Server: connects to (evidence: `src/config/db.js`)
