# ankurdotio/yt-auth architecture

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

- Interactive diagram: https://gitdiagram.com/ankurdotio/yt-auth
- Repository: https://github.com/ankurdotio/yt-auth

## Overview

yt-auth is an Express authentication service. Clients use the mounted auth routes to register, verify email by OTP, log in, fetch their profile, refresh tokens, and log out on one or all devices. The controller coordinates user, OTP, and session persistence, token handling, and verification email delivery; MongoDB and Gmail OAuth are external dependencies. Excerpts show the main calls and route wiring; no README capability claims or uninspected source behavior are available.

Main entry points: [`src/controllers/auth.controller.js`](https://github.com/ankurdotio/yt-auth/blob/main/src/controllers/auth.controller.js) (Auth controller), [`src/config/database.js`](https://github.com/ankurdotio/yt-auth/blob/main/src/config/database.js) (MongoDB connector), [`src/services/email.service.js`](https://github.com/ankurdotio/yt-auth/blob/main/src/services/email.service.js) (Email service), [`src/app.js`](https://github.com/ankurdotio/yt-auth/blob/main/src/app.js) (Express app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP interface"]
  node_server["Server bootstrap<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
  node_routes["Auth routes<br/>[auth.routes.js]"]
end

subgraph group_auth["Authentication flows"]
  node_controller["Auth controller<br/>[auth.controller.js]"]
  node_otp_tools["OTP utilities<br/>[utils.js]"]
end

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

subgraph group_integrations["External integrations"]
  node_email["Email service<br/>[email.service.js]"]
  node_config["Environment config<br/>[config.js]"]
end

node_client(("API client"))
node_mongodb[("MongoDB")]
node_gmail["Gmail OAuth"]

node_client -->|"sends requests"| node_app
node_server -->|"starts"| node_app
node_server -->|"connects"| node_database
node_app -->|"mounts"| node_routes
node_routes -->|"dispatches"| node_controller
node_controller -->|"reads/writes"| node_users
node_controller -->|"reads/writes"| node_otps
node_controller -->|"reads/writes"| node_sessions
node_controller -->|"generates OTP"| node_otp_tools
node_controller -->|"sends verification"| node_email
node_controller -->|"uses JWT secret"| node_config
node_email -->|"reads credentials"| node_config
node_email -->|"sends mail"| node_gmail
node_database -->|"reads URI"| node_config
node_database -->|"connects"| node_mongodb

click node_server "https://github.com/ankurdotio/yt-auth/blob/main/server.js"
click node_app "https://github.com/ankurdotio/yt-auth/blob/main/src/app.js"
click node_routes "https://github.com/ankurdotio/yt-auth/blob/main/src/routes/auth.routes.js"
click node_controller "https://github.com/ankurdotio/yt-auth/blob/main/src/controllers/auth.controller.js"
click node_otp_tools "https://github.com/ankurdotio/yt-auth/blob/main/src/utils/utils.js"
click node_email "https://github.com/ankurdotio/yt-auth/blob/main/src/services/email.service.js"
click node_users "https://github.com/ankurdotio/yt-auth/blob/main/src/models/user.model.js"
click node_otps "https://github.com/ankurdotio/yt-auth/blob/main/src/models/otp.model.js"
click node_sessions "https://github.com/ankurdotio/yt-auth/blob/main/src/models/session.model.js"
click node_database "https://github.com/ankurdotio/yt-auth/blob/main/src/config/database.js"
click node_config "https://github.com/ankurdotio/yt-auth/blob/main/src/config/config.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_client toneBlue
class node_controller,node_otp_tools,node_mongodb toneAmber
class node_users,node_otps,node_sessions,node_database toneMint
class node_email,node_config toneRose
class node_gmail toneIndigo
```

## Components

### HTTP interface

- [Server bootstrap](https://github.com/ankurdotio/yt-auth/blob/main/server.js): `server.js`
- [Express app](https://github.com/ankurdotio/yt-auth/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/ankurdotio/yt-auth/blob/main/src/routes/auth.routes.js): `src/routes/auth.routes.js`

### Authentication flows

- [Auth controller](https://github.com/ankurdotio/yt-auth/blob/main/src/controllers/auth.controller.js): `src/controllers/auth.controller.js`
- [OTP utilities](https://github.com/ankurdotio/yt-auth/blob/main/src/utils/utils.js): `src/utils/utils.js`

### MongoDB persistence

- [User records](https://github.com/ankurdotio/yt-auth/blob/main/src/models/user.model.js): `src/models/user.model.js`
- [OTP records](https://github.com/ankurdotio/yt-auth/blob/main/src/models/otp.model.js): `src/models/otp.model.js`
- [Session records](https://github.com/ankurdotio/yt-auth/blob/main/src/models/session.model.js): `src/models/session.model.js`
- [MongoDB connector](https://github.com/ankurdotio/yt-auth/blob/main/src/config/database.js): `src/config/database.js`

### External integrations

- [Email service](https://github.com/ankurdotio/yt-auth/blob/main/src/services/email.service.js): `src/services/email.service.js`
- [Environment config](https://github.com/ankurdotio/yt-auth/blob/main/src/config/config.js): `src/config/config.js`

### Other components

- **API client**
- **MongoDB**
- **Gmail OAuth**

## Connections

- API client → Express app: sends requests (evidence: `src/app.js`)
- Server bootstrap → Express app: starts (evidence: `server.js`)
- Server bootstrap → MongoDB connector: connects (evidence: `server.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/controllers/auth.controller.js`)
- Auth controller → OTP records: reads/writes (evidence: `src/controllers/auth.controller.js`)
- Auth controller → Session records: reads/writes (evidence: `src/controllers/auth.controller.js`)
- Auth controller → OTP utilities: generates OTP (evidence: `src/controllers/auth.controller.js`)
- Auth controller → Email service: sends verification (evidence: `src/controllers/auth.controller.js`)
- Auth controller → Environment config: uses JWT secret (evidence: `src/controllers/auth.controller.js`)
- Email service → Environment config: reads credentials (evidence: `src/services/email.service.js`)
- Email service → Gmail OAuth: sends mail (evidence: `src/services/email.service.js`)
- MongoDB connector → Environment config: reads URI (evidence: `src/config/database.js`)
- MongoDB connector → MongoDB: connects (evidence: `src/config/database.js`)
