# imohit1o1/medi-hub architecture

> Architecture diagram of the GitHub repository imohit1o1/medi-hub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imohit1o1/medi-hub
- Repository: https://github.com/imohit1o1/medi-hub

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) hospital management system called MediHub.
- It provides three user interfaces:
- A public‐facing React frontend for patients/visitors
- A React-based admin dashboard for healthcare staff
- A Node/Express REST API backend connected to MongoDB
- Key features: appointment scheduling, user authentication (JWT), file management (Cloudinary), payments, analytics.

##### File structure
- Top level:
- frontend/ – patient-facing SPA
- dashboard/ – admin SPA
- backend/ – Express API
- backend/src follows an MVC structure:
- controllers/ – business logic per resource (user, appointment, medicine, etc.)
- models/ – Mongoose schemas
- routes/ – Express routers mapping endpoints to controllers
- middlewares/ – auth, file upload (multer), error/async wrappers
- db/ – MongoDB connection
- utilis/ – helpers (ApiError, ApiResponse, JWT token, Cloudinary)
- frontend and dashboard both use:
- src/components, src/pages – UI composition
- src/Context – React Context for global state
- src/axios – HTTP client config
- Deployment/config files: .env.example, package.json, Vite config, ESLint, Prettier.

##### Extract README insights
- Confirms MERN stack, JWT auth, Cloudinary integration, analytics dashboard.
- Mentions separate frontend, backend, dashboard directories.

a. Main components
1. Public React Frontend (frontend/)
2. Admin React Dashboard (dashboard/)
3. Express REST API (backend/app.js → backend/src/routes & controllers)
4. MongoDB Database
5. External Services:
– Cloudinary for file storage
– JWT Authentication Provider (built-in)
– Payment Gateway (stripe/third-party) if integrated
b. Relationships & interactions
– Both frontends make HTTP(S) calls to the API’s endpoints (e.g., /api/user, /api/appointment).
– On login/signup, API issues JWT tokens, frontends store them and send in Authorization headers.
– API performs CRUD on MongoDB collections via Mongoose models.
– For image/document upload, API routes call Cloudinary util to store assets and return URLs.
– Payment endpoints interact with a third-party payment processor.
– Admin dashboard pulls analytics data from API (aggregate appointment/patient stats).
c. Architectural patterns
– Backend: MVC (Models, Views=Controllers, Routes), layered architecture (controllers → services/utilis → database).
– Frontend: Component-based React, Context API for global state (auth, cart).
– Separation of concerns: UI vs business logic vs data store.
d. Key technologies
– React.js + Vite + TailwindCSS on both frontends
– Axios for HTTP client
– Node.js + Express on backend
– MongoDB with Mongoose ODM
– Multer for file parsing, Cloudinary SDK for storage
– JWT for stateless auth

