# dilkhush-raj/devboard-backend architecture

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

- Interactive diagram: https://gitdiagram.com/dilkhush-raj/devboard-backend
- Repository: https://github.com/dilkhush-raj/devboard-backend

## Overview

#### Purpose and runtime
DevBoard Backend is a Node.js/TypeScript HTTP API for a developer community: users, questions, answers, blogs, tags, saved content, feeds, and leaderboards. It runs as a server process configured through environment variables, with MongoDB persistence, JWT token settings, Cloudinary credentials, and email delivery integration.

Key startup paths: `src/index.ts`, `src/app.ts`, `src/constants.ts`.

#### Application bootstrap and HTTP boundary
`src/index.ts` is the process entry point and is expected to initialize the database before serving the Express application exported/configured by `src/app.ts`. The app layer owns HTTP middleware and mounts feature route modules, separating transport concerns from controller logic.

Paths: `src/index.ts`, `src/app.ts`, `src/routes/user.routes.ts`.

#### Domain API modules
Route/controller pairs expose the main resource boundaries:
- Users and email verification: `src/routes/user.routes.ts`, `src/routes/verify.routes.ts`, `src/controllers/user.controller.ts`
- Questions and answers: `src/routes/question.routes.ts`, `src/controllers/question.controller.ts`, `src/controllers/answer.controller.ts`
- Blog content, tags, saved items, feed, and leaderboard: `src/routes/blog.routes.ts`, `src/routes/feed.routes.ts`, `src/routes/leaderbaord.routes.ts`

Controllers orchestrate request validation, authorization, model operations, and API responses; routes define endpoint-level composition.

#### Persistence model layer
MongoDB access is centralized behind `src/db/index.ts`. The domain schema layer contains separate models for core content and relationships: users, questions, answers, blogs, comments, tags, saved records, and OTPs.

Paths: `src/db/index.ts`, `src/models/index.ts`, `src/models/user.model.ts`, `src/models/question.model.ts`, `src/models/answer.model.ts`, `src/models/blog.model.ts`.

#### Authentication and account lifecycle
Authentication is enforced at the request boundary by `src/middlewares/auth.middleware.ts`, likely using access/refresh JWT secrets and expirations supplied by the environment. Account creation and verification are split into dedicated user controller stages, with OTP persistence and email services supporting verification/welcome workflows.

Paths: `src/middlewares/auth.middleware.ts`, `src/controllers/user/createUser.ts`, `src/controllers/user/verifyEmail.ts`, `src/models/otp.model.ts`, `src/services/sendEmail.ts`.

#### Media and external-service boundary
Multipart upload handling occurs through `src/middlewares/multer.middleware.ts`. Cloudinary integration is encapsulated in `src/utils/cloudinary.ts`, isolating remote media storage from controllers. Email-related external delivery is similarly concentrated in services.

Paths: `src/middlewares/multer.middleware.ts`, `src/utils/cloudinary.ts`, `src/services/welcomeEmail.ts`.

#### Response and failure conventions
Controllers should use shared asynchronous error handling and standardized error/response wrappers, making operational failures cross the HTTP boundary consistently rather than leaking raw database or service errors.

Paths: `src/utils/asyncHandler.ts`, `src/utils/ApiError.ts`, `src/utils/ApiResponse.ts`.

#### API contract
`swagger.yaml` is the repository’s API documentation artifact and should be kept aligned with route/controller behavior. `uploads/` is local transient upload storage, while Cloudinary is the durable external media destination.

Paths: `swagger.yaml`, `uploads/.gitkeep`.

