A modern FastAPI backend for healthcare management, supporting users, appointments, articles, and notifications.
Features JWT authentication, Docker containerization, and Nginx reverse proxy for efficient request handling and enhanced security.
The application follows best practices for scalable API development and is designed to be easily extendable and maintainable.
- Backend Framework: FastAPI
- Database: PostgreSQL (via SQLAlchemy ORM)
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: passlib (bcrypt)
- Environment Management: python-dotenv
- Testing: pytest (recommended)
- API Documentation: OpenAPI/Swagger (auto-generated by FastAPI)
- Containerization: Docker
- Reverse Proxy: Nginx
Healthcare systems need secure, scalable, and maintainable APIs for managing users, appointments, articles, and notifications.
This project demonstrates how to build a modern healthcare backend using FastAPI, focusing on clean architecture, role-based access control, and extensibility.
- Real-World Impact: Healthcare platforms require robust, secure, and flexible APIs to support patient-doctor interactions, appointment scheduling, and information sharing.
- Learning Modern Backend: FastAPI is a cutting-edge Python framework that enables rapid development, automatic documentation, and strong security practices.
- Unified User Management: By treating doctors, patients, and admins as users with roles, the system is easier to maintain and extend.
- Showcase Best Practices: Demonstrates authentication, authorization, and clean separation of concerns for scalable API development.
-
Clone the repository:
git clone ilyesHamdiii/Healthcare-API--fastapi cd Health care api -
Create and activate a virtual environment (if not using Docker):
python -m venv myvenv myvenv\Scripts\activate
-
Install dependencies (if not using Docker):
pip install -r requirements.txt
-
Set up environment variables:
- Copy
.env.exampleto.envand fill in your database credentials andSECRET_KEY.
- Copy
-
Run with Docker and Nginx (recommended):
- Make sure Docker is installed.
- Build and start the containers:
docker-compose up --build
- Nginx will act as a reverse proxy to the FastAPI app.
-
Initialize the database:
- (If using Alembic or similar, run migrations. Otherwise, tables are auto-created on startup.)
-
Start the API server (manual, if not using Docker):
uvicorn app.main:app --reload
-
Explore the interactive docs:
⚠️ Note: Thecreate userrole is left open only for demonstration purposes. In a production environment, this endpoint should be restricted to admins.- Visit http://localhost:8000/docs for Swagger UI and try out endpoints directly.
Try the deployed app here:
https://healthcare-api-fastapi.onrender.com/docs
Health care api/
│
├── app/
│ ├── api/
│ │ └── routes/
│ │ ├── auth.py # Authentication endpoints (login, current user)
│ │ ├── user.py # User management (create, list doctors)
│ │ ├── appointment.py # Appointment booking and management
│ │ ├── article.py # Health articles CRUD
│ │ ├── notifications.py # Notification endpoints
│ │ └── doctors.py # (Legacy, now handled via user.py)
│ ├── core/
│ │ ├── oauth.py # JWT token creation and validation
│ │ ├── roles.py # Role-based access control dependencies
│ │ └── utility.py # Password hashing and verification
│ ├── db/
│ │ ├── base.py # Database session and engine setup
│ ├── models/
│ │ ├── models.py # SQLAlchemy ORM models (User, Appointment, Article, Notification)
│ │ └── schemas.py # Pydantic schemas for request/response validation
│ └── main.py # FastAPI app instance and router registration
│
├── requirements.txt # Python dependencies
├── .env.example # Example environment variables
├── README.md # Project documentation
- app/api/routes/: All API endpoints grouped by resource (auth, user, appointment, etc.).
- app/core/: Core logic for authentication, authorization, and utilities.
- app/db/: Database connection and session management.
- app/models/: Database models and Pydantic schemas for validation.
- app/main.py: FastAPI app setup and router inclusion.
Feel free to open issues or submit pull requests for improvements or new features!
MIT License (or specify your license