How dilkhush-raj/devboard-backend works
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: app.ts Express app · user.routes.ts User and verification routes · question.routes.ts Question routes · index.ts Domain models
Components 19
Runtime
- Server entry · Initializes persistence before serving the API.
src/index.ts
HTTP API
- Express app · Configures middleware and mounts feature routes.
src/app.ts - User and verification routes
src/routes/user.routes.ts - Question routes
src/routes/question.routes.ts - Content routes · Blog, feed, and leaderboard endpoints.
src/routes/blog.routes.ts - JWT auth middleware · Protects authorized request paths.
src/middlewares/auth.middleware.ts - Multipart middleware · Stages uploaded files locally.
src/middlewares/multer.middleware.ts - API error and response contract · Standardizes async failures and successful responses.
src/utils/asyncHandler.ts - OpenAPI contract
swagger.yaml
Domain
- User controller
src/controllers/user.controller.ts - Account verification · Creates accounts and verifies email OTPs.
src/controllers/user/createUser.ts - Question controller
src/controllers/question.controller.ts - Answer controller
src/controllers/answer.controller.ts
Persistence
- Domain models · Schemas cover users, content, comments, tags, and saved records.
src/models/index.ts - OTP model
src/models/otp.model.ts - MongoDB access · Centralized persistence initialization and access.
src/db/index.ts
External services
- Cloudinary adapter · Encapsulates durable remote media storage.
src/utils/cloudinary.ts - Email delivery · Sends verification and welcome messages.
src/services/welcomeEmail.ts - Local upload staging
uploads/.gitkeep
Connections 22
- 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