# mathanponsingh/vhero-backend architecture

> Architecture diagram of the GitHub repository mathanponsingh/vhero-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mathanponsingh/vhero-backend
- Repository: https://github.com/mathanponsingh/vhero-backend

## Overview

VHERO is a FastAPI backend whose main workflow lets a client request an email OTP and then verify it. The router validates request shapes, generates and hashes codes, persists expiry and attempt state, and schedules email delivery; verification checks the stored hash and marks successful codes verified. Rate limits and database access support these endpoints. The README describes the API, while the sampled code shows the concrete OTP workflow. The map omits unsampled details and treats PostgreSQL and SMTP as external services.

Main entry points: [`controller/router.py`](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py) (OTP endpoints), [`service/db.py`](https://github.com/mathanponsingh/vhero-backend/blob/main/service/db.py) (Database access), [`app.py`](https://github.com/mathanponsingh/vhero-backend/blob/main/app.py) (FastAPI app), [`service/app.py`](https://github.com/mathanponsingh/vhero-backend/blob/main/service/app.py) (Email delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_app["FastAPI app<br/>[app.py]"]
  node_router["OTP endpoints<br/>[router.py]"]
  node_request_schemas["Request schemas<br/>[user.py]"]
end

subgraph group_auth["OTP authentication"]
  node_otp_generation["OTP generation<br/>[router.py]"]
  node_otp_hashing["OTP hashing<br/>[router.py]"]
  node_send_otp["Request OTP<br/>[router.py]"]
  node_verify_otp["Verify OTP<br/>[router.py]"]
end

subgraph group_support["Supporting services"]
  node_email_delivery["Email delivery<br/>[app.py]"]
  node_database_access["Database access<br/>[db.py]"]
  node_rate_limiter["Rate limiter<br/>[limiter.py]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]
node_smtp["SMTP server"]

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_router
node_router -->|"validates input"| node_request_schemas
node_router -->|"dispatches"| node_send_otp
node_router -->|"dispatches"| node_verify_otp
node_send_otp -->|"generates code"| node_otp_generation
node_send_otp -->|"hashes code"| node_otp_hashing
node_verify_otp -->|"hashes submitted code"| node_otp_hashing
node_send_otp -->|"stores code state"| node_database_access
node_verify_otp -->|"checks and updates"| node_database_access
node_router -->|"injects connection"| node_database_access
node_database_access -->|"connects to"| node_postgres
node_send_otp -->|"schedules email"| node_email_delivery
node_email_delivery -->|"sends message"| node_smtp
node_router -->|"limits endpoints"| node_rate_limiter
node_app -->|"configures limiter"| node_rate_limiter

click node_app "https://github.com/mathanponsingh/vhero-backend/blob/main/app.py"
click node_router "https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py"
click node_request_schemas "https://github.com/mathanponsingh/vhero-backend/blob/main/schemas/user.py"
click node_otp_generation "https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py"
click node_otp_hashing "https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py"
click node_send_otp "https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py"
click node_verify_otp "https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py"
click node_email_delivery "https://github.com/mathanponsingh/vhero-backend/blob/main/service/app.py"
click node_database_access "https://github.com/mathanponsingh/vhero-backend/blob/main/service/db.py"
click node_rate_limiter "https://github.com/mathanponsingh/vhero-backend/blob/main/service/limiter.py"

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_router,node_request_schemas,node_client toneBlue
class node_otp_generation,node_otp_hashing,node_send_otp,node_verify_otp,node_postgres toneAmber
class node_email_delivery,node_database_access,node_rate_limiter,node_smtp toneMint
```

## Components

### API runtime

- [FastAPI app](https://github.com/mathanponsingh/vhero-backend/blob/main/app.py): `app.py`
- [OTP endpoints](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py): `controller/router.py`
- [Request schemas](https://github.com/mathanponsingh/vhero-backend/blob/main/schemas/user.py): `schemas/user.py`

### OTP authentication

- [OTP generation](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py): `controller/router.py`
- [OTP hashing](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py): `controller/router.py`
- [Request OTP](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py): `controller/router.py`
- [Verify OTP](https://github.com/mathanponsingh/vhero-backend/blob/main/controller/router.py): `controller/router.py`

### Supporting services

- [Email delivery](https://github.com/mathanponsingh/vhero-backend/blob/main/service/app.py): `service/app.py`
- [Database access](https://github.com/mathanponsingh/vhero-backend/blob/main/service/db.py): `service/db.py`
- [Rate limiter](https://github.com/mathanponsingh/vhero-backend/blob/main/service/limiter.py): `service/limiter.py`

### Other components

- **API client**
- **PostgreSQL**
- **SMTP server**

## Connections

- API client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → OTP endpoints: mounts routes (evidence: `app.py`)
- OTP endpoints → Request schemas: validates input (evidence: `controller/router.py`)
- OTP endpoints → Request OTP: dispatches (evidence: `controller/router.py`)
- OTP endpoints → Verify OTP: dispatches (evidence: `controller/router.py`)
- Request OTP → OTP generation: generates code (evidence: `controller/router.py`)
- Request OTP → OTP hashing: hashes code (evidence: `controller/router.py`)
- Verify OTP → OTP hashing: hashes submitted code (evidence: `controller/router.py`)
- Request OTP → Database access: stores code state (evidence: `controller/router.py`)
- Verify OTP → Database access: checks and updates (evidence: `controller/router.py`)
- OTP endpoints → Database access: injects connection (evidence: `controller/router.py`)
- Database access → PostgreSQL: connects to (evidence: `service/db.py`)
- Request OTP → Email delivery: schedules email (evidence: `controller/router.py`)
- Email delivery → SMTP server: sends message (evidence: `service/app.py`)
- OTP endpoints → Rate limiter: limits endpoints (evidence: `controller/router.py`)
- FastAPI app → Rate limiter: configures limiter (evidence: `app.py`)
