# sonivaibhav-git/devdex architecture

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

- Interactive diagram: https://gitdiagram.com/sonivaibhav-git/devdex
- Repository: https://github.com/sonivaibhav-git/devdex

## Overview

1. **High-level shape**
   - Devdex is a **Node.js + Express REST API** backed by **MongoDB/Mongoose**.
   - It uses a **layered MVC-style architecture**: routes define endpoints, middleware gates requests, controllers coordinate, services implement business logic, and repositories handle database access.

2. **Primary domain**
   - The core product is a **PSAT project showcase platform**.
   - Projects are structured around **Problem, Solution, Approach, Technologies**, so the main data model is not just “portfolio items” but a standardized, review-friendly project narrative.

3. **Request flow**
   - The intended flow is: **Client → Routes → Validators/Middleware → Controllers → Services → Repositories → Database**.
   - This is explicitly reinforced by the folder layout: `routes/`, `middlewares/`, `controller/`, `service/`, `repositories/`, and `models/`.

4. **Authentication boundary**
   - The `auth` subsystem (`auth.routes.js`, `auth.controller.js`, `auth.service.js`) handles signup/login/session issuance.
   - JWT-based auth is used, with supporting utilities for **token creation** and **cookie options**, and `auth.middleware.js` protects authenticated routes.
   - `bcrypt` is implied by the README for password hashing.

5. **User/profile subsystem**
   - `profile.controller.js` and `profile.service.js` manage user-facing profile operations.
   - `models/user.model.js` is the persistent user record, and `repositories/user.repo.js` isolates queries involving users.
   - This boundary likely supports public profile views and authenticated profile updates.

6. **Project/problem content subsystem**
   - `project.*` and `problem.*` modules split the showcase content into two concerns: project entities and problem statements.
   - `models/projects.model.js` and `models/problems.model.js` suggest a normalized structure where PSAT content is stored with dedicated schemas.
   - `slug.js` indicates project/problem records are probably addressable through human-friendly URL identifiers.

7. **Search and discovery**
   - `search.routes.js`, `search.controller.js`, `search.service.js`, and `validators/search.validator.js` form a separate discovery path.
   - This subsystem likely supports filtering by **technology, domain, or text fields**, which is important for browsing portfolios at scale.

8. **Validation and request safety**
   - Input validation is handled server-side with **Zod**-based validators in `validators/`.
   - `queryValidator.middleware.js`, `validator.middleware.js`, and `middlewares/auth.middleware.js` form the main request gate before business logic runs.
   - This means malformed bodies, invalid query params, and unauthorized requests are rejected before hitting services.

9. **Persistence layer**
   - MongoDB is the data store, with Mongoose schemas in `models/`.
   - Repositories (`problem.repo.js`, `project.repo.js`, `user.repo.js`) abstract direct persistence operations so services do not talk to Mongoose everywhere.
   - `config/dbconfig.js` is the database connection boundary.

10. **Caching layer**
   - The repo has a distinct cache subsystem: `cache.middleware.js`, `cache.service.js`, `cacheConfig.js`, and `cache.keys.js`.
   - That suggests read-heavy endpoints are cached and cache keys are centralized for consistent invalidation.
   - Architecturally, this is an optimization layer that sits alongside the normal request pipeline, not inside the database layer.

11. **Cross-cutting response utilities**
   - `utils/apiResponse.js` and `utils/responseHandler.js` indicate standardized API responses and error formatting.
   - Supporting helpers like `usernameGenerator.js`, `token.js`, and `cookieOptions.js` keep auth and response behavior consistent across controllers.

12. **Bootstrap and composition**
   - `app.js` is the assembly point where Express, middleware, routes, and configuration are wired together.
   - The README also indicates common infrastructure pieces such as `dotenv`, `cors`, and `cookie-parser`, which affect request handling and auth cookie behavior.
   - Overall, the architecture is a clean separation of **HTTP interface**, **business logic**, **data access**, and **cross-cutting concerns**.

