# sparshgarg31/mediclinic architecture

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

- Interactive diagram: https://gitdiagram.com/sparshgarg31/mediclinic
- Repository: https://github.com/sparshgarg31/mediclinic

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) application called “MediClinic.”
- Purpose: allow patients to register/login, browse doctor profiles, book or cancel appointments, and post reviews; doctors register/login, create and manage their profiles (experience, education), and view appointments and reviews in a dashboard.

##### File structure
A. Top-level directories/files:
- client/ → React single-page application
- config/keys.js → environment/configuration (DB URI, secrets)
- middleware/ → Express middleware for auth (authDoctor.js, authUser.js)
- models/ → Mongoose schemas (Doctor, Profile, User)
- routes/api/ → Express REST endpoints (authDoctor, authUser, appointment, doctors, profile, users)
- server.js → Node/Express server entry point
B. Client subtree (client/src):
- actions/ & reducers/ → Redux actions + reducers (authDoctor, authUser, appointment, profile, review, alert)
- components/ → React components organized by feature (auth, dashboard, profile management, booking, layout, routing, user views)
- store.js → Redux store setup
- utils/setAuthToken.js → helper to set JWT header
- public/ → static HTML, manifest, robots.txt

##### README insights
- Mentions MERN stack, runs with `npm run dev` in root to concurrently start Express (server) and React (client).
- Core features: doctor auth, user auth, profile CRUD, appointment booking/canceling, review posting/deleting, dashboard views.

a. Main components to include
1. React Frontend (client):
- Components (Auth, Booking Form, Dashboard, Profile, Reviews)
- Redux Store (Actions & Reducers)
2. Node/Express Backend (server):
- Route Handlers (REST API endpoints under routes/api/)
- Middleware (authDoctor, authUser, error handling)
- Controllers (business logic invoked by route handlers)
3. MongoDB (database):
- Collections: Users, Doctors, Profiles, Appointments, Reviews
4. External/Infrastructure
- JWT Authentication (token issued on login, stored in client local storage)
- Configuration Service (config/keys.js reads secrets)

b. Relationships and interactions
- Frontend → Backend: HTTP(S) requests to REST endpoints (e.g., POST /api/authUser, GET /api/doctors, POST /api/appointment)
- Backend → DB: Mongoose queries for CRUD operations on collections
- Frontend: React components dispatch Redux actions → triggers axios/fetch calls to API
- Middleware sits on the request path in the backend to validate JWT for protected routes (doctor vs. user)
- Data flow: User inputs → React forms → dispatch Redux action → API call → DB → response → Redux reducer updates store → UI rerenders

c. Architectural patterns & design principles
- Client side: Flux/Redux pattern (unidirectional data flow)
- Server side: MVC-like layering (Routes → Controllers/Services → Models)
- Separation of concerns:
- UI layer (React components)
- State management (Redux)
- API layer (Express routes + middleware)
- Data layer (Mongoose models + MongoDB)
- Authentication/Authorization via JWT and role-based middleware

