# dharam-k/node-js-crud-api-with-jwt-auth architecture

> Architecture diagram of the GitHub repository dharam-k/node-js-crud-api-with-jwt-auth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dharam-k/node-js-crud-api-with-jwt-auth
- Repository: https://github.com/dharam-k/node-js-crud-api-with-jwt-auth

## Overview

This is an Express user-authentication API. Clients register or log in, request an email reset link, reset a password, and access a protected logged-in-user endpoint. The controller owns the domain actions: it hashes passwords, issues and verifies JWTs, reads and updates users, and sends reset email. The app connects Mongoose directly; the separate DB connector is not invoked in the sampled app. The graph reflects documented features, with unsampled behavior grouped under its exact directory; no unsupported reset-page or logout flow is inferred.

Main entry points: [`controllers/UserController.js`](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js) (User controller), [`models/Users.js`](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/models/Users.js) (User model), [`app.js`](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/app.js) (Express app), [`routes/UserRoutes.js`](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/routes/UserRoutes.js) (User routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_app["Express app<br/>[app.js]"]
  node_routes["User routes<br/>[UserRoutes.js]"]
  node_authmw["JWT middleware<br/>[AuthMiddleware.js]"]
end

subgraph group_auth["Authentication workflows"]
  node_controller["User controller<br/>[UserController.js]"]
  node_registration["Sign up<br/>[UserController.js]"]
  node_login["Login<br/>[UserController.js]"]
  node_forgot["Forgot password<br/>[UserController.js]"]
  node_reset["Password reset<br/>[UserController.js]"]
  node_protected["Logged-in user<br/>[UserController.js]"]
end

subgraph group_integrations["Persistence and email"]
  node_users["User model<br/>[Users.js]"]
  node_mongo[("MongoDB")]
  node_emailconfig["Email transport<br/>[Email.js]"]
  node_mail["SMTP service"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_routes
node_routes -->|"dispatches actions"| node_controller
node_routes -->|"guards logged route"| node_authmw
node_authmw -->|"loads user"| node_users
node_authmw -->|"continues request"| node_protected
node_controller -->|"handles signup"| node_registration
node_controller -->|"handles login"| node_login
node_controller -->|"handles request"| node_forgot
node_controller -->|"handles reset"| node_reset
node_controller -->|"returns user"| node_protected
node_registration -->|"creates user"| node_users
node_login -->|"finds user"| node_users
node_forgot -->|"finds user"| node_users
node_forgot -->|"sends reset email"| node_emailconfig
node_emailconfig -->|"delivers email"| node_mail
node_reset -->|"updates password"| node_users
node_users -->|"reads and writes"| node_mongo
node_app -->|"connects Mongoose"| node_mongo

click node_app "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/app.js"
click node_routes "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/routes/UserRoutes.js"
click node_authmw "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/middleware/AuthMiddleware.js"
click node_controller "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_registration "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_login "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_forgot "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_reset "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_protected "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js"
click node_users "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/models/Users.js"
click node_emailconfig "https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/config/Email.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_app,node_routes,node_authmw,node_client toneBlue
class node_controller,node_registration,node_login,node_forgot,node_reset,node_protected toneAmber
class node_users,node_mongo,node_emailconfig,node_mail toneMint
```

## Components

### API runtime

- [Express app](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/app.js): `app.js`
- [User routes](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/routes/UserRoutes.js): `routes/UserRoutes.js`
- [JWT middleware](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/middleware/AuthMiddleware.js): `middleware/AuthMiddleware.js`

### Authentication workflows

- [User controller](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`
- [Sign up](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`
- [Login](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`
- [Forgot password](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`
- [Password reset](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`
- [Logged-in user](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/controllers/UserController.js): `controllers/UserController.js`

### Persistence and email

- [User model](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/models/Users.js): `models/Users.js`
- **MongoDB**
- [Email transport](https://github.com/dharam-k/node-js-crud-api-with-jwt-auth/blob/master/config/Email.js): `config/Email.js`
- **SMTP service**

### Other components

- **API client**

## Connections

- API client → Express app: sends requests
- Express app → User routes: mounts routes
- User routes → User controller: dispatches actions
- User routes → JWT middleware: guards logged route
- JWT middleware → User model: loads user
- JWT middleware → Logged-in user: continues request
- User controller → Sign up: handles signup
- User controller → Login: handles login
- User controller → Forgot password: handles request
- User controller → Password reset: handles reset
- User controller → Logged-in user: returns user
- Sign up → User model: creates user
- Login → User model: finds user
- Forgot password → User model: finds user
- Forgot password → Email transport: sends reset email
- Email transport → SMTP service: delivers email
- Password reset → User model: updates password
- User model → MongoDB: reads and writes
- Express app → MongoDB: connects Mongoose
