HealthBed AI is an advanced, full-stack Hospital Management and Emergency Routing web application designed to reduce operational friction during medical crises.
Built with a Node.js/Express backend, PostgreSQL database, Python AI Microservice, and a Next.js with Tailwind CSS frontend, the platform leverages WebSockets (Socket.io) for low-latency live medical data broadcasting and Pessimistic Database Locking to securely prevent double-booking of critical beds.
- Dynamic Ward Management: Hospital Administrators can dynamically register and track specialized units (e.g., Maternity, Burn Unit, CCU, NICU, Trauma) using JSONB data storage in PostgreSQL.
- Microsecond Synchronization: When an administrator adjusts bed availability, Socket.io broadcasts the new capacity to every connected client, ensuring the public patient directory updates in real-time.
- Public Dispatch Initiation: Users can initiate an emergency dispatch signal (including Patient Name, Condition, and ETA) directly to a specified hospital.
- Active Alerting: The moment a dispatch is requested, an incoming alert is transmitted to the target Hospital Administrator's dashboard.
- Concurrency-Safe Reservations: Administrators can lock and reserve a bed for the incoming ambulance. The system utilizes PostgreSQL
FOR UPDATEpessimistic locking to ensure safe concurrency and prevent bed overbooking.
- Integrates with an internal Python microservice to compute optimal hospital routing based on live distance, location coordinates, and real-time bed capacity.
- Built with Framer Motion for optimized micro-animations and smooth transitions.
- Modern interface utilizing glassmorphism styling and custom theming for an intuitive administrative experience.
This repository is structured into three decoupled services. Refer to the specific module documentation for technical implementation details:
/frontendREADME: The Next.js reactive UI application./backendREADME: The RESTful API layer and WebSocket server (Uses PostgreSQL)./ai-serviceREADME: The Python FastAPI routing engine./database: Containsschema.sqlandseed-data.sqlfor automated local environment initialization.
Explore the technical implementation details of HealthBed AI:
- System Architecture & Data Flow — Architectural overview of the WebSocket event bus topology and real-time synchronization flows.
- System Design & Core Mechanisms — Detailed analysis of the Pessimistic Locking database strategy and dynamic JSONB capacity engine.
- API Documentation — Comprehensive reference for the RESTful endpoints.
- Ensure PostgreSQL is installed and running on port
5432. - Create a database named
hospital_bed_db. - Execute the initialization scripts from the
/databasedirectory:psql -U postgres -d hospital_bed_db -f database/schema.sql psql -U postgres -d hospital_bed_db -f database/seed-data.sql
- Navigate to the backend directory:
cd backend npm install - Create a
.envfile in thebackendfolder (reference.env.example). - Start the backend development server:
npm run dev
- Navigate to the frontend directory:
cd frontend npm install - Create a
.env.localfile in thefrontendfolder:NEXT_PUBLIC_API_URL=http://localhost:5000 - Start the Next.js development server:
npm run dev
Refer to ai-service/README.md for instructions on running the FastAPI routing engine via uvicorn.
Navigate to http://localhost:3000/auth/login to access the platform.
Note: For security reasons, default passwords are not included in this repository. If you are setting up the project locally for the first time, you must generate your own bcrypt hashes in
database/seed-data.sqlor create an account via the Signup interface.
