How prabushankar15/vital_drop works
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: page.tsx Public and role journeys · send-otp/route.ts Next auth API · blood-requests/route.ts Blood request API · notifications/route.ts Notification API
Components 20
Next.js app
Primary App Router UI and colocated API routes.
- App Router UI
src/app/layout.tsx - Public and role journeys · Login, onboarding, emergency submission, and role dashboards.
src/app/page.tsx - Session shell
src/components/Providers.tsx - Next auth API · OTP login, verification, role selection, session, and logout.
src/app/api/auth/send-otp/route.ts - Blood request API · Creates, retrieves, updates, and manages hospital-owned requests.
src/app/api/blood-requests/route.ts - Notification API
src/app/api/notifications/route.ts - Dashboard UI · Donor, hospital, and public dashboard composition.
src/components/dashboard/DashboardLayout.tsx - Notification delivery UI
src/components/dashboard/NotificationBell.tsx - Next domain models · Users, OTPs, requests, donor responses/stats, blood banks, and notifications.
src/models/User.ts - Next Mongo connector
src/lib/mongodb.ts - Next Twilio adapter
src/lib/twilio.ts
Standalone backend
Parallel Node API and domain-service runtime.
- Standalone Node API · Independently runnable parallel API surface.
server/server.js - Backend auth boundary · Authentication, role enforcement, validation, rate limits, and error handling.
server/routes/authRoutes.js - Matching and request services · Matches donors and handles request workflows.
server/services/donorMatchingService.js - Realtime notifications · Socket-oriented notification integration boundary.
server/services/socketService.js - Backend domain models · Users, donations, requests, and notifications.
server/models/Donation.js - Backend database config
server/config/database.js - Backend SMS service
server/utils/smsService.js
Infrastructure
- MongoDB · Shared apparent persistence technology; separate runtime connectors are present.
- Twilio / SMS
Connections 27
- 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.