# abhinav-phi/medicalq architecture

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

- Interactive diagram: https://gitdiagram.com/abhinav-phi/medicalq
- Repository: https://github.com/abhinav-phi/medicalq

## Overview

##### Main Components
- Frontend: React 18+ + TypeScript, built with Vite, styled with Tailwind CSS.
- Pages/Features: Authentication (login/register), Home (Hero, Features, Stats), Dashboard (UserDashboard), Doctors (SpecialistDoctors, DoctorPopup), Community (CommunityPlatform, CommunityAds).
- Connects to backend via RESTful APIs.
- Backend: Node.js 20+ + Express.js.
- Modules:
– authController (register, login, profile)
– appointmentController (book, list)
– doctorController (list, filter, profiles)
– communityController (posts CRUD)
– messageController (conversations, send)
- Middleware: JWT+Firebase Auth validation, role-based (patient/doctor/admin), error handling, rate limiting.
- Uses Firebase Admin SDK to read/write Firestore.
- Database: Firebase Firestore.
- Collections: users, doctorProfiles, patientProfiles, credentials, messages, communityPosts, appointments.
- Authentication: Firebase Auth + JWT.
- Frontend obtains Firebase ID token → sends to backend.
- Backend verifies Firebase token, issues its own JWT or proxies Firebase claims.
- Role-based access control enforced in middleware.
- Deployment Platforms:
- Frontend → Vercel (automatic builds on git push).
- Backend → Heroku or Railway or DigitalOcean App Platform.

##### Relationships & Data Flows
- Frontend → Backend:
- Requests include JWT in Authorization header.
- Backend → Firestore:
- Frontend → Firebase Auth:
- Deployment Flows:

##### Architectural Patterns & Design Principles
- Three-Tier Architecture:
- Presentation Tier (SPA)
- Application Tier (RESTful API server)
- Data Tier (NoSQL document DB)
- Separation of Concerns:
- UI components vs. business logic vs. data access
- Stateless API:
- JWT-based sessions; horizontal scalability
- Context Providers (AuthContext, ThemeContext) for global state

##### Technologies & Layers
- Frontend:
- React + TS, Vite, Tailwind CSS, React Context API, Axios/fetch
- Backend:
- Express.js, Firebase Admin SDK, JSON-Web-Token, Winston logger
- Database:
- Firestore (document model)
- Auth:
- Firebase Auth (email/password, Google sign-in)
- JWT for Backend session management
- DevOps:
- CI/CD: GitHub Actions → Vercel & Heroku
- Environment Variables (.env)

