A modern, robust healthcare management API built with FastAPI β delivering secure, scalable, and efficient healthcare services with real-time notifications.
- Docker & Docker Compose
- Python 3.11+ (for local development)
# Clone and deploy in one command docker-compose up --build -dThe API will be available at: http://localhost:8000 API Documentation: http://localhost:8000/docs
. βββ app/ β βββ api/ β β βββ routes/ # API endpoint handlers β β β βββ auth.py β β β βββ appointment.py β β β βββ doctor.py β β β βββ patient.py β β βββ deps.py # Dependency injection β βββ core/ # Core application logic β β βββ config.py # Configuration management β β βββ security.py # Authentication & authorization β β βββ cache.py # Redis caching layer β β βββ rate_limiter.py # Request rate limiting β β βββ notifications.py # Notification utilities β βββ crud/ # Database operations layer β β βββ crud_base.py # Base CRUD operations β β βββ crud_user.py β β βββ crud_patient.py β β βββ crud_doctor.py β β βββ crud_appointment.py β βββ db/ # Database layer β β βββ models.py # SQLAlchemy models β β βββ session.py # Database session management β βββ schemas/ # Pydantic schemas β β βββ user.py β β βββ patient.py β β βββ doctor.py β β βββ appointment.py β β βββ medical_record.py β βββ tests/ # Test suites β βββ test_api.py β βββ test_crud.py β βββ test_security.py βββ docker-compose.yml # Multi-service orchestration βββ Dockerfile # Main application container βββ Dockerfile.notification # Notification worker container βββ notification_service.py # Async notification processor The system runs as a multi-container application:
| Service | Purpose | Port | Health Check |
|---|---|---|---|
| app | FastAPI Application | 8000 | HTTP 200 on /health |
| db | PostgreSQL Database | 5432 | pg_isready |
| redis | Redis Cache | 6379 | redis-cli ping |
| rabbitmq | Message Queue | 5672/15672 | Built-in |
# Production deployment docker-compose up --build -d # View logs docker-compose logs -f app # Stop services docker-compose down# Create virtual environment python -m venv .venv source .venv/bin/activate # Linux/Mac # OR .\.venv\Scripts\Activate.ps1 # Windows # Install dependencies pip install -r requirements.txt # Run the application uvicorn app.main:app --reload --host 127.0.0.1 --port 8000| Command | Description |
|---|---|
docker-compose up --build -d | Build and start all services |
docker-compose logs -f [service] | Follow service logs |
docker-compose down | Stop and remove containers |
docker-compose exec app [cmd] | Execute command in app container |
| Command | Description |
|---|---|
uvicorn app.main:app --reload | Start development server |
pytest -q | Run test suite quietly |
pytest -v | Run tests with verbose output |
pytest --cov=app | Run tests with coverage |
- π Secure Authentication β JWT-based auth with password hashing
- π₯ Role-Based Access Control β Patient, Doctor, and Admin roles
- π Appointment Management β Schedule, reschedule, and cancel appointments
- β‘ Real-time Notifications β Async notification system with RabbitMQ
- πΎ Intelligent Caching β Redis-powered response caching
- π Rate Limiting β Request throttling for API protection
- π Health Checks β Container and service health monitoring
- π Security Hardened β Password validation, SQL injection protection
fastapiβ Modern, fast web frameworkuvicornβ ASGI server implementationpydanticβ Data validation and settings management
sqlalchemyβ SQL toolkit and ORMasyncpgβ Async PostgreSQL driveralembicβ Database migrations
python-joseβ JWT implementationpasslibβ Password hashingbcryptβ Secure password hashing
redisβ Redis client for Pythonceleryβ Distributed task queuepikaβ RabbitMQ client
python-multipartβ Form data handlingemail-validatorβ Email validationpython-dotenvβ Environment variable management
# Database DATABASE_URL=postgresql://user:pass@db:5432/healthcare_db DB_PASSWORD=your_secure_password # Cache REDIS_URL=redis://redis:6379/0 # Message Queue RABBITMQ_URL=amqp://user:pass@rabbitmq:5672/ RABBITMQ_USER=admin RABBITMQ_PASSWORD=your_rabbitmq_password # Security SECRET_KEY=your_jwt_secret_keyapp/core/config.pyβ Centralized configuration managementdocker-compose.ymlβ Service orchestrationDockerfileβ Application container definitionDockerfile.notificationβ Worker container definition
- Set environment variables in
.envfile - Run
docker-compose up --build -d - Access API at
http://your-server:8000 - Monitor services with
docker-compose logs -f
- API:
GET /health - Database: Automatic health checks in compose
- Redis: Automatic health checks in compose
- Multi-stage Docker builds for optimized image sizes
- Non-root user execution for enhanced security
- Connection pooling for database efficiency
- Request rate limiting to prevent abuse
- JWT token expiration for session security
- Password strength validation with bcrypt hashing
# Run all tests pytest # Run with coverage pytest --cov=app --cov-report=html # Run specific test module pytest app/tests/test_api.py -v- Fork the repository
- Create your feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for more information.
Delivering secure, scalable healthcare APIs with cutting-edge technology.
http://localhost:8000/api/appointments
-H "Authorization: Bearer <token_jwt>"
-H "Content-Type: application/json"
-d '{ "patient_id": 1, "doctor_id": 2, "date": "2025-12-01T10:00:00", "reason": "Consulta preventiva" }'
url = "http://localhost:8000/api/appointments" headers = { "Authorization": "Bearer <token_jwt>", "Content-Type": "application/json" }
payload = { "patient_id": 1, "doctor_id": 2, "date": "2025-12-01T10:00:00", "reason": "Consulta preventiva" } response = requests.post(url, json=payload, headers=headers) print(response.status_code, response.json())