# shashwattt26/reyansh-diagnostics architecture

> Architecture diagram of the GitHub repository shashwattt26/reyansh-diagnostics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shashwattt26/reyansh-diagnostics
- Repository: https://github.com/shashwattt26/reyansh-diagnostics

## Overview

1. **Top-level shape**
   - This repo is a two-tier application: a **Node/Express backend** in `backend/` and a **React/Vite frontend SPA** in `frontend/frontend/`.
   - The backend is the system of record and API gateway; the frontend is a browser client for patients and staff.

2. **Primary business boundary**
   - The core domain is a diagnostic center workflow: **public booking intake**, **staff authentication**, **live booking management**, **lab report delivery**, and **admin-only staff/privacy actions**.
   - The architecture is organized around those workflows rather than generic CRUD resources.

3. **Frontend subsystem**
   - The frontend is a **single-page React app** with route-level pages such as `LandingPage`, `AdminDashboard`, `AdminLogin`, `StaffManagement`, `VerifyEmail`, and `ResetPassword`.
   - Reusable landing-page sections live under `src/components/landing/`, while app-wide layout and utilities live under `src/components/layout/` and `src/components/`.
   - Routing is handled client-side, with SPA deployment support via `vercel.json`.

4. **Public vs. authenticated UI**
   - Public users mainly interact with the **landing/marketing flow** and the booking entry points.
   - Authenticated staff users enter through the **admin/staff portal**, which consumes live booking data and exposes report-processing and account-management screens.
   - This separation is important for diagramming because the same backend serves both public and restricted flows, but the UI paths are distinct.

5. **Backend API boundary**
   - The backend is an **Express server** in `backend/server.js` with route modules split by concern: `authRoutes`, `bookingRoutes`, `adminRoutes`, `reportRoutes`, `searchRoutes`, and `staffRoutes`.
   - `config/db.js` connects to PostgreSQL via a pool, and `config/cloudinary.js` centralizes blob-storage integration.
   - `utils/logger.js` and `utils/sendEmail.js` support cross-cutting concerns rather than domain logic.

6. **Authentication and session model**
   - Authentication is **JWT-based with HTTP-only cookies**, not frontend token storage.
   - `authRoutes` covers staff registration, login, and email verification; password reset is handled as a separate flow.
   - `middleware/authMiddleware.js` and `middleware/roleCheck.js` form the main trust boundary for protected endpoints.

7. **Booking intake and prescription upload flow**
   - Public booking requests hit the booking API, usually as **multipart form submissions**.
   - `middleware/upload.js` handles temporary file reception; the uploaded prescription is then forwarded to **Cloudinary**, and the local file is cleaned up after upload.
   - The booking record, including the Cloudinary URL and a generated **tracking code**, is stored in PostgreSQL.

8. **Report processing flow**
   - Final lab reports are uploaded through the report routes and follow the same storage pattern: **temporary local file → Cloudinary → database update**.
   - Report upload changes booking state to indicate that the report is ready, which is then reflected in staff/admin screens.
   - This is a separate domain path from patient booking because it is restricted to internal staff roles.

9. **Real-time update path**
   - The backend is also a **Socket.IO server**, used to push booking changes to connected clients without polling.
   - The key event is new booking creation: once the booking is persisted, the server emits an event and the admin dashboard prepends the new record in memory.
   - For architecture diagrams, this is the main asynchronous data flow between backend and staff UI.

10. **Security and access control**
   - Security is layered through middleware: `rateLimiter.js` for abuse prevention, `validator.js` for request validation, `roleCheck.js` for authorization, and `authMiddleware.js` for session protection.
   - `backend` also uses `helmet`, bcrypt, and cookie-based auth; the readme indicates role-based access for admin-only operations such as staff management and data anonymization.
   - The booking tracking code is a privacy boundary: it supports lookup without exposing internal identifiers directly.

11. **External services and persistence**
   - **PostgreSQL** stores users, bookings, roles, and report metadata.
   - **Cloudinary** stores prescription and PDF report files; the local filesystem is only a temporary staging area.
   - **Resend** sends verification and password-reset emails.
   - These are the three key external integrations that materially shape the architecture.

12. **Testing and delivery**
   - The backend includes route-level tests under `backend/__tests__`, and the frontend includes component tests such as `BookingCard.test.jsx`.
   - CI is defined in `.github/workflows/ci.yml`, and Dependabot is configured for dependency maintenance.
   - Deployment is split by tier: frontend to Vercel-like static hosting, backend to a Node service with PostgreSQL and external service credentials.

13. **Important diagram boundaries**
   - Draw the **browser/SPA** boundary separately from the **Express API/socket server** boundary.
   - Inside the backend, show separate lanes for **auth**, **booking intake**, **admin/staff operations**, and **report uploads**.
   - Show the shared infrastructure layer beneath them: **PostgreSQL**, **Cloudinary**, and **Resend**, with Socket.IO as the real-time channel between backend and admin UI.