##### Final Checklist
- [ ] All components labeled: Frontend, Backend, Firestore, Firebase Auth, Vercel, Heroku/Railway.
- User → Frontend (UI)
- Frontend → Firebase Auth (login/signup)
- Frontend → Backend (API)
- Backend → Firestore
- CI/CD → Vercel & Heroku/Railway
- [ ] Notes on role-based access (Patient, Doctor, Admin).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    User["User<br/>(Patient/Doctor/Admin)"]:::user

    %% Frontend Layer
    subgraph "Frontend (Vite + React + Tailwind)" 
        direction TB
        AuthPages["Auth Pages"]:::frontend
        HomePages["Home Pages"]:::frontend
        Dashboard["Dashboard"]:::frontend
        Doctors["Doctors"]:::frontend
        Community["Community"]:::frontend
        Layout["Layout<br/>(Header/Footer)"]:::frontend
        GlobalState["Global State<br/>(AuthContext, ThemeContext)"]:::frontend
        Configs["Configs<br/>(API, Firebase SDK)"]:::frontend
        Entry["Entry & Build Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Node.js + Express)" 
        direction TB
        AuthRoutes["authRoutes.js"]:::backend
        Controllers["Controllers"]:::backend
        Middlewares["Middlewares"]:::backend
        Config["Firebase Config"]:::backend
        Models["Models"]:::backend
        Utils["Logger (Winston)"]:::backend
        Bootstrap["app.js / server.js"]:::backend
    end

    %% Auth & Database
    FirebaseAuth["Firebase Auth"]:::auth
    FirestoreDB["Firestore<br/>(NoSQL Document DB)"]:::db

    %% Deployment
    GitHub["GitHub"]:::deploy
    Vercel["Vercel<br/>(Frontend)"]:::deploy
    Heroku["Heroku/Railway/DigitalOcean<br/>(Backend)"]:::deploy

    %% Connections
    User -->|"Interacts with"| AuthPages
    User -->|"Interacts with"| HomePages
    User -->|"Interacts with"| Dashboard
    User -->|"Interacts with"| Doctors
    User -->|"Interacts with"| Community

    AuthPages -->|"REST API (HTTPS, JWT)"| AuthRoutes
    HomePages -->|"REST API (HTTPS, JWT)"| Controllers
    Dashboard -->|"REST API (HTTPS, JWT)"| Controllers
    Doctors -->|"REST API (HTTPS, JWT)"| Controllers
    Community -->|"REST API (HTTPS, JWT)"| Controllers

    AuthPages -.->|"Firebase Auth SDK"| FirebaseAuth
    HomePages -.->|"Firebase Auth SDK"| FirebaseAuth

    Controllers -->|"Uses"| Middlewares
    Controllers -->|"Uses"| Config
    Controllers -->|"Uses"| Models
    Controllers -->|"Logs to"| Utils
    Middlewares -->|"Verifies Token"| FirebaseAuth
    Controllers -->|"Reads/Writes"| FirestoreDB

    GitHub -->|"CI/CD"| Vercel
    GitHub -->|"CI/CD"| Heroku
    Vercel -->|"Deploys"| AuthPages
    Vercel -->|"Deploys"| HomePages
    Vercel -->|"Deploys"| Dashboard
    Vercel -->|"Deploys"| Doctors
    Vercel -->|"Deploys"| Community
    Heroku -->|"Deploys"| AuthRoutes
    Heroku -->|"Deploys"| Controllers
    Heroku -->|"Deploys"| Middlewares
    Heroku -->|"Deploys"| Config
    Heroku -->|"Deploys"| Models
    Heroku -->|"Deploys"| Utils
    Heroku -->|"Deploys"| Bootstrap

    %% Click Events - Frontend
    click AuthPages "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/auth/AuthModal.tsx"
    click HomePages "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/home/Hero.tsx"
    click HomePages "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/home/Features.tsx"
    click HomePages "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/home/Stats.tsx"
    click Dashboard "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/dashboard/UserDashboard.tsx"
    click Doctors "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/doctors/SpecialistDoctors.tsx"
    click Doctors "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/doctors/DoctorPopup.tsx"
    click Community "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/community/CommunityPlatform.tsx"
    click Community "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/community/CommunityAds.tsx"
    click Layout "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/layout/Header.tsx"
    click Layout "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/components/layout/Footer.tsx"
    click GlobalState "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/contexts/AuthContext.tsx"
    click GlobalState "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/contexts/ThemeContext.tsx"
    click Configs "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/configs/api.ts"
    click Configs "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/configs/firebase.ts"
    click Entry "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/main.tsx"
    click Entry "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/src/App.tsx"
    click Entry "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/vite.config.ts"
    click Entry "https://github.com/abhinav-phi/medicalq/blob/main/Frontend/tailwind.config.js"

    %% Click Events - Backend
    click AuthRoutes "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Routes/authRoutes.js"
    click Controllers "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Controllers/authController.js"
    click Middlewares "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Middlewares/Auth.js"
    click Middlewares "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Middlewares/adminMiddleware.js"
    click Middlewares "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Middlewares/Error.js"
    click Config "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Config/Firebase.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/User.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/Credential.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/DoctorProfile.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/PatientProfile.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/Message.js"
    click Models "https://github.com/abhinav-phi/medicalq/blob/main/Backend/Models/Newsletter.js"
    click Utils "https://github.com/abhinav-phi/medicalq/blob/main/Backend/utils/logger.js"
    click Bootstrap "https://github.com/abhinav-phi/medicalq/blob/main/Backend/app.js"
    click Bootstrap "https://github.com/abhinav-phi/medicalq/blob/main/Backend/server.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0066CC,color:#000
    classDef backend fill:#DFF2D8,stroke:#228B22,color:#000
    classDef db fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef auth fill:#FFF4C1,stroke:#DAA520,color:#000
    classDef deploy fill:#E8E8E8,stroke:#808080,color:#000
    classDef user fill:#F0F0F0,stroke:#A9A9A9,color:#000,stroke-dasharray: 5 5
```
