# sukhithms25/code_d-b architecture

> Architecture diagram of the GitHub repository sukhithms25/code_d-b, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sukhithms25/code_d-b
- Repository: https://github.com/sukhithms25/code_d-b

## Overview

1. **Overall shape**
   - This is a **Node.js/Express backend** organized as a layered API service.
   - The main request path is: **HTTP route → middleware → controller → service → Mongoose model/database**.
   - The codebase is domain-sliced by feature area rather than by generic technical layer alone.

2. **Entry and bootstrap**
   - `server.js` is the process entry point, with `src/app.js` assembling the Express app.
   - Startup is driven by centralized configuration in `src/config`, including environment validation, database connection, OpenAPI/Swagger setup, GitHub/OpenAI config, and runtime settings.
   - This is important for the diagram because nearly all subsystems depend on the config layer before handling requests.

3. **Core domain boundaries**
   - The repository is split into major business domains:
     - **Auth**: registration, login, token refresh/logout, password reset flows.
     - **Student**: profiles, progress, roadmap generation, resume upload/analyze, recommendations.
     - **HOD**: analytics dashboard, rankings, alerts, student detail views, announcements.
     - **AI**: chatbot, resume analysis, roadmap generation, resource recommendations.
     - **Integrations**: GitHub OAuth/sync, LeetCode sync, integration status, resource feeds.
     - **Notifications**: list/read/mark-read operations.
   - These are represented consistently in `routes/`, `controllers/`, and `services/`.

4. **Request handling pattern**
   - Routes in `src/routes/*.routes.js` map to feature controllers.
   - Controllers are thin orchestration points: they validate inputs, call services, and shape responses.
   - Shared middleware handles cross-cutting concerns such as authentication, role checks, validation, rate limiting, logging, CORS, security headers, and file uploads.
   - This separation is a key architectural boundary: routes/controllers do not appear to contain heavy business logic.

5. **Persistence and data model**
   - MongoDB is the primary datastore, accessed through **Mongoose** models in `src/models`.
   - Core entities include `User`, `Progress`, `Roadmap`, `Notification`, `Integration`, `Announcement`, and `Resource`.
   - The database layer supports both student-centric activity tracking and department-level aggregation for HOD analytics.
   - `src/models/index.js` suggests a consolidated model export boundary.

6. **AI subsystem**
   - AI features are isolated under `src/services/ai` and exposed through `src/controllers/ai` and student-facing equivalents.
   - Main capabilities:
     - **Resume analysis** for skill extraction.
     - **Roadmap generation** for personalized learning paths.
     - **Resource recommendation**.
     - **Chatbot** interactions.
   - The OpenAI API is a material external dependency, and AI requests are likely routed through the service layer to keep prompt logic and provider integration separate from controllers.

7. **Student performance and scoring**
   - Student progress is not just stored; it is **computed** via a scoring subsystem in `src/services/scoring`.
   - Services such as `scoringAlgorithmService`, `gradeCalculatorService`, and `consistencyTrackerService` indicate a derived-metrics pipeline.
   - HOD analytics, rankings, top/low performer views, and alerts depend on these computed scores rather than raw activity alone.

8. **Integrations and external sync**
   - `src/services/integrations` and corresponding controllers handle external platforms:
     - **GitHub** for activity/profile sync.
     - **LeetCode** for problem-solving activity and streaks.
     - **LinkedIn** appears as a service layer integration, likely for profile enrichment or future support.
   - `src/config/github.js` and the integration controllers indicate OAuth/token-based connection flows.
   - This subsystem feeds data into progress scoring, dashboards, and notifications.

9. **File and notification pipelines**
   - Resume upload flows use middleware plus file services: validation, upload, and S3 storage.
   - Notifications are a standalone subsystem backed by database records and an email service.
   - Email templates in `src/templates/emails` support transactional messages such as welcome, password reset, weekly progress, roadmap reminders, and low performer alerts.
   - This creates two notification channels: **in-app notifications** and **email delivery**.

10. **Background jobs and automation**
   - Scheduled jobs live in `src/jobs`, with distinct automated tasks for cleanup, reminders, and weekly reporting.
   - These jobs likely consume the same services/models as the request handlers, but run out-of-band from HTTP traffic.
   - This is a separate execution path worth showing in the architecture diagram: **cron-triggered jobs → services → database/email/external APIs**.

