# prabushankar15/vital_drop architecture

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

- Interactive diagram: https://gitdiagram.com/prabushankar15/vital_drop
- Repository: https://github.com/prabushankar15/vital_drop

## Overview

#### 1. System purpose and topology
This is a blood-donation coordination application: public users raise emergency requests, donors view/respond to requests, and hospitals manage requests, candidate donors, feedback, and statuses. It contains two overlapping server implementations: a Next.js frontend/BFF API under `src/app`, plus a standalone Node backend under `server/server.js`. The active deployment topology must clarify which API surface is authoritative.

#### 2. Next.js application entry points
The primary UI is an App Router application rooted at `src/app/layout.tsx` and `src/app/page.tsx`. Major user journeys enter through `src/app/login/page.tsx`, `src/app/onboarding/page.tsx`, and `src/app/emergency-request/page.tsx`, then route into role-specific dashboards:
- Donor: `src/app/dashboard/donor/page.tsx`
- Hospital: `src/app/dashboard/hospital/page.tsx`
- Public: `src/app/dashboard/public/page.tsx`

Shared client composition and session-facing UI are concentrated in `src/components/Providers.tsx`, `src/components/dashboard/DashboardLayout.tsx`, and `src/components/ui/SessionExpiry.tsx`.

#### 3. Authentication and role lifecycle
Next API routes implement OTP login, profile creation, role selection, session checking, and logout at `src/app/api/auth/send-otp/route.ts`, `src/app/api/auth/verify-otp/route.ts`, and `src/app/api/auth/select-role/route.ts`. User persistence is modeled by `src/models/User.ts` and `src/models/OTP.ts`; supporting authentication and SMS abstractions are in `src/lib/auth.ts` and `src/lib/twilio.ts`.

The standalone backend provides the parallel auth boundary through `server/routes/authRoutes.js`, `server/controllers/authController.js`, and `server/middleware/auth.js`, with role enforcement in `server/middleware/roleGuard.js`.

#### 4. Blood-request workflow
Request creation and retrieval flow through `src/app/api/blood-requests/route.ts`; request detail/update operations are at `src/app/api/blood-requests/[id]/route.ts`. The core data entity is `src/models/BloodRequest.ts`. Public-facing request submission/rendering is represented by `src/components/public/BloodRequestForm.tsx` and `src/components/public/RequestStatusCard.tsx`.

Hospital ownership introduces a separate request-management boundary: `src/app/api/hospital/requests/route.ts`, `src/app/api/hospital/requests/[id]/status/route.ts`, and `src/app/api/hospital/requests/[id]/donors/route.ts`.

#### 5. Matching, donations, and hospital operations
The standalone service layer appears to contain the domain orchestration for matching and request handling: `server/services/donorMatchingService.js`, `server/services/requestService.js`, and `server/controllers/donorController.js`. Its persistence model includes `server/models/Donation.js`, `server/models/BloodRequest.js`, and `server/models/User.js`.

On the Next side, donor response/statistics models are `src/models/DonorResponse.ts` and `src/models/DonorStats.ts`; donor experience is composed in `src/components/donor/DonorDashboardContent.tsx`. Hospital dashboard and feedback flows are represented by `src/components/hospital/HospitalDashboardContent.tsx`, `src/app/api/hospital/feedback/route.ts`, and `src/models/BloodBank.ts`.

#### 6. Notifications and real-time boundary
Notifications have a first-class API and data model in `src/app/api/notifications/route.ts`, `src/app/api/notifications/[id]/route.ts`, and `src/models/Notification.ts`. UI delivery is handled by `src/components/dashboard/NotificationBell.tsx` and `src/components/ui/NotificationSystem.tsx`.

The standalone backend additionally has notification and socket-oriented services at `server/services/notificationService.js`, `server/services/socketService.js`, and `server/models/Notification.js`. This is the likely real-time integration boundary and should be reconciled with the Next notification API.

