# satishgupta2/prescripto architecture

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

- Interactive diagram: https://gitdiagram.com/satishgupta2/prescripto
- Repository: https://github.com/satishgupta2/prescripto

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node) doctor-appointment booking system with three clients (public website, doctor portal, admin panel), a backend API server, a MongoDB database, and two external services (Cloudinary for image storage, Razorpay for payments).

##### File structure
- Top-level directories:
- frontend – React app for patients (booking UI, profile, payment)
- admin – React app for admins & doctors (dashboard, appointment management, doctor management)
- bankend – Express/Node server (APIs, controllers, models, middleware, config)
- Notice MVC-style arrangement in backend (models/, controllers/, routes/), plus config/ for MongoDB & Cloudinary and middleware/ for JWT authentication and file uploads.
- Both React apps use Vite, Tailwind CSS, Context API for state, and share a similar folder layout (components/, pages/, context/).

##### README for additional insights
- Three authentication levels: patient, doctor, admin
- Razorpay integration for payments
- CRUD operations on users, doctors, appointments via REST APIs
- Deployment targets: Render for backend, static hosting for React apps

a. Main components:
1. Patient-facing Frontend (React SPA)
2. Doctor/Admin Portal (React SPA)
3. Backend API Server (Node/Express)
4. Database (MongoDB Atlas)
5. Cloudinary (image upload & storage)
6. Razorpay Payment Gateway
b. Relationships & interactions:
- Both React apps communicate over HTTPS with the Backend API.
- The Backend uses Mongoose to read/write to MongoDB.
- File-upload endpoints route images through the Cloudinary SDK.
- Booking endpoint calls Razorpay SDK for payment orders.
- Authentication (JWTs) is applied via middleware on protected routes.
c. Architectural patterns & design principles:
- MVC separation in backend (models ↔ controllers ↔ routes)
- Context API in frontend for global state (user session, appointments)
- RESTful API design (adminRoute, doctorRoute, userRoute)
- Layered security: separate JWT guards for Admin, Doctor, User
d. Key technologies/frameworks:
- React + Vite + Tailwind CSS
- Context API for state management
- Express.js + Mongoose
- Cloudinary SDK
- Razorpay Node.js SDK
- JWT for auth