d. Key technologies/frameworks
- React, Redux, React Router
- Express.js, Node.js
- MongoDB with Mongoose ODM
- JWT for auth, axios/fetch for HTTP client calls
- Concurrent run script (npm run dev) using nodemon and concurrently

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser/React)" 
        direction TB
        FE_APP["React App"]:::frontend
        FE_APP --> UI["UI Components"]:::ui
        FE_APP --> STORE["Redux Store"]:::state
        FE_APP --> HTTP_UTIL["HTTP Utility (setAuthToken)"]:::util

        subgraph "UI Components" 
            direction TB
            AUTH["Authentication Components"]:::ui
            BOOK["Booking Components"]:::ui
            DASH["Dashboard Components"]:::ui
            PROFILE_MGMT["Profile Management Components"]:::ui
            REVIEWS["Review Components"]:::ui
            LAYOUT["Layout & UI Helpers"]:::ui
            ROUTING["Private Route Guards"]:::ui
        end

        subgraph "State Management" 
            direction TB
            ACTIONS["Redux Actions"]:::state
            REDUCERS["Redux Reducers"]:::state
            STORE --> ACTIONS
            STORE --> REDUCERS
        end

        AUTH -->|"dispatch actions"| ACTIONS
        BOOK -->|"dispatch actions"| ACTIONS
        DASH -->|"dispatch actions"| ACTIONS
        PROFILE_MGMT -->|"dispatch actions"| ACTIONS
        REVIEWS -->|"dispatch actions"| ACTIONS

        HTTP_UTIL --> FE_APP
    end

    %% Backend Layer
    subgraph "Backend (Node/Express)" 
        direction TB
        SERVER["Express Server (server.js)"]:::backend
        CONFIG["Config & Secrets"]:::backend
        SERVER --> CONFIG
        SERVER --> ROUTES
        SERVER --> MIDDLEWARE

        subgraph "Middleware" 
            direction TB
            MD_AUTH_DOC["Doctor Auth Guard"]:::middleware
            MD_AUTH_USER["User Auth Guard"]:::middleware
            MIDDLEWARE --> MD_AUTH_DOC
            MIDDLEWARE --> MD_AUTH_USER
        end

        subgraph "API Routes" 
            direction TB
            ROUTES["Express Routes"]:::routes
            ROUTES --> API_AUTH_DOC["/api/authDoctor"]:::routes
            ROUTES --> API_AUTH_USER["/api/authUser"]:::routes
            ROUTES --> API_DOCTORS["/api/doctors"]:::routes
            ROUTES --> API_PROFILE["/api/profile"]:::routes
            ROUTES --> API_USERS["/api/users"]:::routes
            ROUTES --> API_APPT["/api/appointment"]:::routes
        end

        subgraph "Data Models" 
            direction TB
            MDL_DOCTOR["Doctor Model"]:::models
            MDL_USER["User Model"]:::models
            MDL_PROFILE["Profile Model"]:::models
        end

        ROUTES --> MDL_DOCTOR
        ROUTES --> MDL_USER
        ROUTES --> MDL_PROFILE

        MDL_DOCTOR --> DB
        MDL_USER --> DB
        MDL_PROFILE --> DB
    end

    %% Database
    DB["MongoDB"]:::database
    DB -->|"Collections: Users, Doctors, Profiles, Appointments, Reviews"| DB

    %% Frontend to Backend Interaction
    FE_APP -->|"HTTP (GET/POST) with JWT"| ROUTES

    %% Click Events
    click FE_APP "https://github.com/sparshgarg31/mediclinic/tree/master/client/"
    click AUTH "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/auth/"
    click BOOK "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/bookappointment/"
    click DASH "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/dashboard/"
    click PROFILE_MGMT "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/profile-forms/"
    click PROFILE_MGMT "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/profile/"
    click REVIEWS "https://github.com/sparshgarg31/mediclinic/blob/master/client/src/components/profile/ProfileReview.js"
    click REVIEWS "https://github.com/sparshgarg31/mediclinic/blob/master/client/src/components/profile/ReviewForm.js"
    click LAYOUT "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/layout/"
    click ROUTING "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/components/routing/"
    click STORE "https://github.com/sparshgarg31/mediclinic/blob/master/client/src/store.js"
    click ACTIONS "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/actions/"
    click REDUCERS "https://github.com/sparshgarg31/mediclinic/tree/master/client/src/reducers/"
    click HTTP_UTIL "https://github.com/sparshgarg31/mediclinic/blob/master/client/src/utils/setAuthToken.js"
    click SERVER "https://github.com/sparshgarg31/mediclinic/blob/master/server.js"
    click CONFIG "https://github.com/sparshgarg31/mediclinic/blob/master/config/keys.js"
    click MD_AUTH_DOC "https://github.com/sparshgarg31/mediclinic/blob/master/middleware/authDoctor.js"
    click MD_AUTH_USER "https://github.com/sparshgarg31/mediclinic/blob/master/middleware/authUser.js"
    click API_AUTH_DOC "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/authDoctor.js"
    click API_AUTH_USER "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/authUser.js"
    click API_DOCTORS "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/doctors.js"
    click API_PROFILE "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/profile.js"
    click API_USERS "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/users.js"
    click API_APPT "https://github.com/sparshgarg31/mediclinic/blob/master/routes/api/appointment.js"
    click MDL_DOCTOR "https://github.com/sparshgarg31/mediclinic/blob/master/models/Doctor.js"
    click MDL_USER "https://github.com/sparshgarg31/mediclinic/blob/master/models/User.js"
    click MDL_PROFILE "https://github.com/sparshgarg31/mediclinic/blob/master/models/Profile.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef ui fill:#E3F2FD,stroke:#2196F3,color:#1E88E5
    classDef state fill:#E8F5E9,stroke:#4CAF50,color:#388E3C
    classDef util fill:#E0F7FA,stroke:#00ACC1,color:#00838F
    classDef backend fill:#FFF3E0,stroke:#FB8C00,color:#EF6C00
    classDef middleware fill:#FFFDE7,stroke:#FDD835,color:#F9A825
    classDef routes fill:#FFEBEE,stroke:#E53935,color:#C62828
    classDef models fill:#F3E5F5,stroke:#8E24AA,color:#6A1B9A
    classDef database fill:#ECEFF1,stroke:#607D8B,color:#455A64
```
