How saianandmohan-cts/healthcarebe works
1. Overall shape
- This is a Node.js/Express REST backend for a healthcare portal, centered on role-based workflows for PATIENT and DOCTOR.
- The main runtime path is: HTTP request → route → middleware → controller → Mongoose model → MongoDB.
2. Bootstrap and server boundary
- server.js and app.js are the entry points that likely split bootstrapping from Express app setup.
- db.config.js is the database boundary, responsible for connecting the app to MongoDB/Mongoose before request handling begins.
3. API surface
- Route modules define the public API boundaries:
- authRoutes.js for login/session-related flows
- registrationRoutes.js for onboarding/registration
- patientRoutes.js, doctorRoutes.js for role-specific resources
- doc_availabilityRoutes.js for doctor schedule management
- These routes are the main integration points for clients.
4. Authentication and session model
- The repository uses JWTs stored in HttpOnly cookies, so auth state is managed server-side at the transport boundary rather than in browser storage.
- authController.js and middleware/auth.js appear to implement login/session restoration plus role checks, with the README calling out endpoints like /login/me and guards such as verifyPatient and verifyDoctor.
5. Security middleware layer
- src/middleware/auth.js is the key security checkpoint for token verification, cookie creation/handling, and role authorization.
- logger.js and errorHandler.js provide cross-cutting concerns: request tracing and centralized error response handling.
6. Domain controllers
- Controllers break business logic into healthcare-specific domains:
- appointmentController.js for appointment lifecycle and categorization
- doctorController.js for doctor dashboard and schedule-related operations
- patientController.js and userController.js for patient/user record operations
- doc_availabilityController.js for availability slots
- authController.js for authentication and session sync
- This keeps route handlers thin and makes each domain independently understandable.
7. Persistence models
- Mongoose models define the persistence layer and map directly to core business entities:
- patient.js
- doctor.js
- appointment.js
- doc_availability.js
- consultations.js
- The presence of both appointment and consultations suggests a split between scheduled visits and completed/historical clinical records.
8. Scheduling and time-based logic
- utils/decodedDate.js supports date normalization or timezone-aware comparisons, which is important for appointment state classification.
- The README describes logic for separating upcoming appointments from past consultations, so date handling is a meaningful architectural concern.
9. Document/report generation
- utils/pdfGenerator.js indicates an output side channel for generating PDFs, likely for medical summaries, reports, or appointment documents.
- This is a separate utility boundary from the core CRUD flows.
10. Validation boundary
- validators/registrationSchema.js and validators/registrationRules.js enforce input constraints for onboarding flows before controller logic runs.
- This prevents invalid patient/doctor registration payloads from reaching persistence.
11. Data and seed-like assets
- src/data/users.json is a local data asset, likely for seed/test/mock user data or bootstrapping.
- It is not the primary system of record; MongoDB remains the authoritative persistence layer.
12. Important external dependencies
- The architecture materially depends on Express, Mongoose/MongoDB Atlas, JWT, bcrypt, and cookie-parser.
- bcrypt is used for password hashing, while JWT + cookies implement the authenticated session boundary.
13. How a request typically flows
- A registration or login request enters via a route, passes validation/auth middleware, reaches a controller, and then reads/writes a Mongoose model.
- Protected doctor/patient endpoints first pass authorization checks, then execute domain logic such as availability updates, appointment filtering, or record retrieval.
14. Architectural takeaway
- The repo is organized as a modular healthcare backend with clear separation between transport, security, domain logic, and persistence.
- For diagramming, the most important boundaries are: public routes, auth/role middleware, domain controllers, Mongoose models, and MongoDB.
Main entry points: app.js app.js · authController.js Auth controller · registrationRoutes.js Registration routes · doctorController.js Doctor controller
Components 27
Bootstrap
App startup, server wiring, and database connection.
- server.js · Process bootstrap and listener startup.
server.js - app.js · Express application setup and route/middleware wiring.
app.js - db.config.js · Database connection boundary for Mongoose/MongoDB.
src/config/db.config.js
API Routes
Public HTTP boundaries for auth, registration, and role-specific resources.
- Auth routes · Login and session-related endpoints.
src/routes/authRoutes.js - Registration routes · Onboarding and registration endpoints.
src/routes/registrationRoutes.js - Patient routes · Patient-facing resource endpoints.
src/routes/patientRoutes.js - Doctor routes · Doctor-facing resource endpoints.
src/routes/doctorRoutes.js - Availability routes · Doctor schedule and availability endpoints.
src/routes/doc_availabilityRoutes.js
Security & Middleware
Cross-cutting request processing for auth, logging, and errors.
- Auth middleware · JWT verification, cookie handling, and role guards.
src/middleware/auth.js - Logger · Request tracing and logging.
src/middleware/logger.js - Error handler · Centralized error response handling.
src/middleware/errorHandler.js
Domain Logic
Controllers, models, validation, and supporting utilities.
- Auth controller · Login, session sync, and auth flow coordination.
src/controllers/authController.js - Appointments · Appointment lifecycle and visit classification.
src/controllers/appointmentController.js - Doctor controller · Doctor dashboard and schedule operations.
src/controllers/doctorController.js - Patient controller · Patient record and profile operations.
src/controllers/patientController.js - User controller · General user record operations.
src/controllers/userController.js - Availability controller · Availability slot management.
src/controllers/doc_availabilityController.js - Patient · Patient persistence model.
src/models/patient.js - Doctor · Doctor persistence model.
src/models/doctor.js - Appointment · Scheduled visit persistence model.
src/models/appointment.js - Consultations · Completed or historical clinical records.
src/models/consultations.js - Availability · Doctor schedule slot persistence model.
src/models/doc_availability.js - Registration schema · Input schema for registration payloads.
src/validators/registrationSchema.js - Registration rules · Registration constraints and checks.
src/validators/registrationRules.js - Date utils · Date normalization and comparison helpers.
src/utils/decodedDate.js - PDF generator · Document/report generation boundary.
src/utils/pdfGenerator.js - users.json · Local user data for seeding or mock data.
src/data/users.json
Connections 34
- server.js → app.js: starts · Server bootstraps the Express application.
- app.js → db.config.js: connects · Application initializes database connectivity.
- app.js → Logger: uses · Global request logging is applied in the app.
- app.js → Error handler: uses · Central error handling is mounted in the app.
- app.js → Auth routes: mounts · Auth endpoints are exposed through the Express app.
- app.js → Registration routes: mounts · Registration endpoints are exposed through the Express app.
- app.js → Patient routes: mounts · Patient endpoints are exposed through the Express app.
- app.js → Doctor routes: mounts · Doctor endpoints are exposed through the Express app.
- app.js → Availability routes: mounts · Availability endpoints are exposed through the Express app.
- Auth routes → Auth controller: calls · Authentication requests are handled by the auth controller.
- Registration routes → Registration schema: validates · Registration payloads are checked against schema rules.
- Registration routes → Registration rules: validates · Registration payloads are checked against business rules.
- Registration routes → Auth controller: calls · Onboarding flows reuse auth/session logic.
- Patient routes → Auth middleware: guards · Patient routes require token and role verification.
- Patient routes → Patient controller: calls · Patient endpoints delegate to patient logic.
- Doctor routes → Auth middleware: guards · Doctor routes require token and role verification.
- Doctor routes → Doctor controller: calls · Doctor endpoints delegate to doctor logic.
- Availability routes → Auth middleware: guards · Availability routes are protected by auth middleware.
- Availability routes → Availability controller: calls · Availability endpoints delegate to schedule logic.
- Auth controller → Patient: reads/writes · Auth flow may touch patient records.
- Auth controller → Doctor: reads/writes · Auth flow may touch doctor records.
- Auth controller → Appointment: reads/writes · Session-aware flows may inspect appointments.
- Patient controller → Patient: reads/writes · Patient operations persist to patient model.
- Patient controller → Appointment: reads/writes · Patient views can include appointment data.
- Doctor controller → Doctor: reads/writes · Doctor operations persist to doctor model.
- Doctor controller → Appointment: reads/writes · Doctor dashboard logic uses appointment data.
- Doctor controller → Consultations: reads/writes · Completed visits are tracked as consultations.
- Availability controller → Availability: reads/writes · Availability management persists schedule slots.
- Availability controller → Doctor: reads/writes · Availability updates are tied to doctors.
- Appointments → Appointment: reads/writes · Appointment lifecycle is stored in appointment records.
- Appointments → Consultations: reads/writes · Past appointments can be promoted to consultations.
- Appointments → Date utils: uses · Date helpers support appointment classification.
- Auth controller → PDF generator: uses · Auth or account flows may generate documents.
- Registration routes → users.json: loads · Local user data can support bootstrap or mock flows.