# calladitya/authentication-system architecture

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

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

## Overview

This is an Express authentication API. Requests enter through the server and auth routes, then the controller handles registration, login, profile lookup, session refresh/logout, and OTP verification using MongoDB models and email/OTP helpers. The README describes protected routes, but the sampled routes show no authorization middleware, so none is represented. Controller excerpts are partial; links among its workflows and storage are limited to relationships visible in those excerpts or the source index.

Main entry points: [`src/controller/auth.controller.js`](https://github.com/calladitya/authentication-system/blob/main/src/controller/auth.controller.js) (Auth controller), [`server.js`](https://github.com/calladitya/authentication-system/blob/main/server.js) (HTTP server), [`src/config/database.js`](https://github.com/calladitya/authentication-system/blob/main/src/config/database.js) (DB connector), [`src/app.js`](https://github.com/calladitya/authentication-system/blob/main/src/app.js) (Express app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_server["HTTP server<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
  node_routes["Auth routes<br/>[auth.routes.js]"]
  node_config["Environment config<br/>[config.js]"]
end

subgraph group_identity["Identity workflows"]
  node_controller["Auth controller<br/>[auth.controller.js]"]
  node_otp_helpers["OTP helpers<br/>[utils.js]"]
end

subgraph group_persistence["Persistence"]
  node_db_connector["DB connector<br/>[database.js]"]
  node_users[("User records<br/>[user.model.js]")]
  node_sessions[("Session records<br/>[session.model.js]")]
  node_otps[("OTP records<br/>[otp.model.js]")]
end

subgraph group_messaging["Email verification"]
  node_email_service["Email service<br/>[email.service.js]"]
end

node_client(("API client"))
node_mongo[("MongoDB")]
node_gmail["Gmail SMTP"]
node_jwt["JWT library"]
node_bcrypt["bcrypt library"]

node_client -->|"sends requests"| node_server
node_server -->|"starts"| node_app
node_server -->|"loads"| node_config
node_server -->|"connects"| node_db_connector
node_db_connector -->|"reads URI"| node_config
node_db_connector -->|"connects"| node_mongo
node_app -->|"mounts"| node_routes
node_routes -->|"dispatches"| node_controller
node_controller -->|"reads/writes"| node_users
node_controller -->|"reads/writes"| node_sessions
node_controller -->|"reads/writes"| node_otps
node_controller -->|"generates OTP"| node_otp_helpers
node_controller -->|"sends verification"| node_email_service
node_email_service -->|"sends email"| node_gmail
node_controller -->|"signs/verifies tokens"| node_jwt
node_controller -->|"hashes/checks"| node_bcrypt

click node_server "https://github.com/calladitya/authentication-system/blob/main/server.js"
click node_app "https://github.com/calladitya/authentication-system/blob/main/src/app.js"
click node_routes "https://github.com/calladitya/authentication-system/blob/main/src/routes/auth.routes.js"
click node_controller "https://github.com/calladitya/authentication-system/blob/main/src/controller/auth.controller.js"
click node_otp_helpers "https://github.com/calladitya/authentication-system/blob/main/src/utils/utils.js"
click node_config "https://github.com/calladitya/authentication-system/blob/main/src/config/config.js"
click node_db_connector "https://github.com/calladitya/authentication-system/blob/main/src/config/database.js"
click node_users "https://github.com/calladitya/authentication-system/blob/main/src/models/user.model.js"
click node_sessions "https://github.com/calladitya/authentication-system/blob/main/src/models/session.model.js"
click node_otps "https://github.com/calladitya/authentication-system/blob/main/src/models/otp.model.js"
click node_email_service "https://github.com/calladitya/authentication-system/blob/main/src/service/email.service.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_routes,node_config,node_client toneBlue
class node_controller,node_otp_helpers,node_mongo toneAmber
class node_db_connector,node_users,node_sessions,node_otps toneMint
class node_email_service toneRose
class node_gmail,node_jwt,node_bcrypt toneIndigo
```

## Components

### API runtime

- [HTTP server](https://github.com/calladitya/authentication-system/blob/main/server.js): `server.js`
- [Express app](https://github.com/calladitya/authentication-system/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/calladitya/authentication-system/blob/main/src/routes/auth.routes.js): `src/routes/auth.routes.js`
- [Environment config](https://github.com/calladitya/authentication-system/blob/main/src/config/config.js): `src/config/config.js`

### Identity workflows

- [Auth controller](https://github.com/calladitya/authentication-system/blob/main/src/controller/auth.controller.js): `src/controller/auth.controller.js`
- [OTP helpers](https://github.com/calladitya/authentication-system/blob/main/src/utils/utils.js): `src/utils/utils.js`

### Persistence

- [DB connector](https://github.com/calladitya/authentication-system/blob/main/src/config/database.js): `src/config/database.js`
- [User records](https://github.com/calladitya/authentication-system/blob/main/src/models/user.model.js): `src/models/user.model.js`
- [Session records](https://github.com/calladitya/authentication-system/blob/main/src/models/session.model.js): `src/models/session.model.js`
- [OTP records](https://github.com/calladitya/authentication-system/blob/main/src/models/otp.model.js): `src/models/otp.model.js`

### Email verification

- [Email service](https://github.com/calladitya/authentication-system/blob/main/src/service/email.service.js): `src/service/email.service.js`

### Other components

- **API client**
- **MongoDB**
- **Gmail SMTP**
- **JWT library**
- **bcrypt library**

## Connections

- API client → HTTP server: sends requests (evidence: `README.md`)
- HTTP server → Express app: starts (evidence: `server.js`)
- HTTP server → Environment config: loads (evidence: `server.js`)
- HTTP server → DB connector: connects (evidence: `server.js`)
- DB connector → Environment config: reads URI (evidence: `src/config/database.js`)
- DB connector → MongoDB: connects (evidence: `src/config/database.js`)
- Express app → Auth routes: mounts (evidence: `src/app.js`)
- Auth routes → Auth controller: dispatches (evidence: `src/routes/auth.routes.js`)
- Auth controller → User records: reads/writes (evidence: `src/controller/auth.controller.js`)
- Auth controller → Session records: reads/writes (evidence: `src/controller/auth.controller.js`)
- Auth controller → OTP records: reads/writes (evidence: `src/controller/auth.controller.js`)
- Auth controller → OTP helpers: generates OTP (evidence: `src/controller/auth.controller.js`)
- Auth controller → Email service: sends verification (evidence: `src/controller/auth.controller.js`)
- Email service → Gmail SMTP: sends email (evidence: `src/service/email.service.js`)
- Auth controller → JWT library: signs/verifies tokens (evidence: `src/controller/auth.controller.js`)
- Auth controller → bcrypt library: hashes/checks (evidence: `src/controller/auth.controller.js`)