##### Essential elements
- Authentication layers: JWT guards for Users, Doctors, Admins
- Context stores in frontends (AppContext, AdminContext, DoctorsContext)
- Static hosting of SPAs (e.g., Vercel/Netlify) vs. Render hosting for API
- Contact point: API Base URL (e.g., https://api.prescripto.com)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        direction TB
        PFSPA["Patient Frontend SPA"]:::frontend
        PFSPA_PAGES["Pages"]:::frontend
        PFSPA_COMPS["Components"]:::frontend
        PFSPA_CTX["AppContext"]:::frontend
        PFSPA --> PFSPA_PAGES
        PFSPA --> PFSPA_COMPS
        PFSPA --> PFSPA_CTX
        click PFSPA "https://github.com/satishgupta2/prescripto/tree/main/frontend/"
        click PFSPA_PAGES "https://github.com/satishgupta2/prescripto/tree/main/frontend/src/pages/"
        click PFSPA_COMPS "https://github.com/satishgupta2/prescripto/tree/main/frontend/src/components/"
        click PFSPA_CTX "https://github.com/satishgupta2/prescripto/blob/main/frontend/src/context/AppContext.jsx"

        ADSPA["Doctor/Admin Portal SPA"]:::frontend
        ADSPA_PAGES["Pages"]:::frontend
        ADSPA_COMPS["Components"]:::frontend
        ADSPA_ADMIN_CTX["AdminContext"]:::frontend
        ADSPA_DOC_CTX["DoctorsContext"]:::frontend
        ADSPA_APP_CTX["Shared AppContext"]:::frontend
        ADSPA --> ADSPA_PAGES
        ADSPA --> ADSPA_COMPS
        ADSPA --> ADSPA_ADMIN_CTX
        ADSPA --> ADSPA_DOC_CTX
        ADSPA --> ADSPA_APP_CTX
        click ADSPA "https://github.com/satishgupta2/prescripto/tree/main/admin/"
        click ADSPA_PAGES "https://github.com/satishgupta2/prescripto/tree/main/admin/src/pages/"
        click ADSPA_COMPS "https://github.com/satishgupta2/prescripto/tree/main/admin/src/components/"
        click ADSPA_ADMIN_CTX "https://github.com/satishgupta2/prescripto/blob/main/admin/src/context/AdminContext.jsx"
        click ADSPA_DOC_CTX "https://github.com/satishgupta2/prescripto/blob/main/admin/src/context/DoctorsContext.jsx"
        click ADSPA_APP_CTX "https://github.com/satishgupta2/prescripto/blob/main/admin/src/context/AppContext.jsx"
    end

    %% Server Layer
    subgraph "Backend API Server" 
        direction TB
        API["API Entry Point<br/>(server.js)"]:::backend
        CONFIG["Config"]:::backend
        CONFIG_MONGO["MongoDB Config"]:::backend
        CONFIG_CLOUD["Cloudinary Config"]:::backend
        ROUTES["Routes"]:::backend
        R_USER["userRoute.js"]:::backend
        R_DOCTOR["doctorRoute.js"]:::backend
        R_ADMIN["adminRoute.js"]:::backend
        CONTROLLERS["Controllers"]:::backend
        C_USER["userController.js"]:::backend
        C_DOCTOR["doctorController.js"]:::backend
        C_ADMIN["adminController.js"]:::backend
        MODELS["Models"]:::backend
        M_USER["userModel.js"]:::backend
        M_DOCTOR["doctorModel.js"]:::backend
        M_APPT["appointmentModel.js"]:::backend
        MIDDLEWARE["Middleware"]:::backend
        MW_AUTH_USER["AuthUser.js"]:::backend
        MW_AUTH_DOCTOR["AuthDoctor.js"]:::backend
        MW_AUTH_ADMIN["AuthAdmin.js"]:::backend
        MW_MULTER["multer.js"]:::backend

        API --> CONFIG
        CONFIG --> CONFIG_MONGO
        CONFIG --> CONFIG_CLOUD
        API --> ROUTES
        ROUTES --> R_USER
        ROUTES --> R_DOCTOR
        ROUTES --> R_ADMIN
        API --> CONTROLLERS
        CONTROLLERS --> C_USER
        CONTROLLERS --> C_DOCTOR
        CONTROLLERS --> C_ADMIN
        API --> MODELS
        MODELS --> M_USER
        MODELS --> M_DOCTOR
        MODELS --> M_APPT
        API --> MIDDLEWARE
        MIDDLEWARE --> MW_AUTH_USER
        MIDDLEWARE --> MW_AUTH_DOCTOR
        MIDDLEWARE --> MW_AUTH_ADMIN
        MIDDLEWARE --> MW_MULTER

        click API "https://github.com/satishgupta2/prescripto/blob/main/bankend/server.js"
        click CONFIG_MONGO "https://github.com/satishgupta2/prescripto/blob/main/bankend/config/mongodb.js"
        click CONFIG_CLOUD "https://github.com/satishgupta2/prescripto/blob/main/bankend/config/cloudinary.js"
        click R_USER "https://github.com/satishgupta2/prescripto/blob/main/bankend/routes/userRoute.js"
        click R_DOCTOR "https://github.com/satishgupta2/prescripto/blob/main/bankend/routes/doctorRoute.js"
        click R_ADMIN "https://github.com/satishgupta2/prescripto/blob/main/bankend/routes/adminRoute.js"
        click C_USER "https://github.com/satishgupta2/prescripto/blob/main/bankend/controllers/usercontroller.js"
        click C_DOCTOR "https://github.com/satishgupta2/prescripto/blob/main/bankend/controllers/doctorController.js"
        click C_ADMIN "https://github.com/satishgupta2/prescripto/blob/main/bankend/controllers/adminController.js"
        click M_USER "https://github.com/satishgupta2/prescripto/blob/main/bankend/models/userModel.js"
        click M_DOCTOR "https://github.com/satishgupta2/prescripto/blob/main/bankend/models/doctorModel.js"
        click M_APPT "https://github.com/satishgupta2/prescripto/blob/main/bankend/models/appointmentModel.js"
        click MW_AUTH_USER "https://github.com/satishgupta2/prescripto/blob/main/bankend/middlewares/AuthUser.js"
        click MW_AUTH_DOCTOR "https://github.com/satishgupta2/prescripto/blob/main/bankend/middlewares/AuthDoctor.js"
        click MW_AUTH_ADMIN "https://github.com/satishgupta2/prescripto/blob/main/bankend/middlewares/AuthAdmin.js"
        click MW_MULTER "https://github.com/satishgupta2/prescripto/blob/main/bankend/middlewares/multer.js"
    end

    %% Third-party Services
    subgraph "Third-Party Services"
        direction TB
        DB["MongoDB Atlas"]:::db
        CLOUDINARY["Cloudinary"]:::service
        RAZORPAY["Razorpay"]:::service
    end

    %% Data Flows
    PFSPA -->|HTTPS GET/POST| API
    ADSPA -->|HTTPS GET/POST| API
    API -->|Mongoose Queries| DB
    API -->|Upload Images| CLOUDINARY
    API -->|Create Payment Order| RAZORPAY
    RAZORPAY -->|Payment Confirmation| API

    classDef frontend fill:#D0E8FF,stroke:#2B7CE9,color:#0B3D91;
    classDef backend fill:#E0F8E0,stroke:#28A745,color:#196F3D;
    classDef db fill:#FFE5CC,stroke:#FF8C00,color:#A65B00;
    classDef service fill:#F3E8FF,stroke:#9B59B6,color:#5D3FD3;
```