Main entry points: [`src/app.ts`](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/app.ts) (Express app), [`src/routes/user.routes.ts`](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/user.routes.ts) (User and verification routes), [`src/routes/question.routes.ts`](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/question.routes.ts) (Question routes), [`src/models/index.ts`](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/models/index.ts) (Domain models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_entry{{"Server entry<br/>Node.js entry<br/>[index.ts]"}}
end

subgraph group_api["HTTP API"]
  node_app["Express app<br/>HTTP application<br/>[app.ts]"]
  node_routes_users["User and verification routes<br/>route module<br/>[user.routes.ts]"]
  node_routes_questions["Question routes<br/>route module<br/>[question.routes.ts]"]
  node_routes_blog["Content routes<br/>route modules<br/>[blog.routes.ts]"]
  node_auth["JWT auth middleware<br/>[auth.middleware.ts]"]
  node_upload["Multipart middleware"]
  node_error_contract["API error and response contract<br/>HTTP utilities<br/>[asyncHandler.ts]"]
  node_swagger["OpenAPI contract<br/>API documentation<br/>[swagger.yaml]"]
end

subgraph group_domain["Domain"]
  node_user_controller["User controller<br/>[user.controller.ts]"]
  node_account_lifecycle["Account verification<br/>controller stages<br/>[createUser.ts]"]
  node_question_controller["Question controller"]
  node_answer_controller["Answer controller"]
end

subgraph group_data["Persistence"]
  node_models[("Domain models<br/>Mongoose schema layer<br/>[index.ts]")]
  node_otp_model["OTP model<br/>Mongoose model<br/>[otp.model.ts]"]
  node_database[("MongoDB access<br/>database connection<br/>[index.ts]")]
end

subgraph group_integrations["External services"]
  node_cloudinary["Cloudinary adapter<br/>media integration<br/>[cloudinary.ts]"]
  node_email["Email delivery<br/>email service<br/>[welcomeEmail.ts]"]
  node_uploads[("Local upload staging<br/>transient storage<br/>[.gitkeep]")]
end

node_entry -->|"initializes"| node_database
node_entry -->|"serves"| node_app
node_app -->|"mounts"| node_routes_users
node_app -->|"mounts"| node_routes_questions
node_app -->|"mounts"| node_routes_blog
node_routes_users -->|"protects endpoints"| node_auth
node_routes_users -->|"dispatches"| node_user_controller
node_routes_users -->|"dispatches"| node_account_lifecycle
node_routes_questions -->|"protects endpoints"| node_auth
node_routes_questions -->|"dispatches"| node_question_controller
node_routes_questions -->|"dispatches"| node_answer_controller
node_routes_blog -->|"protects endpoints"| node_auth
node_user_controller -->|"reads and writes"| node_models
node_account_lifecycle -->|"stores verification codes"| node_otp_model
node_account_lifecycle -->|"sends verification"| node_email
node_question_controller -->|"reads and writes"| node_models
node_answer_controller -->|"reads and writes"| node_models
node_models -->|"persists through"| node_database
node_upload -->|"stages files"| node_uploads
node_upload -->|"uploads media"| node_cloudinary
node_app -->|"uses response conventions"| node_error_contract
node_swagger -.->|"documents API"| node_app

click node_entry "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/index.ts"
click node_app "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/app.ts"
click node_routes_users "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/user.routes.ts"
click node_routes_questions "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/question.routes.ts"
click node_routes_blog "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/blog.routes.ts"
click node_auth "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/middlewares/auth.middleware.ts"
click node_upload "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/middlewares/multer.middleware.ts"
click node_user_controller "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/user.controller.ts"
click node_account_lifecycle "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/user/createUser.ts"
click node_question_controller "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/question.controller.ts"
click node_answer_controller "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/answer.controller.ts"
click node_models "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/models/index.ts"
click node_otp_model "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/models/otp.model.ts"
click node_database "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/db/index.ts"
click node_error_contract "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/utils/asyncHandler.ts"
click node_cloudinary "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/utils/cloudinary.ts"
click node_email "https://github.com/dilkhush-raj/devboard-backend/blob/main/src/services/welcomeEmail.ts"
click node_swagger "https://github.com/dilkhush-raj/devboard-backend/blob/main/swagger.yaml"
click node_uploads "https://github.com/dilkhush-raj/devboard-backend/blob/main/uploads/.gitkeep"

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_entry toneBlue
class node_app,node_routes_users,node_routes_questions,node_routes_blog,node_auth,node_upload,node_error_contract,node_swagger toneAmber
class node_user_controller,node_account_lifecycle,node_question_controller,node_answer_controller toneMint
class node_models,node_otp_model,node_database toneRose
class node_cloudinary,node_email,node_uploads toneIndigo
```

## Components

### Runtime

- [Server entry](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/index.ts): Node.js entry · Initializes persistence before serving the API. · `src/index.ts`

### HTTP API

- [Express app](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/app.ts): HTTP application · Configures middleware and mounts feature routes. · `src/app.ts`
- [User and verification routes](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/user.routes.ts): route module · `src/routes/user.routes.ts`
- [Question routes](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/question.routes.ts): route module · `src/routes/question.routes.ts`
- [Content routes](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/routes/blog.routes.ts): route modules · Blog, feed, and leaderboard endpoints. · `src/routes/blog.routes.ts`
- [JWT auth middleware](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/middlewares/auth.middleware.ts): middleware · Protects authorized request paths. · `src/middlewares/auth.middleware.ts`
- [Multipart middleware](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/middlewares/multer.middleware.ts): middleware · Stages uploaded files locally. · `src/middlewares/multer.middleware.ts`
- [API error and response contract](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/utils/asyncHandler.ts): HTTP utilities · Standardizes async failures and successful responses. · `src/utils/asyncHandler.ts`
- [OpenAPI contract](https://github.com/dilkhush-raj/devboard-backend/blob/main/swagger.yaml): API documentation · `swagger.yaml`

### Domain

- [User controller](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/user.controller.ts): controller · `src/controllers/user.controller.ts`
- [Account verification](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/user/createUser.ts): controller stages · Creates accounts and verifies email OTPs. · `src/controllers/user/createUser.ts`
- [Question controller](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/question.controller.ts): controller · `src/controllers/question.controller.ts`
- [Answer controller](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/controllers/answer.controller.ts): controller · `src/controllers/answer.controller.ts`

### Persistence

- [Domain models](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/models/index.ts): Mongoose schema layer · Schemas cover users, content, comments, tags, and saved records. · `src/models/index.ts`
- [OTP model](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/models/otp.model.ts): Mongoose model · `src/models/otp.model.ts`
- [MongoDB access](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/db/index.ts): database connection · Centralized persistence initialization and access. · `src/db/index.ts`

### External services

- [Cloudinary adapter](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/utils/cloudinary.ts): media integration · Encapsulates durable remote media storage. · `src/utils/cloudinary.ts`
- [Email delivery](https://github.com/dilkhush-raj/devboard-backend/blob/main/src/services/welcomeEmail.ts): email service · Sends verification and welcome messages. · `src/services/welcomeEmail.ts`
- [Local upload staging](https://github.com/dilkhush-raj/devboard-backend/blob/main/uploads/.gitkeep): transient storage · `uploads/.gitkeep`

## Connections

- Server entry → MongoDB access: initializes
- Server entry → Express app: serves
- Express app → User and verification routes: mounts
- Express app → Question routes: mounts
- Express app → Content routes: mounts
- User and verification routes → JWT auth middleware: protects endpoints
- User and verification routes → User controller: dispatches
- User and verification routes → Account verification: dispatches
- Question routes → JWT auth middleware: protects endpoints
- Question routes → Question controller: dispatches
- Question routes → Answer controller: dispatches
- Content routes → JWT auth middleware: protects endpoints
- User controller → Domain models: reads and writes
- Account verification → OTP model: stores verification codes
- Account verification → Email delivery: sends verification
- Question controller → Domain models: reads and writes
- Answer controller → Domain models: reads and writes
- Domain models → MongoDB access: persists through
- Multipart middleware → Local upload staging: stages files
- Multipart middleware → Cloudinary adapter: uploads media
- Express app → API error and response contract: uses response conventions
- OpenAPI contract → Express app: documents API
