# kaushalkumar08/prescripto architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack web application (“Prescripto”) for booking doctor appointments, managing prescriptions, and handling payments.
- It provides three user interfaces:
– Public patient frontend
– Admin panel frontend
– Doctor-specific pages (within both frontends via routing and role-based access)
- It exposes a REST API server to support authentication, appointment and prescription CRUD, and payment processing.

##### File structure
Top-level directories:
- frontend/   ← Patient-facing React app
- admin/      ← Admin/Doctor React app
- backend/    ← Node.js/Express REST API
Key patterns and files:
- frontend/src and admin/src each follow a component/context/pages split → UI layer with React Router and Tailwind CSS
- backend/controllers, backend/models, backend/routes, backend/middleware → MVC-style organization
- backend/config → third-party service configuration (MongoDB, Cloudinary)
- .env files in frontend/admin for client keys; backend uses its own .env in server.js
- Deployment configs: Vite, ESLint, PostCSS, vercel.json (admin)

##### README for additional insights
- Tech stack is React + Tailwind + Vite on the frontends, Node/Express on the backend, MongoDB as the database.
- Dependencies: Stripe (payments), JWT (authentication), Axios (API calls), Toastify (notifications).
- Features: role-based login (patients, doctors, admins), prescription management, appointment scheduling, secure payments.

