A full-stack Hospital Management System built with React + Vite, Node.js/Express, MongoDB, and JWT authentication. Supports three roles: Patient, Doctor, and Admin.
- Node.js v18+
- MongoDB (local or Atlas)
- npm
cd smartcare-hmscd backend
cp .env.example .envnpm install
npm run seed # Seed database with sample data
npm run dev # Start backend on port 5001cd ../frontend
npm install
npm run dev # Start frontend on port 5173smartcare-hms/
├── backend/
│ ├── server.js
│ ├── .env.example
│ ├── package.json
│ ├── models/
│ │ ├── User.js # Base model + Patient/Doctor/Admin discriminators
│ │ ├── Test.js
│ │ └── Appointment.js
│ ├── middleware/
│ │ └── auth.js # JWT verify + RBAC
│ ├── controllers/
│ │ ├── authController.js
│ │ ├── doctorController.js
│ │ ├── testController.js
│ │ ├── appointmentController.js
│ │ └── adminController.js
│ ├── routes/
│ │ ├── auth.js
│ │ ├── doctors.js
│ │ ├── tests.js
│ │ ├── appointments.js
│ │ ├── slots.js
│ │ ├── admin.js
│ │ └── contact.js
│ └── utils/
│ └── seed.js
│
└── frontend/
├── index.html
├── vite.config.js
├── tailwind.config.js
└── src/
├── main.jsx
├── App.jsx
├── index.css
├── utils/
│ └── api.js # Axios instance with JWT interceptor
├── context/
│ └── AuthContext.jsx # Auth state management
├── components/
│ ├── layout/
│ │ └── Navbar.jsx
│ └── common/
│ └── BookingModal.jsx
└── pages/
├── Home.jsx
├── Doctors.jsx
├── Tests.jsx
├── Contact.jsx
├── auth/
│ └── AuthPage.jsx
├── patient/
│ └── Dashboard.jsx
├── doctor/
│ └── Dashboard.jsx
└── admin/
└── Dashboard.jsx
- Slots: Every 15 minutes, 8:00 AM – 10:00 PM
- Working days: Saturday – Thursday (Friday is off)
- Double booking: Prevented — each slot handles one patient
- Daily limit: One booking per patient per doctor/test per day
- Patient: Book appointments, view/cancel their own appointments, manage profile
- Doctor: View & manage their appointments (confirm/reject/complete), update profile
- Admin: Full control over tests, test bookings, doctor management, stats
- Passwords hashed with bcrypt (salt rounds: 12)
- JWT tokens expire in 7 days
- Rate limiting: 100 requests per 15 minutes per IP
- CORS restricted to frontend origin
- Helmet.js security headers
- Set environment variables from
.env.example - Set
MONGODB_URIto your MongoDB Atlas URI - Set
CLIENT_URLto your deployed frontend URL - Deploy the
backend/folder
- Update
vite.config.jsproxy OR setVITE_API_URLenv variable - In
src/utils/api.js, changebaseURLto your backend URL for production - Deploy the
frontend/folder
- Create free cluster at mongodb.com/atlas
- Whitelist all IPs (
0.0.0.0/0) for cloud deployment - Copy connection string to
MONGODB_URI
| Problem | Solution |
|---|---|
MongoServerError: connect ECONNREFUSED |
Start MongoDB locally or use Atlas URI |
Invalid admin key |
Check ADMIN_KEY in .env matches what you enter in signup |
| CORS errors | Ensure CLIENT_URL in backend .env matches your frontend port |
| Slots not loading | Make sure you're passing date, type, and id as query params |
| 401 on dashboard | Token may have expired — log out and log in again |
MIT © Smartcare HMS