Main entry points: [`routes/index.js`](https://github.com/sonivaibhav-git/devdex/blob/main/routes/index.js) (Routes), [`service/project.service.js`](https://github.com/sonivaibhav-git/devdex/blob/main/service/project.service.js) (Project service), [`routes/project.routes.js`](https://github.com/sonivaibhav-git/devdex/blob/main/routes/project.routes.js) (Project routes), [`service/auth.service.js`](https://github.com/sonivaibhav-git/devdex/blob/main/service/auth.service.js) (Auth service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP layer"]
  node_app_js["app.js<br/>Express bootstrap<br/>[app.js]"]
  node_routes_index["Routes<br/>router composition<br/>[index.js]"]
  node_routes_auth["Auth routes<br/>HTTP routes<br/>[auth.routes.js]"]
  node_routes_project["Project routes<br/>HTTP routes<br/>[project.routes.js]"]
  node_routes_problem["Problem routes<br/>HTTP routes<br/>[problem.routes.js]"]
  node_routes_profile["Profile routes<br/>HTTP routes<br/>[profile.routes.js]"]
  node_routes_search["Search routes<br/>HTTP routes<br/>[search.routes.js]"]
  node_mw_auth(("Auth guard<br/>middleware<br/>[auth.middleware.js]"))
  node_mw_validator(("Body validation<br/>middleware"))
  node_mw_query_validator(("Query validation<br/>middleware"))
  node_mw_cache(("Cache gate<br/>middleware"))
end

subgraph group_domain["Domain layer"]
  node_ctl_auth["Auth controller<br/>[auth.controller.js]"]
  node_ctl_project["Project controller"]
  node_ctl_problem["Problem controller"]
  node_ctl_profile["Profile controller"]
  node_ctl_search["Search controller"]
  node_svc_auth["Auth service<br/>[auth.service.js]"]
  node_svc_project["Project service<br/>[project.service.js]"]
  node_svc_problem["Problem service<br/>[problem.service.js]"]
  node_svc_profile["Profile service<br/>[profile.service.js]"]
  node_svc_search["Search service<br/>[search.service.js]"]
end

subgraph group_data["Persistence layer"]
  node_repo_user["User repo<br/>[user.repo.js]"]
  node_repo_project["Project repo<br/>[project.repo.js]"]
  node_repo_problem["Problem repo<br/>[problem.repo.js]"]
  node_model_user[("User model<br/>mongoose model<br/>[user.model.js]")]
  node_model_projects[("Projects model<br/>mongoose model<br/>[projects.model.js]")]
  node_model_problems[("Problems model<br/>mongoose model<br/>[problems.model.js]")]
  node_dbconfig["DB config<br/>database config<br/>[dbconfig.js]"]
end

subgraph group_shared["Shared concerns"]
  node_svc_cache["Cache service<br/>[cache.service.js]"]
  node_cacheconfig["Cache config<br/>[cacheConfig.js]"]
  node_utils_response["API response<br/>response helper<br/>[apiResponse.js]"]
  node_utils_token["Token utils<br/>auth helper<br/>[token.js]"]
  node_validators_register["Register schema<br/>zod schema"]
  node_validators_project["Project schema<br/>zod schema"]
end

node_app_js -->|"mounts"| node_routes_index
node_routes_index -->|"registers"| node_routes_auth
node_routes_index -->|"registers"| node_routes_project
node_routes_index -->|"registers"| node_routes_problem
node_routes_index -->|"registers"| node_routes_profile
node_routes_index -->|"registers"| node_routes_search
node_routes_auth -->|"validates"| node_mw_validator
node_routes_auth -->|"handles"| node_ctl_auth
node_routes_project -->|"guards"| node_mw_auth
node_routes_project -->|"validates"| node_mw_validator
node_routes_project -->|"caches"| node_mw_cache
node_routes_project -->|"handles"| node_ctl_project
node_routes_problem -->|"validates"| node_mw_validator
node_routes_problem -->|"handles"| node_ctl_problem
node_routes_profile -->|"guards"| node_mw_auth
node_routes_profile -->|"handles"| node_ctl_profile
node_routes_search -->|"validates"| node_mw_query_validator
node_routes_search -->|"caches"| node_mw_cache
node_routes_search -->|"handles"| node_ctl_search
node_ctl_auth -->|"uses"| node_svc_auth
node_ctl_auth -->|"formats"| node_utils_response
node_svc_auth -->|"queries"| node_repo_user
node_svc_auth -->|"uses"| node_model_user
node_svc_auth -->|"issues"| node_utils_token
node_svc_auth -->|"depends on"| node_validators_register
node_ctl_project -->|"uses"| node_svc_project
node_svc_project -->|"queries"| node_repo_project
node_svc_project -->|"uses"| node_model_projects
node_svc_project -->|"formats"| node_utils_response
node_svc_project -->|"depends on"| node_validators_project
node_svc_project -->|"invalidates"| node_svc_cache
node_ctl_problem -->|"uses"| node_svc_problem
node_svc_problem -->|"queries"| node_repo_problem
node_svc_problem -->|"uses"| node_model_problems
node_svc_problem -->|"formats"| node_utils_response
node_ctl_profile -->|"uses"| node_svc_profile
node_svc_profile -->|"queries"| node_repo_user
node_svc_profile -->|"uses"| node_model_user
node_ctl_search -->|"uses"| node_svc_search
node_svc_search -->|"queries"| node_repo_project
node_svc_search -->|"queries"| node_repo_problem
node_svc_search -->|"reads"| node_svc_cache
node_svc_search -->|"formats"| node_utils_response
node_svc_cache -->|"configured by"| node_cacheconfig
node_svc_cache -->|"reports"| node_utils_response
node_repo_user -->|"connects via"| node_dbconfig
node_repo_project -->|"connects via"| node_dbconfig
node_repo_problem -->|"connects via"| node_dbconfig

click node_app_js "https://github.com/sonivaibhav-git/devdex/blob/main/app.js"
click node_routes_index "https://github.com/sonivaibhav-git/devdex/blob/main/routes/index.js"
click node_routes_auth "https://github.com/sonivaibhav-git/devdex/blob/main/routes/auth.routes.js"
click node_routes_project "https://github.com/sonivaibhav-git/devdex/blob/main/routes/project.routes.js"
click node_routes_problem "https://github.com/sonivaibhav-git/devdex/blob/main/routes/problem.routes.js"
click node_routes_profile "https://github.com/sonivaibhav-git/devdex/blob/main/routes/profile.routes.js"
click node_routes_search "https://github.com/sonivaibhav-git/devdex/blob/main/routes/search.routes.js"
click node_mw_auth "https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/auth.middleware.js"
click node_mw_validator "https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/validator.middleware.js"
click node_mw_query_validator "https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/queryValidator.middleware.js"
click node_mw_cache "https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/cache.middleware.js"
click node_ctl_auth "https://github.com/sonivaibhav-git/devdex/blob/main/controller/auth.controller.js"
click node_ctl_project "https://github.com/sonivaibhav-git/devdex/blob/main/controller/project.controller.js"
click node_ctl_problem "https://github.com/sonivaibhav-git/devdex/blob/main/controller/problem.controller.js"
click node_ctl_profile "https://github.com/sonivaibhav-git/devdex/blob/main/controller/profile.controller.js"
click node_ctl_search "https://github.com/sonivaibhav-git/devdex/blob/main/controller/search.controller.js"
click node_svc_auth "https://github.com/sonivaibhav-git/devdex/blob/main/service/auth.service.js"
click node_svc_project "https://github.com/sonivaibhav-git/devdex/blob/main/service/project.service.js"
click node_svc_problem "https://github.com/sonivaibhav-git/devdex/blob/main/service/problem.service.js"
click node_svc_profile "https://github.com/sonivaibhav-git/devdex/blob/main/service/profile.service.js"
click node_svc_search "https://github.com/sonivaibhav-git/devdex/blob/main/service/search.service.js"
click node_svc_cache "https://github.com/sonivaibhav-git/devdex/blob/main/service/cache.service.js"
click node_repo_user "https://github.com/sonivaibhav-git/devdex/blob/main/repositories/user.repo.js"
click node_repo_project "https://github.com/sonivaibhav-git/devdex/blob/main/repositories/project.repo.js"
click node_repo_problem "https://github.com/sonivaibhav-git/devdex/blob/main/repositories/problem.repo.js"
click node_model_user "https://github.com/sonivaibhav-git/devdex/blob/main/models/user.model.js"
click node_model_projects "https://github.com/sonivaibhav-git/devdex/blob/main/models/projects.model.js"
click node_model_problems "https://github.com/sonivaibhav-git/devdex/blob/main/models/problems.model.js"
click node_dbconfig "https://github.com/sonivaibhav-git/devdex/blob/main/config/dbconfig.js"
click node_cacheconfig "https://github.com/sonivaibhav-git/devdex/blob/main/config/cacheConfig.js"
click node_utils_response "https://github.com/sonivaibhav-git/devdex/blob/main/utils/apiResponse.js"
click node_utils_token "https://github.com/sonivaibhav-git/devdex/blob/main/utils/token.js"
click node_validators_register "https://github.com/sonivaibhav-git/devdex/blob/main/validators/register.validators.js"
click node_validators_project "https://github.com/sonivaibhav-git/devdex/blob/main/validators/project.validators.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_app_js,node_routes_index,node_routes_auth,node_routes_project,node_routes_problem,node_routes_profile,node_routes_search,node_mw_auth,node_mw_validator,node_mw_query_validator,node_mw_cache toneBlue
class node_ctl_auth,node_ctl_project,node_ctl_problem,node_ctl_profile,node_ctl_search,node_svc_auth,node_svc_project,node_svc_problem,node_svc_profile,node_svc_search toneAmber
class node_repo_user,node_repo_project,node_repo_problem,node_model_user,node_model_projects,node_model_problems,node_dbconfig toneMint
class node_svc_cache,node_cacheconfig,node_utils_response,node_utils_token,node_validators_register,node_validators_project toneRose
```

## Components

### HTTP layer

Express bootstrap, route composition, and request gates.

- [app.js](https://github.com/sonivaibhav-git/devdex/blob/main/app.js): Express bootstrap · Assembles middleware, routes, and application wiring. · `app.js`
- [Routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/index.js): router composition · Top-level route registration and API mounting. · `routes/index.js`
- [Auth routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/auth.routes.js): HTTP routes · Authentication endpoints for signup, login, and sessions. · `routes/auth.routes.js`
- [Project routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/project.routes.js): HTTP routes · Project showcase endpoints. · `routes/project.routes.js`
- [Problem routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/problem.routes.js): HTTP routes · Problem statement endpoints. · `routes/problem.routes.js`
- [Profile routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/profile.routes.js): HTTP routes · User profile endpoints. · `routes/profile.routes.js`
- [Search routes](https://github.com/sonivaibhav-git/devdex/blob/main/routes/search.routes.js): HTTP routes · Discovery and filtering endpoints. · `routes/search.routes.js`
- [Auth guard](https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/auth.middleware.js): middleware · Protects authenticated routes with JWT/session checks. · `middlewares/auth.middleware.js`
- [Body validation](https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/validator.middleware.js): middleware · Validates request bodies before controllers run. · `middlewares/validator.middleware.js`
- [Query validation](https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/queryValidator.middleware.js): middleware · Validates query parameters for search and listing flows. · `middlewares/queryValidator.middleware.js`
- [Cache gate](https://github.com/sonivaibhav-git/devdex/blob/main/middlewares/cache.middleware.js): middleware · Handles cached read paths and cache lookups. · `middlewares/cache.middleware.js`

### Domain layer

Controllers and services for auth, profiles, projects, problems, and search.

- [Auth controller](https://github.com/sonivaibhav-git/devdex/blob/main/controller/auth.controller.js): controller · Coordinates signup, login, and token issuance. · `controller/auth.controller.js`
- [Project controller](https://github.com/sonivaibhav-git/devdex/blob/main/controller/project.controller.js): controller · Coordinates project showcase requests. · `controller/project.controller.js`
- [Problem controller](https://github.com/sonivaibhav-git/devdex/blob/main/controller/problem.controller.js): controller · Coordinates problem content requests. · `controller/problem.controller.js`
- [Profile controller](https://github.com/sonivaibhav-git/devdex/blob/main/controller/profile.controller.js): controller · Coordinates user profile requests. · `controller/profile.controller.js`
- [Search controller](https://github.com/sonivaibhav-git/devdex/blob/main/controller/search.controller.js): controller · Coordinates discovery and filtering requests. · `controller/search.controller.js`
- [Auth service](https://github.com/sonivaibhav-git/devdex/blob/main/service/auth.service.js): service · Implements authentication rules and token/session logic. · `service/auth.service.js`
- [Project service](https://github.com/sonivaibhav-git/devdex/blob/main/service/project.service.js): service · Implements project showcase business rules. · `service/project.service.js`
- [Problem service](https://github.com/sonivaibhav-git/devdex/blob/main/service/problem.service.js): service · Implements problem statement business rules. · `service/problem.service.js`
- [Profile service](https://github.com/sonivaibhav-git/devdex/blob/main/service/profile.service.js): service · Implements profile operations and updates. · `service/profile.service.js`
- [Search service](https://github.com/sonivaibhav-git/devdex/blob/main/service/search.service.js): service · Implements portfolio search and filtering. · `service/search.service.js`

### Persistence layer

Repositories, Mongoose models, and database connection.

- [User repo](https://github.com/sonivaibhav-git/devdex/blob/main/repositories/user.repo.js): repository · Mongo access for users and profile-related queries. · `repositories/user.repo.js`
- [Project repo](https://github.com/sonivaibhav-git/devdex/blob/main/repositories/project.repo.js): repository · Mongo access for project records. · `repositories/project.repo.js`
- [Problem repo](https://github.com/sonivaibhav-git/devdex/blob/main/repositories/problem.repo.js): repository · Mongo access for problem records. · `repositories/problem.repo.js`
- [User model](https://github.com/sonivaibhav-git/devdex/blob/main/models/user.model.js): mongoose model · Persistent user schema. · `models/user.model.js`
- [Projects model](https://github.com/sonivaibhav-git/devdex/blob/main/models/projects.model.js): mongoose model · Persistent project narrative schema. · `models/projects.model.js`
- [Problems model](https://github.com/sonivaibhav-git/devdex/blob/main/models/problems.model.js): mongoose model · Persistent problem statement schema. · `models/problems.model.js`
- [DB config](https://github.com/sonivaibhav-git/devdex/blob/main/config/dbconfig.js): database config · MongoDB connection setup. · `config/dbconfig.js`

### Shared concerns

Caching, response helpers, tokens, slugging, and validation schemas.

- [Cache service](https://github.com/sonivaibhav-git/devdex/blob/main/service/cache.service.js): cache service · Shared cache read/write and invalidation logic. · `service/cache.service.js`
- [Cache config](https://github.com/sonivaibhav-git/devdex/blob/main/config/cacheConfig.js): cache config · Cache backend configuration and wiring. · `config/cacheConfig.js`
- [API response](https://github.com/sonivaibhav-git/devdex/blob/main/utils/apiResponse.js): response helper · Standardized success and error payloads. · `utils/apiResponse.js`
- [Token utils](https://github.com/sonivaibhav-git/devdex/blob/main/utils/token.js): auth helper · JWT creation and token handling helpers. · `utils/token.js`
- [Register schema](https://github.com/sonivaibhav-git/devdex/blob/main/validators/register.validators.js): zod schema · Validation for auth/signup payloads. · `validators/register.validators.js`
- [Project schema](https://github.com/sonivaibhav-git/devdex/blob/main/validators/project.validators.js): zod schema · Validation for project payloads. · `validators/project.validators.js`

## Connections

- app.js → Routes: mounts · Application bootstraps the route registry.
- Routes → Auth routes: registers · Top-level routing mounts auth endpoints.
- Routes → Project routes: registers · Top-level routing mounts project endpoints.
- Routes → Problem routes: registers · Top-level routing mounts problem endpoints.
- Routes → Profile routes: registers · Top-level routing mounts profile endpoints.
- Routes → Search routes: registers · Top-level routing mounts search endpoints.
- Auth routes → Body validation: validates · Auth routes validate incoming payloads.
- Auth routes → Auth controller: handles · Auth routes delegate to the controller.
- Project routes → Auth guard: guards · Project routes require authentication for protected actions.
- Project routes → Body validation: validates · Project routes validate payloads.
- Project routes → Cache gate: caches · Read paths can be served through cache.
- Project routes → Project controller: handles · Project routes delegate to the controller.
- Problem routes → Body validation: validates · Problem routes validate payloads.
- Problem routes → Problem controller: handles · Problem routes delegate to the controller.
- Profile routes → Auth guard: guards · Profile routes require authenticated access.
- Profile routes → Profile controller: handles · Profile routes delegate to the controller.
- Search routes → Query validation: validates · Search routes validate query parameters.
- Search routes → Cache gate: caches · Search reads can be cached.
- Search routes → Search controller: handles · Search routes delegate to the controller.
- Auth controller → Auth service: uses · Controller coordinates authentication logic through the service.
- Auth controller → API response: formats · Controller returns standardized API responses.
- Auth service → User repo: queries · Auth service persists and looks up users.
- Auth service → User model: uses · User records are backed by the user model.
- Auth service → Token utils: issues · Auth service creates tokens.
- Auth service → Register schema: depends on · Signup input shape is enforced by schema validation.
- Project controller → Project service: uses · Project controller delegates to business logic.
- Project service → Project repo: queries · Project service reads and writes showcase records.
- Project service → Projects model: uses · Project records are backed by the projects model.
- Project service → API response: formats · Service results are returned in a consistent envelope.
- Project service → Project schema: depends on · Project payloads are validated before persistence.
- Project service → Cache service: invalidates · Project changes can invalidate cached reads.
- Problem controller → Problem service: uses · Problem controller delegates to business logic.
- Problem service → Problem repo: queries · Problem service reads and writes problem records.
- Problem service → Problems model: uses · Problem records are backed by the problems model.
- Problem service → API response: formats · Service results are returned in a consistent envelope.
- Profile controller → Profile service: uses · Profile controller delegates to profile logic.
- Profile service → User repo: queries · Profile service works through the user repository.
- Profile service → User model: uses · Profile data is persisted in the user model.
- Search controller → Search service: uses · Search controller delegates to discovery logic.
- Search service → Project repo: queries · Search typically indexes project content.
- Search service → Problem repo: queries · Search can also surface problem content.
- Search service → Cache service: reads · Search results can be cached for reuse.
- Search service → API response: formats · Search responses use standardized payloads.
- Cache service → Cache config: configured by · Cache behavior is driven by shared configuration.
- Cache service → API response: reports · Cache operations return structured responses.
- User repo → DB config: connects via · User repository uses the MongoDB connection.
- Project repo → DB config: connects via · Project repository uses the MongoDB connection.
- Problem repo → DB config: connects via · Problem repository uses the MongoDB connection.
