How sonivaibhav-git/devdex works
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: index.js Routes · project.service.js Project service · project.routes.js Project routes · auth.service.js Auth service
Components 34
HTTP layer
Express bootstrap, route composition, and request gates.
- app.js · Assembles middleware, routes, and application wiring.
app.js - Routes · Top-level route registration and API mounting.
routes/index.js - Auth routes · Authentication endpoints for signup, login, and sessions.
routes/auth.routes.js - Project routes · Project showcase endpoints.
routes/project.routes.js - Problem routes · Problem statement endpoints.
routes/problem.routes.js - Profile routes · User profile endpoints.
routes/profile.routes.js - Search routes · Discovery and filtering endpoints.
routes/search.routes.js - Auth guard · Protects authenticated routes with JWT/session checks.
middlewares/auth.middleware.js - Body validation · Validates request bodies before controllers run.
middlewares/validator.middleware.js - Query validation · Validates query parameters for search and listing flows.
middlewares/queryValidator.middleware.js - Cache gate · 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 · Coordinates signup, login, and token issuance.
controller/auth.controller.js - Project controller · Coordinates project showcase requests.
controller/project.controller.js - Problem controller · Coordinates problem content requests.
controller/problem.controller.js - Profile controller · Coordinates user profile requests.
controller/profile.controller.js - Search controller · Coordinates discovery and filtering requests.
controller/search.controller.js - Auth service · Implements authentication rules and token/session logic.
service/auth.service.js - Project service · Implements project showcase business rules.
service/project.service.js - Problem service · Implements problem statement business rules.
service/problem.service.js - Profile service · Implements profile operations and updates.
service/profile.service.js - Search service · Implements portfolio search and filtering.
service/search.service.js
Persistence layer
Repositories, Mongoose models, and database connection.
- User repo · Mongo access for users and profile-related queries.
repositories/user.repo.js - Project repo · Mongo access for project records.
repositories/project.repo.js - Problem repo · Mongo access for problem records.
repositories/problem.repo.js - User model · Persistent user schema.
models/user.model.js - Projects model · Persistent project narrative schema.
models/projects.model.js - Problems model · Persistent problem statement schema.
models/problems.model.js - DB config · MongoDB connection setup.
config/dbconfig.js
Shared concerns
Caching, response helpers, tokens, slugging, and validation schemas.
- Cache service · Shared cache read/write and invalidation logic.
service/cache.service.js - Cache config · Cache backend configuration and wiring.
config/cacheConfig.js - API response · Standardized success and error payloads.
utils/apiResponse.js - Token utils · JWT creation and token handling helpers.
utils/token.js - Register schema · Validation for auth/signup payloads.
validators/register.validators.js - Project schema · Validation for project payloads.
validators/project.validators.js
Connections 48
- 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.