# harshavardhan3535/user-auth-api architecture

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

- Interactive diagram: https://gitdiagram.com/harshavardhan3535/user-auth-api
- Repository: https://github.com/harshavardhan3535/user-auth-api

## Overview

This is an Express REST API for account registration, login, token refresh/logout, profile access, and admin user management. A client sends requests through the app and route layer; authentication controllers validate credentials and issue tokens, while protected routes apply JWT and role checks before accessing user records. The User model supplies password hashing and persisted refresh-token state, backed by MongoDB. The README documents the endpoint and security capabilities; deployment and Postman testing are not runtime components. Source excerpts support the main calls; database use is also documented in the README.

Main entry points: [`src/app.js`](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/app.js) (Express app), [`src/routes/protectedRoutes.js`](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/protectedRoutes.js) (Protected routes), [`src/routes/authRoutes.js`](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/authRoutes.js) (Auth routes), [`src/controllers/authController.js`](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/controllers/authController.js) (Auth controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["Express app<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_protected_routes["Protected routes<br/>[protectedRoutes.js]"]
  node_rate_limiter["Login rate limit<br/>[app.js]"]
end

subgraph group_auth["Authentication"]
  node_auth_controller["Auth controller<br/>[authController.js]"]
  node_token_utils["Token utilities<br/>[tokenUtils.js]"]
end

subgraph group_access["Protected access"]
  node_jwt_auth["JWT verification<br/>[authMiddleware.js]"]
  node_role_check["Role authorization<br/>[roleMiddleware.js]"]
end

subgraph group_data["User data"]
  node_user_model["User model<br/>[User.js]"]
  node_db_connect["DB connection<br/>[db.js]"]
  node_mongo[("MongoDB")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts auth"| node_auth_routes
node_app -->|"mounts protected"| node_protected_routes
node_app -->|"limits login"| node_rate_limiter
node_auth_routes -->|"dispatches auth"| node_auth_controller
node_auth_routes -->|"guards logout"| node_jwt_auth
node_auth_controller -->|"reads and saves"| node_user_model
node_auth_controller -->|"generates tokens"| node_token_utils
node_protected_routes -->|"verifies access"| node_jwt_auth
node_protected_routes -->|"checks admin role"| node_role_check
node_protected_routes -->|"queries users"| node_user_model
node_user_model -->|"persists user state"| node_mongo
node_db_connect -->|"connects"| node_mongo

click node_app "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/app.js"
click node_auth_routes "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/authRoutes.js"
click node_protected_routes "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/protectedRoutes.js"
click node_rate_limiter "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/app.js"
click node_auth_controller "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/controllers/authController.js"
click node_token_utils "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/utils/tokenUtils.js"
click node_jwt_auth "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/middlewares/authMiddleware.js"
click node_role_check "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/middlewares/roleMiddleware.js"
click node_user_model "https://github.com/harshavardhan3535/user-auth-api/blob/main/src/models/User.js"
click node_db_connect "https://github.com/harshavardhan3535/user-auth-api/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_app,node_auth_routes,node_protected_routes,node_rate_limiter,node_client toneBlue
class node_auth_controller,node_token_utils toneAmber
class node_jwt_auth,node_role_check toneMint
class node_user_model,node_db_connect,node_mongo toneRose
```

## Components

### API entry

- [Express app](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/authRoutes.js): `src/routes/authRoutes.js`
- [Protected routes](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/routes/protectedRoutes.js): `src/routes/protectedRoutes.js`
- [Login rate limit](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/app.js): `src/app.js`

### Authentication

- [Auth controller](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [Token utilities](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/utils/tokenUtils.js): `src/utils/tokenUtils.js`

### Protected access

- [JWT verification](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/middlewares/authMiddleware.js): `src/middlewares/authMiddleware.js`
- [Role authorization](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/middlewares/roleMiddleware.js): `src/middlewares/roleMiddleware.js`

### User data

- [User model](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/models/User.js): `src/models/User.js`
- [DB connection](https://github.com/harshavardhan3535/user-auth-api/blob/main/src/config/db.js): `src/config/db.js`
- **MongoDB**

### Other components

- **API client**

## Connections

- API client → Express app: sends requests (evidence: `README.md`)
- Express app → Auth routes: mounts auth (evidence: `src/app.js`)
- Express app → Protected routes: mounts protected (evidence: `src/app.js`)
- Express app → Login rate limit: limits login (evidence: `src/app.js`)
- Auth routes → Auth controller: dispatches auth (evidence: `src/routes/authRoutes.js`)
- Auth routes → JWT verification: guards logout (evidence: `src/routes/authRoutes.js`)
- Auth controller → User model: reads and saves (evidence: `src/controllers/authController.js`)
- Auth controller → Token utilities: generates tokens (evidence: `src/controllers/authController.js`)
- Protected routes → JWT verification: verifies access (evidence: `src/routes/protectedRoutes.js`)
- Protected routes → Role authorization: checks admin role (evidence: `src/routes/protectedRoutes.js`)
- Protected routes → User model: queries users (evidence: `src/routes/protectedRoutes.js`)
- User model → MongoDB: persists user state (evidence: `README.md`)
- DB connection → MongoDB: connects (evidence: `src/config/db.js`)