##### Detail
- Call out shared Context providers in frontends (AuthContext, CartContext).
- Rate-limiting, validation, error-handling middlewares.
- Development vs production config (ENV variables, .env.example).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        style Presentation Layer fill:none,stroke:none
        PF["Public React Frontend"]:::frontend
        AD["Admin React Dashboard"]:::dashboard
    end

    %% Application Layer
    subgraph "Application Layer"
        style Application Layer fill:none,stroke:none
        API["Express REST API"]:::backend
        subgraph Controllers
            UC["User Controller"]:::backend
            LL["Login/Logout Controller"]:::backend
            AC["Appointment Controller"]:::backend
            PC["Payment Controller"]:::backend
            AdminC["Admin Analytics Controller"]:::backend
        end
        subgraph Routes
            UR["User Routes"]:::backend
            LLR["Login/Logout Routes"]:::backend
            AR["Appointment Routes"]:::backend
            PR["Payment Routes"]:::backend
        end
        subgraph Models
            UM["User Model"]:::database
            AM["Appointment Model"]:::database
            PM["Payment Model"]:::database
        end
        subgraph Middlewares
            AuthM["Auth Middleware"]:::backend
            MulterM["Multer Middleware"]:::backend
        end
        subgraph Utils
            JWTU["JWT Utility"]:::backend
            CloudU["Cloudinary Utility"]:::backend
            ApiError["ApiError Helper"]:::backend
            ApiResp["ApiResponse Helper"]:::backend
            AsyncH["asyncHandler"]:::backend
        end
        DBConn["DB Connection"]:::database
    end

    %% Data Layer
    subgraph "Data Layer"
        style Data Layer fill:none,stroke:none
        MongoDB[(MongoDB)]:::db
        Cloudinary("Cloudinary"):::external
        PaymentGW("Payment Gateway"):::external
    end

    %% Presentation Sub-components
    subgraph PublicUI["Public React Frontend"]
        AuthCtx["AuthContext"]:::frontend
        AxiosF["Axios Config"]:::frontend
        ComponentsF["Components"]:::frontend
        PagesF["Pages"]:::frontend
    end

    subgraph AdminUI["Admin React Dashboard"]
        AuthCtxD["AuthContext"]:::dashboard
        AxiosD["Axios Config"]:::dashboard
        ComponentsD["Components"]:::dashboard
        PagesD["Pages"]:::dashboard
    end

    %% Connections
    PF -->|uses| AuthCtx
    PF -->|uses| AxiosF
    PF -->|renders| ComponentsF
    PF -->|renders| PagesF

    AD -->|uses| AuthCtxD
    AD -->|uses| AxiosD
    AD -->|renders| ComponentsD
    AD -->|renders| PagesD

    ComponentsF -->|HTTP calls| API
    PagesF -->|HTTP calls| API
    ComponentsD -->|HTTP calls| API
    PagesD -->|HTTP calls| API

    API -->|controllers| UC & LL & AC & PC & AdminC
    API -->|routes| UR & LLR & AR & PR
    API -->|models| UM & AM & PM
    Controllers -->|use models| Models
    Routes -->|invoke controllers| Controllers
    API -->|use middlewares| AuthM & MulterM
    Controllers -->|use utils| JWTU & CloudU & ApiError & ApiResp & AsyncH
    API -->|connect| DBConn
    DBConn -->|connects to| MongoDB
    AC -->|CRUD| MongoDB
    UC -->|CRUD| MongoDB
    PC -->|CRUD| MongoDB
    AdminC -->|aggregate| MongoDB

    AC -->|upload files| Cloudinary
    API -->|store files via| Cloudinary
    PC -->|process payments| PaymentGW
    PaymentGW -->|webhooks| API

    %% Click Events
    click PF "https://github.com/imohit1o1/medi-hub/tree/main/frontend/"
    click AD "https://github.com/imohit1o1/medi-hub/tree/main/dashboard/"
    click API "https://github.com/imohit1o1/medi-hub/blob/main/backend/app.js"
    click DBConn "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/db/dbConnection.js"
    click UC "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/controllers/user.controller.js"
    click LL "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/controllers/login_logout.controller.js"
    click AC "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/controllers/appointment.controller.js"
    click PC "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/controllers/payment.controller.js"
    click AdminC "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/controllers/admin.controller.js"
    click UR "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/routes/user.routes.js"
    click LLR "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/routes/user.routes.js"
    click AR "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/routes/appointment.routes.js"
    click PR "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/routes/payment.routes.js"
    click UM "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/models/user.model.js"
    click AM "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/models/appointment.model.js"
    click PM "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/models/payment.model.js"
    click AuthM "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/middlewares/auth.middleware.js"
    click MulterM "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/middlewares/multer.middleware.js"
    click JWTU "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/utilis/jwtToken.js"
    click CloudU "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/utilis/cloudinary.js"
    click ApiError "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/utilis/ApiError.js"
    click ApiResp "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/utilis/ApiResponse.js"
    click AsyncH "https://github.com/imohit1o1/medi-hub/blob/main/backend/src/utilis/asyncHandler.js"
    click AuthCtx "https://github.com/imohit1o1/medi-hub/blob/main/frontend/src/Context/Context.jsx"
    click AxiosF "https://github.com/imohit1o1/medi-hub/blob/main/frontend/src/axios/axios.jsx"
    click ComponentsF "https://github.com/imohit1o1/medi-hub/tree/main/frontend/src/components/"
    click PagesF "https://github.com/imohit1o1/medi-hub/tree/main/frontend/src/pages/"
    click AuthCtxD "https://github.com/imohit1o1/medi-hub/blob/main/dashboard/src/Context/Context.jsx"
    click AxiosD "https://github.com/imohit1o1/medi-hub/blob/main/dashboard/src/axios/axios.jsx"
    click ComponentsD "https://github.com/imohit1o1/medi-hub/tree/main/dashboard/src/components/"
    click PagesD "https://github.com/imohit1o1/medi-hub/tree/main/dashboard/src/pages/"

    %% Styles
    classDef frontend fill:#CFE2FF,stroke:#2B6CB0,color:#1A365D
    classDef dashboard fill:#E2E8F0,stroke:#4A5568,color:#2D3748
    classDef backend fill:#C6F6D5,stroke:#2F855A,color:#22543D
    classDef database fill:#FEEBC8,stroke:#DD6B20,color:#7B341E
    classDef db fill:#FEEBC8,stroke:#DD6B20,color:#7B341E
    classDef external fill:#EDF2F7,stroke:#A0AEC0,color:#4A5568
```
