A comprehensive RESTful API for hospital management built with Node.js, Express.js, and MongoDB. This system provides complete functionality for appointment booking, patient management, and administrative features.
- Features
- Tech Stack
- Prerequisites
- Installation
- Project Structure
- API Endpoints
- Documentation
- Testing
- Deployment
- Contributing
- License
- Author
-
Authentication & Authorization
- JWT-based authentication
- Role-based access control (Admin, Doctor, Patient)
- Password reset functionality
- Secure cookie handling
-
Patient Management
- Patient registration and profiles
- Medical history tracking
- Appointment scheduling
-
Doctor Management
- Doctor profiles and specializations
- Availability management
- Appointment handling
-
Administrative Features
- User management
- System monitoring
- Data analytics
-
Security Features
- Rate limiting
- CORS protection
- Helmet security headers
- HPP protection
- Input validation and sanitization
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- File Upload: Multer with Sharp for image processing
- Email: Nodemailer for email notifications
- Validation: Express Validator
- Security: Helmet, CORS, HPP, Rate Limiting
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/3mr-5aled/hospital-api.git cd hospital-api -
Install dependencies
npm install
-
Environment Configuration
Copy the example environment file and configure it:
cp .env.example config.env
Edit
config.envwith your settings:NODE_ENV=development PORT=8000 # Database db_uri=mongodb://localhost:27017/hospital-db # Or use MongoDB Atlas # db_uri=mongodb+srv://username:password@cluster.mongodb.net/database # JWT JWT_SECRET_KEY=your-super-secret-jwt-key-min-32-chars JWT_EXPIRE_TIME=90d # Email Configuration (Gmail example) EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USER=your-email@gmail.com EMAIL_PASSWORD=your-app-specific-password # Other configurations BASE_URL=http://localhost:8000
β οΈ Security: Never commitconfig.envto version control. Use.env.exampleas a template. -
Start MongoDB
# If using local MongoDB mongod # Or use MongoDB Atlas (cloud database)
-
Start the application
Development mode:
npm run dev
Production mode:
npm run start:prod
hospital-api/
βββ src/
β βββ config/ # Database and app configuration
β βββ controllers/ # Route controllers
β βββ middlewares/ # Custom middleware functions
β βββ models/ # Mongoose models (User, Patient, Doctor, etc.)
β βββ routes/ # Express routes
β βββ services/ # Business logic services
β βββ utils/ # Utility functions (errors, helpers, email)
β βββ validators/ # Input validation schemas
βββ postman/ # Postman collections and test suites
βββ uploads/ # File upload directory
βββ server.js # Application entry point
βββ config.env # Environment variables (DO NOT COMMIT)
βββ .env.example # Environment template
βββ package.json # Project dependencies
βββ DATABASE_SCHEMA.md # Database schema documentation
βββ README.md # Project documentation
For detailed database schema information, see DATABASE_SCHEMA.md.
npm run dev- Start development server with nodemonnpm start- Start production servernpm run start:prod- Start production server with NODE_ENV=productionnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issues automaticallynpm run format- Format code with Prettiernpm run format:check- Check code formatting
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/v1/auth/signup |
Register new user | No |
| POST | /api/v1/auth/login |
Login user | No |
| POST | /api/v1/auth/forgotPassword |
Request password reset | No |
| PUT | /api/v1/auth/resetPassword/:token |
Reset password | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/v1/patients |
Get all patients | Admin/Doctor |
| GET | /api/v1/patients/:id |
Get patient by ID | Yes |
| POST | /api/v1/patients |
Create patient profile | Patient |
| PUT | /api/v1/patients/:id |
Update patient | Patient |
| DELETE | /api/v1/patients/:id |
Delete patient | Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/v1/doctors |
Get all doctors | No |
| GET | /api/v1/doctors/:id |
Get doctor by ID | No |
| POST | /api/v1/doctors |
Create doctor profile | Admin |
| PUT | /api/v1/doctors/:id |
Update doctor | Doctor/Admin |
| DELETE | /api/v1/doctors/:id |
Delete doctor | Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/v1/clinics |
Get all clinics | No |
| GET | /api/v1/clinics/:id |
Get clinic by ID | No |
| POST | /api/v1/clinics |
Create clinic | Admin |
| PUT | /api/v1/clinics/:id |
Update clinic | Admin |
| DELETE | /api/v1/clinics/:id |
Delete clinic | Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/v1/appointments |
Get appointments | Yes |
| GET | /api/v1/appointments/:id |
Get appointment by ID | Yes |
| POST | /api/v1/appointments |
Create appointment | Patient |
| PUT | /api/v1/appointments/:id |
Update appointment | Doctor/Patient |
| DELETE | /api/v1/appointments/:id |
Cancel appointment | Doctor/Patient/Admin |
π For detailed API documentation with request/response examples, see API_REFERENCE.md or import the Postman collection from the
postman/directory.
Comprehensive Postman collections are available in the postman/ directory:
- Hospital-Management-API.postman_collection.json - Full API endpoints
- Hospital-API-TestSuite.postman_collection.json - Automated test suite
cd postman
npm install
npm testThree pre-configured environments are available:
- Development
- Staging
- Production
Import them into Postman from the postman/ directory.
Core Documentation:
- API Reference - Complete endpoint documentation with examples
- Database Schema - Detailed database design and relationships
- Quick Start Guide - Get started in 5 minutes
- Deployment Guide - Deploy to Heroku, AWS, Vercel, DigitalOcean
Additional Resources:
- Contributing Guidelines - How to contribute to this project
- Security Policy - Security guidelines and vulnerability reporting
- Postman Documentation - API testing and automation
- Changelog - Version history and release notes
- LinkedIn Showcase - Tips for showcasing this project
For detailed deployment instructions to various platforms (Heroku, AWS, Vercel, DigitalOcean, Railway), see DEPLOYMENT.md.
Quick Deploy:
- Ensure environment variables are properly configured
- Set
NODE_ENV=production - Use a production-grade database (MongoDB Atlas recommended)
- Enable HTTPS/SSL
- Configure CORS for your domain
We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
Quick steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'feat(scope): add amazing feature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project uses:
- ESLint with Airbnb configuration
- Prettier for code formatting
- Conventional Commits for commit messages
- Node.js best practices
Run quality checks before committing:
npm run lint:fix # Fix ESLint issues
npm run format # Format with PrettierThis project is licensed under the ISC License - see the LICENSE file for details.
Amr Khaled Morcy
- GitHub: @3mr-5aled
- Email: 3mr5aled.contact@gmail.com
- Course Inspiration: This project was developed as part of the Node.js - Build a Full E-Commerce RESTful APIs course by Ahmed Boghdady, Mahmoud Bakr, and Index Academy on Udemy. The course provided excellent guidance on building production-ready RESTful APIs with Node.js, Express, and MongoDB.
- Express.js team for the excellent framework
- MongoDB team for the robust database
- Open Source Community for all the amazing packages and tools
- All contributors and maintainers of the libraries used in this project
For support and questions:
- Open an issue on GitHub
- Email: 3mr5aled.contact@gmail.com
- Check existing documentation and closed issues
β If you found this project helpful, please give it a star!
πΌ Portfolio Project: This API demonstrates full-stack backend development skills including RESTful API design, authentication, database management, and security best practices.