11. **Security and cross-cutting middleware**
   - Authentication is JWT-based with role-based authorization for student vs HOD access.
   - Middleware also covers validation, rate limiting, error normalization, request logging, helmet/CORS, and file upload handling.
   - `src/utils/errorMiddleware`, `AppError`, and `catchAsync` suggest a consistent error-handling contract across the whole API.

12. **Testing and operational tooling**
   - The repo includes Jest and Supertest integration/unit coverage, with fixtures for users, evaluations, and roadmaps.
   - Scripts support seeding, data migration, smoke testing, and algorithm verification.
   - Deployment artifacts (`vercel.json`, `.nvmrc`, environment examples) show the service is designed to be run as a standalone backend API with external dependencies configured via environment variables.

Main entry points: [`src/routes/index.js`](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/index.js) (Routes), [`src/models/index.js`](https://github.com/sukhithms25/code_d-b/blob/main/src/models/index.js) (Models), [`src/services/notifications/notificationService.js`](https://github.com/sukhithms25/code_d-b/blob/main/src/services/notifications/notificationService.js) (Notification Logic), [`src/app.js`](https://github.com/sukhithms25/code_d-b/blob/main/src/app.js) (App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_bootstrap["Bootstrap"]
  node_server_js(("server.js<br/>entrypoint<br/>[server.js]"))
  node_app_js["App<br/>[app.js]"]
  node_config_index["Config<br/>[index.js]"]
end

subgraph group_group_http["HTTP API"]
  node_routes_index["Routes<br/>route map<br/>[index.js]"]
  node_middleware_index["Middleware<br/>cross-cutting<br/>[index.js]"]
  node_auth_routes["Auth API<br/>route slice<br/>[auth.routes.js]"]
  node_student_routes["Student API<br/>route slice<br/>[student.routes.js]"]
  node_hod_routes["HOD API<br/>route slice<br/>[hod.routes.js]"]
  node_integrations_routes["Integrations API<br/>route slice"]
  node_notifications_routes["Notifications API<br/>route slice"]
  node_ai_routes["AI API<br/>route slice<br/>[ai.routes.js]"]
end

subgraph group_group_domains["Domain Services"]
  node_auth_services["Auth Logic<br/>service layer<br/>[tokenService.js]"]
  node_student_services["Student Logic<br/>service layer"]
  node_ai_services["AI Engine<br/>service layer<br/>[chatbotService.js]"]
  node_scoring_services["Scoring Engine<br/>derived metrics"]
  node_integration_services["Sync Services<br/>integration layer<br/>[githubService.js]"]
  node_notification_services["Notification Logic<br/>service layer"]
end

subgraph group_group_data["Data & Automation"]
  node_models[("Models<br/>[index.js]")]
  node_jobs["Jobs<br/>scheduled tasks<br/>[scheduledJobs.js]"]
  node_templates["Email Templates"]
end

node_server_js -->|"bootstraps"| node_app_js
node_app_js -->|"loads"| node_config_index
node_app_js -->|"attaches"| node_middleware_index
node_app_js -->|"mounts"| node_routes_index
node_routes_index -->|"includes"| node_auth_routes
node_routes_index -->|"includes"| node_student_routes
node_routes_index -->|"includes"| node_hod_routes
node_routes_index -->|"includes"| node_integrations_routes
node_routes_index -->|"includes"| node_notifications_routes
node_routes_index -->|"includes"| node_ai_routes
node_auth_routes -->|"calls"| node_auth_services
node_student_routes -->|"calls"| node_student_services
node_student_routes -->|"uses"| node_ai_services
node_hod_routes -->|"reads"| node_scoring_services
node_hod_routes -->|"calls"| node_student_services
node_integrations_routes -->|"calls"| node_integration_services
node_notifications_routes -->|"calls"| node_notification_services
node_ai_routes -->|"calls"| node_ai_services
node_auth_services -->|"persists"| node_models
node_student_services -->|"persists"| node_models
node_scoring_services -->|"computes"| node_models
node_integration_services -->|"syncs"| node_models
node_notification_services -->|"stores"| node_models
node_notification_services -->|"renders"| node_templates
node_jobs -->|"runs"| node_notification_services
node_jobs -->|"recomputes"| node_scoring_services
node_jobs -->|"reads/writes"| node_models
node_ai_services -->|"depends on"| node_config_index
node_integration_services -->|"depends on"| node_config_index
node_student_services -->|"uses"| node_scoring_services
node_notification_services -->|"uses"| node_auth_services

click node_server_js "https://github.com/sukhithms25/code_d-b/blob/main/server.js"
click node_app_js "https://github.com/sukhithms25/code_d-b/blob/main/src/app.js"
click node_config_index "https://github.com/sukhithms25/code_d-b/blob/main/src/config/index.js"
click node_routes_index "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/index.js"
click node_middleware_index "https://github.com/sukhithms25/code_d-b/blob/main/src/middleware/index.js"
click node_auth_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/auth.routes.js"
click node_student_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/student.routes.js"
click node_hod_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/hod.routes.js"
click node_integrations_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/integrations.routes.js"
click node_notifications_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/notifications.routes.js"
click node_ai_routes "https://github.com/sukhithms25/code_d-b/blob/main/src/routes/ai.routes.js"
click node_auth_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/auth/tokenService.js"
click node_student_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/notifications/notificationService.js"
click node_ai_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/ai/chatbotService.js"
click node_scoring_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/scoring/scoringAlgorithmService.js"
click node_integration_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/integrations/githubService.js"
click node_notification_services "https://github.com/sukhithms25/code_d-b/blob/main/src/services/notifications/notificationService.js"
click node_models "https://github.com/sukhithms25/code_d-b/blob/main/src/models/index.js"
click node_jobs "https://github.com/sukhithms25/code_d-b/blob/main/src/jobs/scheduledJobs.js"
click node_templates "https://github.com/sukhithms25/code_d-b/tree/main/src/templates/emails"

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_server_js,node_app_js,node_config_index toneBlue
class node_routes_index,node_middleware_index,node_auth_routes,node_student_routes,node_hod_routes,node_integrations_routes,node_notifications_routes,node_ai_routes toneAmber
class node_auth_services,node_student_services,node_ai_services,node_scoring_services,node_integration_services,node_notification_services toneMint
class node_models,node_jobs,node_templates toneRose
```

## Components

### Bootstrap

Process entry, app assembly, and centralized runtime configuration.

- [server.js](https://github.com/sukhithms25/code_d-b/blob/main/server.js): entrypoint · Process entry that starts the backend. · `server.js`
- [App](https://github.com/sukhithms25/code_d-b/blob/main/src/app.js): express app · Assembles the Express application and middleware wiring. · `src/app.js`
- [Config](https://github.com/sukhithms25/code_d-b/blob/main/src/config/index.js): runtime config · Central environment, database, OpenAPI, GitHub, and OpenAI setup. · `src/config/index.js`

### HTTP API

Routing, middleware, and controllers for request handling.

- [Routes](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/index.js): route map · Top-level API router composition. · `src/routes/index.js`
- [Middleware](https://github.com/sukhithms25/code_d-b/blob/main/src/middleware/index.js): cross-cutting · Authentication, roles, validation, logging, security, CORS, rate limits, and uploads. · `src/middleware/index.js`
- [Auth API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/auth.routes.js): route slice · Registration, login, token, and password reset endpoints. · `src/routes/auth.routes.js`
- [Student API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/student.routes.js): route slice · Profile, progress, roadmap, resume, score, and recommendations endpoints. · `src/routes/student.routes.js`
- [HOD API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/hod.routes.js): route slice · Analytics, rankings, alerts, and student oversight endpoints. · `src/routes/hod.routes.js`
- [Integrations API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/integrations.routes.js): route slice · GitHub, LeetCode, and resource sync endpoints. · `src/routes/integrations.routes.js`
- [Notifications API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/notifications.routes.js): route slice · List and read-state notification endpoints. · `src/routes/notifications.routes.js`
- [AI API](https://github.com/sukhithms25/code_d-b/blob/main/src/routes/ai.routes.js): route slice · Chat, resume analysis, roadmap generation, and resource recommendations. · `src/routes/ai.routes.js`

### Domain Services

Business logic for auth, student flows, AI, scoring, integrations, and notifications.

- [Auth Logic](https://github.com/sukhithms25/code_d-b/blob/main/src/services/auth/tokenService.js): service layer · Token, session, and password workflows. · `src/services/auth/tokenService.js`
- [Student Logic](https://github.com/sukhithms25/code_d-b/blob/main/src/services/notifications/notificationService.js): service layer · Profile, progress, roadmap, resume, and recommendation workflows. · `src/services/notifications/notificationService.js`
- [AI Engine](https://github.com/sukhithms25/code_d-b/blob/main/src/services/ai/chatbotService.js): service layer · Chatbot, resume analysis, roadmap generation, resource recommendation, and interest detection. · `src/services/ai/chatbotService.js`
- [Scoring Engine](https://github.com/sukhithms25/code_d-b/blob/main/src/services/scoring/scoringAlgorithmService.js): derived metrics · Progress scoring, grade calculation, and consistency tracking. · `src/services/scoring/scoringAlgorithmService.js`
- [Sync Services](https://github.com/sukhithms25/code_d-b/blob/main/src/services/integrations/githubService.js): integration layer · GitHub, LeetCode, and LinkedIn synchronization. · `src/services/integrations/githubService.js`
- [Notification Logic](https://github.com/sukhithms25/code_d-b/blob/main/src/services/notifications/notificationService.js): service layer · In-app notifications, email delivery, and reminders. · `src/services/notifications/notificationService.js`

### Data & Automation

Persistence models, scheduled jobs, and outbound email templates.

- [Models](https://github.com/sukhithms25/code_d-b/blob/main/src/models/index.js): mongoose models · User, Progress, Roadmap, Notification, Integration, Announcement, and Resource persistence. · `src/models/index.js`
- [Jobs](https://github.com/sukhithms25/code_d-b/blob/main/src/jobs/scheduledJobs.js): scheduled tasks · Cleanup, reminders, and weekly reports running outside HTTP traffic. · `src/jobs/scheduledJobs.js`
- [Email Templates](https://github.com/sukhithms25/code_d-b/tree/main/src/templates/emails): templates · Transactional email bodies for welcome, reset, roadmap, weekly progress, and alerts. · `src/templates/emails`

## Connections

- server.js → App: bootstraps · Starts the Express application.
- App → Config: loads · Initializes environment and runtime configuration.
- App → Middleware: attaches · Registers security, logging, validation, auth, and upload middleware.
- App → Routes: mounts · Connects the API router tree to the app.
- Routes → Auth API: includes · Mounts auth endpoints.
- Routes → Student API: includes · Mounts student endpoints.
- Routes → HOD API: includes · Mounts HOD endpoints.
- Routes → Integrations API: includes · Mounts integration endpoints.
- Routes → Notifications API: includes · Mounts notification endpoints.
- Routes → AI API: includes · Mounts AI endpoints.
- Auth API → Auth Logic: calls · Delegates authentication workflows.
- Student API → Student Logic: calls · Delegates student workflows.
- Student API → AI Engine: uses · Uses AI capabilities for resume and roadmap flows.
- HOD API → Scoring Engine: reads · Consumes derived scores for analytics and rankings.
- HOD API → Student Logic: calls · Fetches student details and summaries.
- Integrations API → Sync Services: calls · Handles OAuth and external sync workflows.
- Notifications API → Notification Logic: calls · Lists and updates notifications.
- AI API → AI Engine: calls · Exposes AI-backed features.
- Auth Logic → Models: persists · Uses user and session data.
- Student Logic → Models: persists · Reads and writes student progress and roadmap data.
- Scoring Engine → Models: computes · Derives metrics from persisted progress and evaluations.
- Sync Services → Models: syncs · Stores integration state and external activity.
- Notification Logic → Models: stores · Creates and updates notification records.
- Notification Logic → Email Templates: renders · Uses email templates for outbound messages.
- Jobs → Notification Logic: runs · Triggers reminder and reporting notifications.
- Jobs → Scoring Engine: recomputes · Refreshes derived scoring data on schedule.
- Jobs → Models: reads/writes · Cleans up and updates persisted records.
- AI Engine → Config: depends on · Uses OpenAI and provider settings.
- Sync Services → Config: depends on · Uses GitHub and integration credentials.
- Student Logic → Scoring Engine: uses · Feeds progress events into scoring.
- Notification Logic → Auth Logic: uses · Supports password reset and account emails.
