# plutonurmux/doctor-appiontment architecture

> Architecture diagram of the GitHub repository plutonurmux/doctor-appiontment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/plutonurmux/doctor-appiontment
- Repository: https://github.com/plutonurmux/doctor-appiontment

## Overview

##### Project Type and Purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) web application called “Online Doctor Appointment.”
- It comprises a React SPA in the root/src and public directories, and a TypeScript/JavaScript Express API in the api directory.
- Purpose: allow patients to browse doctors, book appointments, view or cancel them, and provide dashboards for admins, doctors, and patients.

##### High-Level Component Breakdown
a. Frontend (React)
- Location: `/src` + static assets in `/public`
- Key pieces:
– Context/AuthContext for auth state
– Components grouped by feature (Home, Appointment, Dashboard, Login)
– Routing via React Router, protected routes via PrivateRoute
- UI libraries: React-Bootstrap, Material-UI, custom CSS, preloader, animations
b. Backend (Express API)
- Location: `/api/src`
- Layered MVC structure per domain module (auth, appointment, doctor, patient, payment, etc.)
– Routes → Controllers → Services → Models
- Middleware: auth, error handlers, catchAsync, global logger
- Utilities: JWT helper, Winston logging, error handlers, Mongoose models
- Config & constants for environment variables, CORS, body-parser, image uploader
c. Database
- MongoDB accessed via Mongoose (models under `api/models` and `api/src/app/modules/*/*.model.ts`)
d. External Services & Infrastructure
- JWT for stateless authentication
- Winston for structured logging (success & error logs)
- (Optional) Firebase for hosting (firebase.json, .firebaserc) or image storage
- Deployment: Netlify (frontend) & Node host (backend) or Firebase Hosting

##### Component Interactions and Data Flow
- User’s browser → React App → HTTP(S) API calls (REST) → Express routes → Controllers → Service layer → Mongoose → MongoDB
- Auth flow: React login form → `/api/auth/login` → JWT issued → stored in client (localStorage or cookie) → used in Authorization header for protected calls → auth middleware verifies token → route handlers
- Booking flow: React appointment UI → POST `/api/appointment` → validate + create record → response → UI updates
- Admin flow: React dashboard → GET `/api/patient` or `/api/doctor` → list CRUD → respond

##### Architectural Patterns & Design Principles
- Layered MVC on the backend, with clear separation of concerns
- Module-per-domain organization (each feature in its own folder)
- Centralized error handling and logging
- Stateless authentication via JWT
- Feature-driven component organization on the frontend