Main entry points: [`backend/server.js`](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/server.js) (Express Server), [`backend/config/db.js`](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/config/db.js) (PostgreSQL), [`backend/routes/authRoutes.js`](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/authRoutes.js) (Auth Routes), [`backend/routes/bookingRoutes.js`](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/bookingRoutes.js) (Booking Intake)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_spa["React App<br/>Vite SPA<br/>[App.jsx]"]
  node_landing["Landing Flow<br/>public UI<br/>[LandingPage.jsx]"]
  node_adminui["Admin Portal<br/>staff UI<br/>[AdminDashboard.jsx]"]
  node_authui["Auth Screens<br/>account UI<br/>[AdminLogin.jsx]"]
  node_supportui["Info Pages<br/>content UI<br/>[AboutPage.jsx]"]
  node_landingcomp["Landing Components<br/>ui components<br/>[BookingCard.jsx]"]
  node_layout["Layout Utils<br/>shared UI<br/>[MainLayout.jsx]"]
end

subgraph group_backend["Backend API"]
  node_server["Express Server<br/>api + socket server<br/>[server.js]"]
  node_auth["Auth Routes<br/>JWT auth<br/>[authRoutes.js]"]
  node_booking["Booking Intake<br/>public booking API<br/>[bookingRoutes.js]"]
  node_admin["Admin Ops<br/>staff API<br/>[adminRoutes.js]"]
  node_reports["Report Uploads<br/>report API<br/>[reportRoutes.js]"]
  node_search["Search API<br/>lookup API<br/>[searchRoutes.js]"]
  node_staff["Staff API<br/>staff data API<br/>[staffRoutes.js]"]
  node_middleware["Security Middleware<br/>trust boundary<br/>[authMiddleware.js]"]
end

subgraph group_infra["Shared Infra"]
  node_db[("PostgreSQL<br/>relational store<br/>[db.js]")]
  node_cloudinary[("Cloudinary<br/>blob storage<br/>[cloudinary.js]")]
  node_resend["Resend<br/>email service<br/>[sendEmail.js]"]
end

node_spa -->|"routes to"| node_landing
node_spa -->|"routes to"| node_adminui
node_spa -->|"routes to"| node_authui
node_spa -->|"routes to"| node_supportui
node_landing -->|"submit booking"| node_booking
node_adminui -->|"API + socket"| node_server
node_authui -->|"auth actions"| node_auth
node_server -->|"mounts"| node_auth
node_server -->|"mounts"| node_booking
node_server -->|"mounts"| node_admin
node_server -->|"mounts"| node_reports
node_server -->|"mounts"| node_search
node_server -->|"mounts"| node_staff
node_auth -->|"protected by"| node_middleware
node_booking -->|"protected by"| node_middleware
node_admin -->|"protected by"| node_middleware
node_reports -->|"protected by"| node_middleware
node_auth -->|"reads/writes"| node_db
node_booking -->|"writes booking"| node_db
node_admin -->|"reads/writes"| node_db
node_reports -->|"updates reports"| node_db
node_search -->|"queries"| node_db
node_staff -->|"queries"| node_db
node_booking -->|"uploads"| node_cloudinary
node_reports -->|"uploads"| node_cloudinary
node_auth -->|"emails"| node_resend
node_server -.->|"push updates"| node_adminui

