# alihgad/saraha-prod architecture

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

- Interactive diagram: https://gitdiagram.com/alihgad/saraha-prod
- Repository: https://github.com/alihgad/saraha-prod

## Overview

This is an Express-based messaging service with user accounts, authentication, and message submission, retrieval, and deletion. Its main request flow starts at the application entry point, mounts feature routers, and passes requests through route middleware to controllers and services. Auth includes email OTP, password reset, Google sign-in, and token rotation; messages support optional authentication and image uploads. MongoDB-backed repositories and Redis-backed caching support runtime operations. Source excerpts show key calls, but some route wiring and service-to-repository details are not sampled, so those links are omitted or marked unverified.

Main entry points: [`src/module/auth/auth.service.js`](https://github.com/alihgad/saraha-prod/blob/main/src/module/auth/auth.service.js) (Auth workflows), [`src/module/message/message.controller.js`](https://github.com/alihgad/saraha-prod/blob/main/src/module/message/message.controller.js) (Message routes), [`src/module/user/user.controller.js`](https://github.com/alihgad/saraha-prod/blob/main/src/module/user/user.controller.js) (User routes), [`src/common/utils/token.service.js`](https://github.com/alihgad/saraha-prod/blob/main/src/common/utils/token.service.js) (Token management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and routes"]
  node_main["App startup<br/>[main.js]"]
  node_module_routes["Feature routing<br/>[index.js]"]
end

subgraph group_identity["Identity and users"]
  node_auth_controller["Auth routes<br/>[auth.controller.js]"]
  node_auth_service["Auth workflows<br/>[auth.service.js]"]
  node_user_controller["User routes<br/>[user.controller.js]"]
  node_user_service["User operations<br/>[user.service.js]"]
  node_auth_middleware["Authentication<br/>[auth.js]"]
  node_optional_auth["Optional auth<br/>[optionalAuth.js]"]
  node_token_service["Token management<br/>[token.service.js]"]
end

subgraph group_messaging["Messaging and uploads"]
  node_message_controller["Message routes"]
  node_message_service["Message operations<br/>[message.service.js]"]
  node_upload["File processing<br/>[multer.local.js]"]
end

subgraph group_platform["Data and shared services"]
  node_user_repo["User repository<br/>[user.repo.js]"]
  node_message_repo["Message repository<br/>[message.repo.js]"]
  node_mongo[("MongoDB models")]
  node_cache_service["Cache operations<br/>[cache.service.js]"]
  node_redis[("Redis connection")]
  node_email_events["Email events<br/>[email.events.js]"]
  node_mail_service["Mail delivery<br/>[mail.service.js]"]
  node_templates["Email templates<br/>[templates.js]"]
end

node_client(("HTTP client"))
node_google["Google identity"]

node_client -.->|"sends requests"| node_main
node_main -->|"mounts routes"| node_module_routes
node_module_routes -->|"registers auth"| node_auth_controller
node_module_routes -->|"registers users"| node_user_controller
node_module_routes -->|"registers messages"| node_message_controller
node_auth_controller -->|"calls"| node_auth_service
node_user_controller -->|"calls"| node_user_service
node_user_controller -->|"mounts router"| node_message_controller
node_message_controller -->|"calls"| node_message_service
node_message_controller -->|"checks optionally"| node_optional_auth
node_message_controller -->|"authenticates"| node_auth_middleware
node_message_controller -->|"processes uploads"| node_upload
node_user_controller -->|"authenticates"| node_auth_middleware
node_user_controller -->|"processes uploads"| node_upload
node_auth_service -->|"uses"| node_user_repo
node_auth_service -->|"stores OTPs"| node_cache_service
node_auth_service -->|"creates tokens"| node_token_service
node_auth_service -->|"emits email events"| node_email_events
node_auth_service -->|"verifies ID token"| node_google
node_token_service -->|"checks revocation"| node_cache_service
node_token_service -->|"loads user"| node_mongo
node_auth_middleware -->|"verifies token"| node_token_service
node_optional_auth -->|"verifies token"| node_token_service
node_user_repo -->|"queries"| node_mongo
node_message_repo -->|"queries"| node_mongo
node_cache_service -->|"uses client"| node_redis
node_email_events -->|"dispatches email"| node_mail_service
node_email_events -->|"uses templates"| node_templates
node_mail_service -.->|"reads configuration"| node_main

click node_main "https://github.com/alihgad/saraha-prod/blob/main/src/main.js"
click node_module_routes "https://github.com/alihgad/saraha-prod/blob/main/src/module/index.js"
click node_auth_controller "https://github.com/alihgad/saraha-prod/blob/main/src/module/auth/auth.controller.js"
click node_auth_service "https://github.com/alihgad/saraha-prod/blob/main/src/module/auth/auth.service.js"
click node_user_controller "https://github.com/alihgad/saraha-prod/blob/main/src/module/user/user.controller.js"
click node_user_service "https://github.com/alihgad/saraha-prod/blob/main/src/module/user/user.service.js"
click node_message_controller "https://github.com/alihgad/saraha-prod/blob/main/src/module/message/message.controller.js"
click node_message_service "https://github.com/alihgad/saraha-prod/blob/main/src/module/message/message.service.js"
click node_upload "https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/multer.local.js"
click node_auth_middleware "https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/auth.js"
click node_optional_auth "https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/optionalAuth.js"
click node_token_service "https://github.com/alihgad/saraha-prod/blob/main/src/common/utils/token.service.js"
click node_user_repo "https://github.com/alihgad/saraha-prod/blob/main/src/db/repositery/user.repo.js"
click node_message_repo "https://github.com/alihgad/saraha-prod/blob/main/src/db/repositery/message.repo.js"
click node_mongo "https://github.com/alihgad/saraha-prod/tree/main/src/db/model"
click node_cache_service "https://github.com/alihgad/saraha-prod/blob/main/src/common/services/cache.service.js"
click node_redis "https://github.com/alihgad/saraha-prod/blob/main/src/db/redis.connection.js"
click node_email_events "https://github.com/alihgad/saraha-prod/blob/main/src/common/events/email.events.js"
click node_mail_service "https://github.com/alihgad/saraha-prod/blob/main/src/common/services/mail.service.js"
click node_templates "https://github.com/alihgad/saraha-prod/blob/main/src/common/templates/templates.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_main,node_module_routes,node_client toneBlue
class node_auth_controller,node_auth_service,node_user_controller,node_user_service,node_auth_middleware,node_optional_auth,node_token_service toneAmber
class node_message_controller,node_message_service,node_upload toneMint
class node_user_repo,node_message_repo,node_mongo,node_cache_service,node_redis,node_email_events,node_mail_service,node_templates toneRose
class node_google toneIndigo
```

## Components

### Application and routes

- [App startup](https://github.com/alihgad/saraha-prod/blob/main/src/main.js): `src/main.js`
- [Feature routing](https://github.com/alihgad/saraha-prod/blob/main/src/module/index.js): `src/module/index.js`

### Identity and users

- [Auth routes](https://github.com/alihgad/saraha-prod/blob/main/src/module/auth/auth.controller.js): `src/module/auth/auth.controller.js`
- [Auth workflows](https://github.com/alihgad/saraha-prod/blob/main/src/module/auth/auth.service.js): `src/module/auth/auth.service.js`
- [User routes](https://github.com/alihgad/saraha-prod/blob/main/src/module/user/user.controller.js): `src/module/user/user.controller.js`
- [User operations](https://github.com/alihgad/saraha-prod/blob/main/src/module/user/user.service.js): `src/module/user/user.service.js`
- [Authentication](https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/auth.js): `src/common/middleware/auth.js`
- [Optional auth](https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/optionalAuth.js): `src/common/middleware/optionalAuth.js`
- [Token management](https://github.com/alihgad/saraha-prod/blob/main/src/common/utils/token.service.js): `src/common/utils/token.service.js`

### Messaging and uploads

- [Message routes](https://github.com/alihgad/saraha-prod/blob/main/src/module/message/message.controller.js): `src/module/message/message.controller.js`
- [Message operations](https://github.com/alihgad/saraha-prod/blob/main/src/module/message/message.service.js): `src/module/message/message.service.js`
- [File processing](https://github.com/alihgad/saraha-prod/blob/main/src/common/middleware/multer.local.js): `src/common/middleware/multer.local.js`

### Data and shared services

- [User repository](https://github.com/alihgad/saraha-prod/blob/main/src/db/repositery/user.repo.js): `src/db/repositery/user.repo.js`
- [Message repository](https://github.com/alihgad/saraha-prod/blob/main/src/db/repositery/message.repo.js): `src/db/repositery/message.repo.js`
- [MongoDB models](https://github.com/alihgad/saraha-prod/tree/main/src/db/model): `src/db/model`
- [Cache operations](https://github.com/alihgad/saraha-prod/blob/main/src/common/services/cache.service.js): `src/common/services/cache.service.js`
- [Redis connection](https://github.com/alihgad/saraha-prod/blob/main/src/db/redis.connection.js): `src/db/redis.connection.js`
- [Email events](https://github.com/alihgad/saraha-prod/blob/main/src/common/events/email.events.js): `src/common/events/email.events.js`
- [Mail delivery](https://github.com/alihgad/saraha-prod/blob/main/src/common/services/mail.service.js): `src/common/services/mail.service.js`
- [Email templates](https://github.com/alihgad/saraha-prod/blob/main/src/common/templates/templates.js): `src/common/templates/templates.js`

### Other components

- **HTTP client**
- **Google identity**

## Connections

- HTTP client → App startup: sends requests
- App startup → Feature routing: mounts routes (evidence: `src/main.js`)
- Feature routing → Auth routes: registers auth (evidence: `src/module/index.js`)
- Feature routing → User routes: registers users (evidence: `src/module/index.js`)
- Feature routing → Message routes: registers messages (evidence: `src/module/index.js`)
- Auth routes → Auth workflows: calls (evidence: `src/module/auth/auth.controller.js`)
- User routes → User operations: calls (evidence: `src/module/user/user.controller.js`)
- User routes → Message routes: mounts router (evidence: `src/module/user/user.controller.js`)
- Message routes → Message operations: calls (evidence: `src/module/message/message.controller.js`)
- Message routes → Optional auth: checks optionally (evidence: `src/module/message/message.controller.js`)
- Message routes → Authentication: authenticates (evidence: `src/module/message/message.controller.js`)
- Message routes → File processing: processes uploads (evidence: `src/module/message/message.controller.js`)
- User routes → Authentication: authenticates (evidence: `src/module/user/user.controller.js`)
- User routes → File processing: processes uploads (evidence: `src/module/user/user.controller.js`)
- Auth workflows → User repository: uses (evidence: `src/module/auth/auth.service.js`)
- Auth workflows → Cache operations: stores OTPs (evidence: `src/module/auth/auth.service.js`)
- Auth workflows → Token management: creates tokens (evidence: `src/module/auth/auth.service.js`)
- Auth workflows → Email events: emits email events (evidence: `src/module/auth/auth.service.js`)
- Auth workflows → Google identity: verifies ID token (evidence: `src/module/auth/auth.service.js`)
- Token management → Cache operations: checks revocation (evidence: `src/common/utils/token.service.js`)
- Token management → MongoDB models: loads user (evidence: `src/common/utils/token.service.js`)
- Authentication → Token management: verifies token (evidence: `src/common/middleware/auth.js`)
- Optional auth → Token management: verifies token (evidence: `src/common/middleware/optionalAuth.js`)
- User repository → MongoDB models: queries (evidence: `src/db/repositery/user.repo.js`)
- Message repository → MongoDB models: queries (evidence: `src/db/repositery/message.repo.js`)
- Cache operations → Redis connection: uses client (evidence: `src/common/services/cache.service.js`)
- Email events → Mail delivery: dispatches email (evidence: `src/common/events/email.events.js`)
- Email events → Email templates: uses templates (evidence: `src/common/events/email.events.js`)
- Mail delivery → App startup: reads configuration