#### 7. Infrastructure, persistence, and external services
MongoDB is the apparent persistence layer, connected through `src/lib/mongodb.ts` and modeled with TypeScript entities under `src/models`; the backend has a separate database configuration at `server/config/database.js`. Twilio/SMS integration is exposed by `src/lib/twilio.ts` and `server/utils/smsService.js`, likely for OTP and notifications.

Standalone API protections include `server/middleware/rateLimiter.js`, `server/middleware/validation.js`, and `server/middleware/errorHandler.js`. Environment configuration exists separately for Next (`.env.local`) and backend (`server/.env`), reinforcing that these are independently runnable runtimes.

Main entry points: [`src/app/page.tsx`](https://github.com/prabushankar15/vital_drop/blob/master/src/app/page.tsx) (Public and role journeys), [`src/app/api/auth/send-otp/route.ts`](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/auth/send-otp/route.ts) (Next auth API), [`src/app/api/blood-requests/route.ts`](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/blood-requests/route.ts) (Blood request API), [`src/app/api/notifications/route.ts`](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/notifications/route.ts) (Notification API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_next["Next.js app"]
  node_ui["App Router UI<br/>Next.js frontend<br/>[layout.tsx]"]
  node_entry["Public and role journeys<br/>pages<br/>[page.tsx]"]
  node_session_ui["Session shell<br/>client composition<br/>[Providers.tsx]"]
  node_auth_api["Next auth API<br/>route handlers<br/>[route.ts]"]
  node_request_api["Blood request API<br/>route handlers<br/>[route.ts]"]
  node_notification_api["Notification API<br/>route handlers<br/>[route.ts]"]
  node_dashboard_ui["Dashboard UI<br/>role UI"]
  node_notification_ui["Notification delivery UI<br/>client UI"]
  node_next_models["Next domain models<br/>Mongoose models<br/>[User.ts]"]
  node_next_db["Next Mongo connector<br/>database adapter<br/>[mongodb.ts]"]
  node_next_sms["Next Twilio adapter<br/>SMS adapter<br/>[twilio.ts]"]
end

subgraph group_backend["Standalone backend"]
  node_node_api["Standalone Node API<br/>Express runtime<br/>[server.js]"]
  node_backend_auth["Backend auth boundary<br/>routes and middleware<br/>[authRoutes.js]"]
  node_domain_services["Matching and request services<br/>domain orchestration"]
  node_realtime["Realtime notifications<br/>socket services<br/>[socketService.js]"]
  node_backend_models["Backend domain models<br/>Mongoose models<br/>[Donation.js]"]
  node_backend_db["Backend database config<br/>database adapter<br/>[database.js]"]
  node_backend_sms["Backend SMS service<br/>SMS adapter<br/>[smsService.js]"]
end

subgraph group_external["Infrastructure"]
  node_mongo[("MongoDB<br/>database")]
  node_twilio{{"Twilio / SMS<br/>external service"}}
end

node_ui -->|"renders"| node_entry
node_ui -->|"wraps with"| node_session_ui
node_entry -->|"authenticates through"| node_auth_api
node_entry -->|"submits and views requests"| node_request_api
node_entry -->|"routes into"| node_dashboard_ui
node_session_ui -->|"maintains session"| node_auth_api
node_dashboard_ui -->|"manages requests"| node_request_api
node_dashboard_ui -->|"reads notifications"| node_notification_api
node_notification_ui -->|"delivers"| node_notification_api
node_auth_api -->|"uses"| node_next_models
node_request_api -->|"uses"| node_next_models
node_notification_api -->|"uses"| node_next_models
node_next_models -->|"connects via"| node_next_db
node_next_db -->|"connects to"| node_mongo
node_auth_api -->|"sends OTP"| node_next_sms
node_next_sms -->|"calls"| node_twilio
node_node_api -->|"protects with"| node_backend_auth
node_node_api -->|"delegates to"| node_domain_services
node_node_api -->|"hosts"| node_realtime
node_domain_services -->|"uses"| node_backend_models
node_realtime -->|"persists notifications"| node_backend_models
node_backend_models -->|"connects via"| node_backend_db
node_backend_db -->|"connects to"| node_mongo
node_backend_auth -->|"sends OTP"| node_backend_sms
node_backend_sms -->|"calls"| node_twilio
node_notification_api -.->|"overlapping notification boundary"| node_realtime
node_request_api -.->|"overlapping request boundary"| node_domain_services

click node_ui "https://github.com/prabushankar15/vital_drop/blob/master/src/app/layout.tsx"
click node_entry "https://github.com/prabushankar15/vital_drop/blob/master/src/app/page.tsx"
click node_session_ui "https://github.com/prabushankar15/vital_drop/blob/master/src/components/Providers.tsx"
click node_auth_api "https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/auth/send-otp/route.ts"
click node_request_api "https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/blood-requests/route.ts"
click node_notification_api "https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/notifications/route.ts"
click node_dashboard_ui "https://github.com/prabushankar15/vital_drop/blob/master/src/components/dashboard/DashboardLayout.tsx"
click node_notification_ui "https://github.com/prabushankar15/vital_drop/blob/master/src/components/dashboard/NotificationBell.tsx"
click node_next_models "https://github.com/prabushankar15/vital_drop/blob/master/src/models/User.ts"
click node_next_db "https://github.com/prabushankar15/vital_drop/blob/master/src/lib/mongodb.ts"
click node_next_sms "https://github.com/prabushankar15/vital_drop/blob/master/src/lib/twilio.ts"
click node_node_api "https://github.com/prabushankar15/vital_drop/blob/master/server/server.js"
click node_backend_auth "https://github.com/prabushankar15/vital_drop/blob/master/server/routes/authRoutes.js"
click node_domain_services "https://github.com/prabushankar15/vital_drop/blob/master/server/services/donorMatchingService.js"
click node_realtime "https://github.com/prabushankar15/vital_drop/blob/master/server/services/socketService.js"
click node_backend_models "https://github.com/prabushankar15/vital_drop/blob/master/server/models/Donation.js"
click node_backend_db "https://github.com/prabushankar15/vital_drop/blob/master/server/config/database.js"
click node_backend_sms "https://github.com/prabushankar15/vital_drop/blob/master/server/utils/smsService.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_ui,node_entry,node_session_ui,node_auth_api,node_request_api,node_notification_api,node_dashboard_ui,node_notification_ui,node_next_models,node_next_db,node_next_sms toneBlue
class node_node_api,node_backend_auth,node_domain_services,node_realtime,node_backend_models,node_backend_db,node_backend_sms toneAmber
class node_mongo,node_twilio toneMint
```

## Components

### Next.js app

Primary App Router UI and colocated API routes.

- [App Router UI](https://github.com/prabushankar15/vital_drop/blob/master/src/app/layout.tsx): Next.js frontend · `src/app/layout.tsx`
- [Public and role journeys](https://github.com/prabushankar15/vital_drop/blob/master/src/app/page.tsx): pages · Login, onboarding, emergency submission, and role dashboards. · `src/app/page.tsx`
- [Session shell](https://github.com/prabushankar15/vital_drop/blob/master/src/components/Providers.tsx): client composition · `src/components/Providers.tsx`
- [Next auth API](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/auth/send-otp/route.ts): route handlers · OTP login, verification, role selection, session, and logout. · `src/app/api/auth/send-otp/route.ts`
- [Blood request API](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/blood-requests/route.ts): route handlers · Creates, retrieves, updates, and manages hospital-owned requests. · `src/app/api/blood-requests/route.ts`
- [Notification API](https://github.com/prabushankar15/vital_drop/blob/master/src/app/api/notifications/route.ts): route handlers · `src/app/api/notifications/route.ts`
- [Dashboard UI](https://github.com/prabushankar15/vital_drop/blob/master/src/components/dashboard/DashboardLayout.tsx): role UI · Donor, hospital, and public dashboard composition. · `src/components/dashboard/DashboardLayout.tsx`
- [Notification delivery UI](https://github.com/prabushankar15/vital_drop/blob/master/src/components/dashboard/NotificationBell.tsx): client UI · `src/components/dashboard/NotificationBell.tsx`
- [Next domain models](https://github.com/prabushankar15/vital_drop/blob/master/src/models/User.ts): Mongoose models · Users, OTPs, requests, donor responses/stats, blood banks, and notifications. · `src/models/User.ts`
- [Next Mongo connector](https://github.com/prabushankar15/vital_drop/blob/master/src/lib/mongodb.ts): database adapter · `src/lib/mongodb.ts`
- [Next Twilio adapter](https://github.com/prabushankar15/vital_drop/blob/master/src/lib/twilio.ts): SMS adapter · `src/lib/twilio.ts`

### Standalone backend

Parallel Node API and domain-service runtime.

- [Standalone Node API](https://github.com/prabushankar15/vital_drop/blob/master/server/server.js): Express runtime · Independently runnable parallel API surface. · `server/server.js`
- [Backend auth boundary](https://github.com/prabushankar15/vital_drop/blob/master/server/routes/authRoutes.js): routes and middleware · Authentication, role enforcement, validation, rate limits, and error handling. · `server/routes/authRoutes.js`
- [Matching and request services](https://github.com/prabushankar15/vital_drop/blob/master/server/services/donorMatchingService.js): domain orchestration · Matches donors and handles request workflows. · `server/services/donorMatchingService.js`
- [Realtime notifications](https://github.com/prabushankar15/vital_drop/blob/master/server/services/socketService.js): socket services · Socket-oriented notification integration boundary. · `server/services/socketService.js`
- [Backend domain models](https://github.com/prabushankar15/vital_drop/blob/master/server/models/Donation.js): Mongoose models · Users, donations, requests, and notifications. · `server/models/Donation.js`
- [Backend database config](https://github.com/prabushankar15/vital_drop/blob/master/server/config/database.js): database adapter · `server/config/database.js`
- [Backend SMS service](https://github.com/prabushankar15/vital_drop/blob/master/server/utils/smsService.js): SMS adapter · `server/utils/smsService.js`

### Infrastructure

- **MongoDB**: database · Shared apparent persistence technology; separate runtime connectors are present.
- **Twilio / SMS**: external service

## Connections

- App Router UI → Public and role journeys: renders
- App Router UI → Session shell: wraps with
- Public and role journeys → Next auth API: authenticates through
- Public and role journeys → Blood request API: submits and views requests
- Public and role journeys → Dashboard UI: routes into
- Session shell → Next auth API: maintains session
- Dashboard UI → Blood request API: manages requests
- Dashboard UI → Notification API: reads notifications
- Notification delivery UI → Notification API: delivers
- Next auth API → Next domain models: uses
- Blood request API → Next domain models: uses
- Notification API → Next domain models: uses
- Next domain models → Next Mongo connector: connects via
- Next Mongo connector → MongoDB: connects to
- Next auth API → Next Twilio adapter: sends OTP
- Next Twilio adapter → Twilio / SMS: calls
- Standalone Node API → Backend auth boundary: protects with
- Standalone Node API → Matching and request services: delegates to
- Standalone Node API → Realtime notifications: hosts
- Matching and request services → Backend domain models: uses
- Realtime notifications → Backend domain models: persists notifications
- Backend domain models → Backend database config: connects via
- Backend database config → MongoDB: connects to
- Backend auth boundary → Backend SMS service: sends OTP
- Backend SMS service → Twilio / SMS: calls
- Notification API → Realtime notifications: overlapping notification boundary · Authority between the Next API and standalone realtime service is unresolved.
- Blood request API → Matching and request services: overlapping request boundary · Both runtimes implement request-related behavior.