click node_spa "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/App.jsx"
click node_landing "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/LandingPage.jsx"
click node_adminui "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AdminDashboard.jsx"
click node_authui "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AdminLogin.jsx"
click node_supportui "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AboutPage.jsx"
click node_landingcomp "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/components/landing/BookingCard.jsx"
click node_layout "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/components/layout/MainLayout.jsx"
click node_server "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/server.js"
click node_auth "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/authRoutes.js"
click node_booking "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/bookingRoutes.js"
click node_admin "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/adminRoutes.js"
click node_reports "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/reportRoutes.js"
click node_search "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/searchRoutes.js"
click node_staff "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/staffRoutes.js"
click node_middleware "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/middleware/authMiddleware.js"
click node_db "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/config/db.js"
click node_cloudinary "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/config/cloudinary.js"
click node_resend "https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/utils/sendEmail.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_landing,node_adminui,node_authui,node_supportui,node_landingcomp,node_layout toneBlue
class node_server,node_auth,node_booking,node_admin,node_reports,node_search,node_staff,node_middleware toneAmber
class node_db,node_cloudinary,node_resend toneMint
```

## Components

### Frontend SPA

React/Vite browser client for public users and staff

- [React App](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/App.jsx): Vite SPA · Client-side application shell and routing · `frontend/frontend/src/App.jsx`
- [Landing Flow](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/LandingPage.jsx): public UI · Public marketing and booking entry experience · `frontend/frontend/src/pages/LandingPage.jsx`
- [Admin Portal](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AdminDashboard.jsx): staff UI · Authenticated dashboard for live bookings and operations · `frontend/frontend/src/pages/AdminDashboard.jsx`
- [Auth Screens](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AdminLogin.jsx): account UI · Staff login, verification, and password reset pages · `frontend/frontend/src/pages/AdminLogin.jsx`
- [Info Pages](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/pages/AboutPage.jsx): content UI · About, services, and legal pages · `frontend/frontend/src/pages/AboutPage.jsx`
- [Landing Components](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/components/landing/BookingCard.jsx): ui components · Reusable hero, sections, navigation, and booking card pieces · `frontend/frontend/src/components/landing/BookingCard.jsx`
- [Layout Utils](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/frontend/frontend/src/components/layout/MainLayout.jsx): shared UI · App-wide layout, SEO, and scroll helpers · `frontend/frontend/src/components/layout/MainLayout.jsx`

### Backend API

Express + Socket.IO server for booking, auth, and reports

- [Express Server](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/server.js): api + socket server · HTTP entrypoint and realtime event hub · `backend/server.js`
- [Auth Routes](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/authRoutes.js): JWT auth · Staff registration, login, verification, and reset flows · `backend/routes/authRoutes.js`
- [Booking Intake](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/bookingRoutes.js): public booking API · Public booking creation and tracking code generation · `backend/routes/bookingRoutes.js`
- [Admin Ops](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/adminRoutes.js): staff API · Staff management, anonymization, and admin-only actions · `backend/routes/adminRoutes.js`
- [Report Uploads](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/reportRoutes.js): report API · Lab report ingestion and booking state updates · `backend/routes/reportRoutes.js`
- [Search API](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/searchRoutes.js): lookup API · Tracking and search endpoints for bookings and records · `backend/routes/searchRoutes.js`
- [Staff API](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/routes/staffRoutes.js): staff data API · Staff-facing operational endpoints · `backend/routes/staffRoutes.js`
- [Security Middleware](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/middleware/authMiddleware.js): trust boundary · Auth, roles, validation, rate limiting, and upload handling · `backend/middleware/authMiddleware.js`

### Shared Infra

Persistence and external integrations

- [PostgreSQL](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/config/db.js): relational store · System of record for users, bookings, roles, and reports · `backend/config/db.js`
- [Cloudinary](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/config/cloudinary.js): blob storage · Stores prescription files and final report PDFs · `backend/config/cloudinary.js`
- [Resend](https://github.com/shashwattt26/reyansh-diagnostics/blob/main/backend/utils/sendEmail.js): email service · Sends verification and password reset emails · `backend/utils/sendEmail.js`

## Connections

- React App → Landing Flow: routes to · Client-side routing serves public landing experience
- React App → Admin Portal: routes to · Client-side routing serves authenticated staff dashboard
- React App → Auth Screens: routes to · Client-side routing serves login and recovery pages
- React App → Info Pages: routes to · Client-side routing serves informational pages
- Landing Flow → Booking Intake: submit booking · Public users create bookings from the landing flow
- Admin Portal → Express Server: API + socket · Staff dashboard consumes live API data and realtime events
- Auth Screens → Auth Routes: auth actions · Login, verification, and password reset requests
- Express Server → Auth Routes: mounts · Express server exposes auth routes
- Express Server → Booking Intake: mounts · Express server exposes booking intake routes
- Express Server → Admin Ops: mounts · Express server exposes admin routes
- Express Server → Report Uploads: mounts · Express server exposes report upload routes
- Express Server → Search API: mounts · Express server exposes lookup routes
- Express Server → Staff API: mounts · Express server exposes staff routes
- Auth Routes → Security Middleware: protected by · JWT cookies, role checks, validation, and rate limiting
- Booking Intake → Security Middleware: protected by · Multipart upload and request validation
- Admin Ops → Security Middleware: protected by · Authorization and input validation for admin-only operations
- Report Uploads → Security Middleware: protected by · Authorization plus upload handling for report ingestion
- Auth Routes → PostgreSQL: reads/writes · Stores staff accounts and verification state
- Booking Intake → PostgreSQL: writes booking · Persists bookings, tracking codes, and file URLs
- Admin Ops → PostgreSQL: reads/writes · Manages staff and privacy-sensitive records
- Report Uploads → PostgreSQL: updates reports · Marks reports ready and updates booking state
- Search API → PostgreSQL: queries · Looks up booking status and tracking information
- Staff API → PostgreSQL: queries · Fetches staff-facing operational data
- Booking Intake → Cloudinary: uploads · Stores prescription uploads after temporary local staging
- Report Uploads → Cloudinary: uploads · Stores report PDFs after temporary local staging
- Auth Routes → Resend: emails · Sends verification and password reset messages
- Express Server → Admin Portal: push updates · Socket.IO emits new booking events to the dashboard
