How sukhithms25/code_d-b works
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: routes/index.js Routes · models/index.js Models · notificationService.js Notification Logic · app.js App
Components 20
Bootstrap
Process entry, app assembly, and centralized runtime configuration.
HTTP API
Routing, middleware, and controllers for request handling.
- Routes · Top-level API router composition.
src/routes/index.js - Middleware · Authentication, roles, validation, logging, security, CORS, rate limits, and uploads.
src/middleware/index.js - Auth API · Registration, login, token, and password reset endpoints.
src/routes/auth.routes.js - Student API · Profile, progress, roadmap, resume, score, and recommendations endpoints.
src/routes/student.routes.js - HOD API · Analytics, rankings, alerts, and student oversight endpoints.
src/routes/hod.routes.js - Integrations API · GitHub, LeetCode, and resource sync endpoints.
src/routes/integrations.routes.js - Notifications API · List and read-state notification endpoints.
src/routes/notifications.routes.js - AI API · 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 · Token, session, and password workflows.
src/services/auth/tokenService.js - Student Logic · Profile, progress, roadmap, resume, and recommendation workflows.
src/services/notifications/notificationService.js - AI Engine · Chatbot, resume analysis, roadmap generation, resource recommendation, and interest detection.
src/services/ai/chatbotService.js - Scoring Engine · Progress scoring, grade calculation, and consistency tracking.
src/services/scoring/scoringAlgorithmService.js - Sync Services · GitHub, LeetCode, and LinkedIn synchronization.
src/services/integrations/githubService.js - Notification Logic · In-app notifications, email delivery, and reminders.
src/services/notifications/notificationService.js
Data & Automation
Persistence models, scheduled jobs, and outbound email templates.
- Models · User, Progress, Roadmap, Notification, Integration, Announcement, and Resource persistence.
src/models/index.js - Jobs · Cleanup, reminders, and weekly reports running outside HTTP traffic.
src/jobs/scheduledJobs.js - Email Templates · Transactional email bodies for welcome, reset, roadmap, weekly progress, and alerts.
src/templates/emails
Connections 31
- 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.