a. Main components
- Client side
– Patient Frontend (React)
– Admin/Doctor Frontend (React)
- API Layer
– Express.js server with route files for users, doctors, admins
– Middleware for JWT auth and file uploads (multer)
– Controllers for business logic (appointmentController, userController, etc.)
- Data Layer
– MongoDB database (collections: users, doctors, appointments)
- External services
– Stripe for payments
– Cloudinary for image/storage uploads
b. Relationships and interactions
- API to MongoDB showing read/write flows
- API to Stripe (payment processing) and to Cloudinary (media uploads)
- Authentication flow: login request → JWT issued → JWT passed in subsequent API calls → middleware validation
c. Architectural patterns & design principles
- Three-tier architecture: Presentation (React UIs), Application (Express API), Data (MongoDB)
- MVC within the backend (Models, Controllers, Routes)
- Context API in React for global state (AuthContext, AppContext, DoctorContext)
- Separation of concerns between admin and user features via distinct frontends
- RESTful routing and stateless JWT-based authentication
d. Key technologies/frameworks
- Frontends: React.js, Tailwind CSS, Vite, React Router, Context API
- Backend: Node.js, Express.js, Mongoose (ODM)
- Database: MongoDB
- External: Stripe SDK, Cloudinary SDK, Multer (file upload), JWT

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        PatientUI["Patient Frontend (React)"]:::frontend
        AdminUI["Admin/Doctor Frontend (React)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        API["Express API"]:::api

        subgraph "Routes"
            UserRoute["User Routes"]:::routes
            DoctorRoute["Doctor Routes"]:::routes
            AdminRoute["Admin Routes"]:::routes
        end

        subgraph "Controllers"
            UserController["User Controller"]:::controllers
            DoctorController["Doctor Controller"]:::controllers
            AdminController["Admin Controller"]:::controllers
        end

        subgraph "Middleware"
            AuthUser["Auth User Middleware"]:::middleware
            AuthDoctor["Auth Doctor Middleware"]:::middleware
            AuthAdmin["Auth Admin Middleware"]:::middleware
            Multer["Multer + Cloudinary Middleware"]:::middleware
        end
    end

    %% Data & Services Layer
    subgraph "Data & Services Layer"
        subgraph "Database"
            DB["MongoDB"]:::db
            subgraph "Models"
                UserModel["User Model"]:::model
                DoctorModel["Doctor Model"]:::model
                AppointmentModel["Appointment Model"]:::model
            end
        end
        subgraph "External Services"
            Stripe["Stripe (Payments)"]:::external
            Cloudinary["Cloudinary (Image Upload)"]:::external
        end
    end

    %% Presentation to API
    PatientUI -->|"REST API calls (Axios)"| API
    AdminUI -->|"REST API calls (Axios)"| API

    %% API internal flow
    API --> Routes
    UserRoute --> UserController
    DoctorRoute --> DoctorController
    AdminRoute --> AdminController
    UserController --> UserModel
    DoctorController --> DoctorModel
    AdminController --> AppointmentModel
    UserModel --> DB
    DoctorModel --> DB
    AppointmentModel --> DB

    %% Middleware integration
    UserRoute --> AuthUser
    DoctorRoute --> AuthDoctor
    AdminRoute --> AuthAdmin
    API --> Multer --> Cloudinary
    API --> Stripe --> API

    %% Click Events
    click PatientUI "https://github.com/kaushalkumar08/prescripto/tree/main/frontend/"
    click AdminUI "https://github.com/kaushalkumar08/prescripto/tree/main/admin/"
    click API "https://github.com/kaushalkumar08/prescripto/blob/main/backend/server.js"
    click UserRoute "https://github.com/kaushalkumar08/prescripto/blob/main/backend/routes/userRoute.js"
    click DoctorRoute "https://github.com/kaushalkumar08/prescripto/blob/main/backend/routes/doctorRoute.js"
    click AdminRoute "https://github.com/kaushalkumar08/prescripto/blob/main/backend/routes/adminRoute.js"
    click UserController "https://github.com/kaushalkumar08/prescripto/blob/main/backend/controllers/userController.js"
    click DoctorController "https://github.com/kaushalkumar08/prescripto/blob/main/backend/controllers/doctorController.js"
    click AdminController "https://github.com/kaushalkumar08/prescripto/blob/main/backend/controllers/adminController.js"
    click AuthUser "https://github.com/kaushalkumar08/prescripto/blob/main/backend/middleware/authUser.js"
    click AuthDoctor "https://github.com/kaushalkumar08/prescripto/blob/main/backend/middleware/authDoctor.js"
    click AuthAdmin "https://github.com/kaushalkumar08/prescripto/blob/main/backend/middleware/authAdmin.js"
    click Multer "https://github.com/kaushalkumar08/prescripto/blob/main/backend/middleware/multer.js"
    click UserModel "https://github.com/kaushalkumar08/prescripto/blob/main/backend/models/userModel.js"
    click DoctorModel "https://github.com/kaushalkumar08/prescripto/blob/main/backend/models/doctorModel.js"
    click AppointmentModel "https://github.com/kaushalkumar08/prescripto/blob/main/backend/models/appointmentModel.js"
    click DB "https://github.com/kaushalkumar08/prescripto/blob/main/backend/config/mongodb.js"
    click Cloudinary "https://github.com/kaushalkumar08/prescripto/blob/main/backend/config/cloudinary.js"
    click AppContext "https://github.com/kaushalkumar08/prescripto/blob/main/frontend/src/context/AppContext.jsx"
    click PagesPatient "https://github.com/kaushalkumar08/prescripto/tree/main/frontend/src/pages/"
    click AdminContext "https://github.com/kaushalkumar08/prescripto/blob/main/admin/src/context/AdminContext.jsx"
    click AdminAppContext "https://github.com/kaushalkumar08/prescripto/blob/main/admin/src/context/AppContext.jsx"
    click DoctorContext "https://github.com/kaushalkumar08/prescripto/blob/main/admin/src/context/DoctorContext.jsx"
    click AdminPages "https://github.com/kaushalkumar08/prescripto/tree/main/admin/src/pages/Admin/"
    click DoctorPages "https://github.com/kaushalkumar08/prescripto/tree/main/admin/src/pages/Doctor/"
    click LoginPage "https://github.com/kaushalkumar08/prescripto/blob/main/admin/src/pages/Login.jsx"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9
    classDef api fill:#E8F5E9,stroke:#A5D6A7
    classDef routes fill:#FFFDE7,stroke:#FFF59D
    classDef controllers fill:#E0F7FA,stroke:#4DD0E1
    classDef middleware fill:#FFF3E0,stroke:#FFCC80
    classDef model fill:#FCE4EC,stroke:#F48FB1
    classDef db fill:#ECEFF1,stroke:#B0BEC5
    classDef external fill:#F3E5F5,stroke:#CE93D8
```