##### Essential Details
- All domain modules (Auth, Appointment, Doctor, Patient, Payment) as sub-components of the API layer
- The middleware chain (Auth, error handler, logger) intercepting incoming API calls
- The JWT authentication flow
- Logging destinations (Winston success/error files)
- Hosting/deployment boundaries (where the React bundle and API run)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlanes
    subgraph "Frontend (React SPA)" 
        direction TB
        Browser["User Browser"]:::frontend
        Browser -->|"renders"| ReactApp["React App"]:::frontend
        subgraph "React Application" 
            direction TB
            AppEntry["App.js / index.js"]:::frontend
            AuthCtx["AuthContext"]:::frontend
            PrivateRoute["PrivateRoute"]:::frontend
            HomeFeat["Home Components"]:::frontend
            ApptFeat["Appointment Components"]:::frontend
            DashFeat["Dashboard Components"]:::frontend
            LoginFeat["Login/Signup Components"]:::frontend
            SharedUI["Shared UI Components"]:::frontend
            Hooks["useFetch Hook"]:::frontend
        end
        ReactApp -->|"uses"| AppEntry
        ReactApp -->|"provides auth state"| AuthCtx
        ReactApp -->|"routes via React Router"| PrivateRoute
        ReactApp --> HomeFeat
        ReactApp --> ApptFeat
        ReactApp --> DashFeat
        ReactApp --> LoginFeat
        ReactApp --> SharedUI
        ReactApp --> Hooks
        AppEntry -->|"HTTP(S)/JSON"| API["Express API"]:::backend
    end

    subgraph "Backend (Express API)" 
        direction TB
        APIServer["api/src/server.ts"]:::backend
        AppSetup["api/src/app.ts"]:::backend
        APIServer --> AppSetup
        subgraph "Middleware Layer"
            direction TB
            AuthMW["auth.ts"]:::backend
            ErrorMW["globalErrorHandler.ts"]:::backend
            LoggerMW["logger.ts"]:::backend
        end
        AppSetup --> AuthMW
        AppSetup --> ErrorMW
        AppSetup --> LoggerMW
        subgraph "Routing Layer"
            direction TB
            Routes["app/routes/index.ts"]:::backend
            LegacyRoutes["api/routes/doctor.js"]:::backend
        end
        AppSetup --> Routes
        AppSetup --> LegacyRoutes
        subgraph "Controller Layer"
            direction TB
            ModulesCtrl["Modules Controllers"]:::backend
            LegacyCtrl["doctor.js / user.js"]:::backend
        end
        Routes --> ModulesCtrl
        LegacyRoutes --> LegacyCtrl
        subgraph "Service Layer"
            direction TB
            ModulesSvc["Modules Services"]:::backend
        end
        ModulesCtrl --> ModulesSvc
        subgraph "Data Access Layer (Mongoose Models)"
            direction TB
            DBModels["app/modules/*/*.model.ts"]:::backend
            LegacyModels["api/models/*.js"]:::backend
        end
        ModulesSvc --> DBModels
        LegacyCtrl --> LegacyModels

        subgraph "Shared Utils & Helpers"
            direction TB
            CatchAsync["catchAsync.ts"]:::backend
            SendResp["sendResponse.ts"]:::backend
            JWTHelper["jwtHelper.ts"]:::backend
            Constants["config & constants"]:::backend
            Errors["api/src/errors/"]:::backend
        end
        AppSetup --> Constants
        ModulesSvc --> CatchAsync
        ModulesSvc --> SendResp
        AuthMW --> JWTHelper
        AppSetup --> Errors
        ModulesSvc --> LoggerMW
    end

    subgraph "Database (MongoDB)" 
        direction TB
        MongoDB["MongoDB\n(Mongoose)"]:::database
    end

    subgraph "External Services & Deployment" 
        direction TB
        JWTService["JWT Auth Provider"]:::external
        WinstonLogs["Winston Logs\n(errors & successes)"]:::external
        Firebase["Firebase Hosting"]:::external
        Netlify["Netlify Hosting"]:::external
    end

    %% Data Flows
    API -->|"CRUD Ops"| MongoDB
    AuthMW -->|"verifies token"| JWTService
    LoggerMW -->|"writes logs"| WinstonLogs
    ReactApp -->|"deployed to"| Netlify
    AppSetup -->|"deployed to"| Firebase

    %% Click Events Frontend
    click ReactApp "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/"
    click Browser "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/public/"
    click AuthCtx "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Context/AuthContext.jsx"
    click AppEntry "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/src/App.js"
    click AppEntry "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/src/index.js"
    click PrivateRoute "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Login/PrivateRoute/PrivateRoute.js"
    click HomeFeat "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Home/"
    click ApptFeat "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/components/AppointMent/"
    click DashFeat "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Dashboard/"
    click LoginFeat "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Login/"
    click SharedUI "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/src/components/Shared/"
    click Hooks "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/src/components/hooks/useFetch.js"

    %% Click Events Backend
    click AppSetup "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app.ts"
    click APIServer "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/server.ts"
    click AuthMW "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/middlewares/auth.ts"
    click ErrorMW "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/middlewares/globalErrorHandler.ts"
    click Routes "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/routes/index.ts"
    click Constants "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/config/index.ts"
    click Constants "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/constants/index.ts"
    click Constants "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/enums/index.ts"
    click Errors "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/api/src/errors/"
    click CatchAsync "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/shared/catchAsync.ts"
    click SendResp "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/shared/sendResponse.ts"
    click JWTHelper "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/helpers/jwtHelper.ts"
    click DBModels "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/modules/auth/auth.model.ts"
    click ModulesCtrl "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/modules/auth/auth.controller.ts"
    click ModulesSvc "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/src/app/modules/auth/auth.service.ts"

    click LegacyCtrl "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/controllers/doctor.js"
    click LegacyCtrl "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/controllers/user.js"
    click LegacyRoutes "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/routes/doctor.js"
    click LegacyModels "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/models/Doctors.js"
    click LegacyModels "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/models/Users.js"

    click WinstonLogs "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/api/logs/winston/errors/"
    click WinstonLogs "https://github.com/plutonurmux/doctor-appiontment/tree/19-backend-folder-structure-update-follow-mvc-pattern/api/logs/winston/successes/"
    click Constants "https://github.com/plutonurmux/doctor-appiontment/blob/19-backend-folder-structure-update-follow-mvc-pattern/api/.env.example"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1976D2,color:#0D47A1
    classDef backend fill:#C8E6C9,stroke:#388E3C,color:#1B5E20
    classDef database fill:#FFE0B2,stroke:#F57C00,color:#E65100
    classDef external fill:#E0E0E0,stroke:#9E9E9E,color:#424242
```
