|
1 | | -# Health Care Management System — Python / FastAPI |
| 1 | +# Health Care Management System — FastAPI Backend |
2 | 2 |
|
3 | | -This repository implements a Health Care Management System API using FastAPI. It includes services for appointments, doctors, patients, users, and a notification worker. |
| 3 | +A modern, robust healthcare management API built with FastAPI — delivering secure, scalable, and efficient healthcare services with real-time notifications. |
4 | 4 |
|
5 | | -Maintainers |
6 | | -- Repository owner: turabbb |
7 | | -- Primary contributor (this branch): umarm |
| 5 | +## 🚀 Quick Start with Docker |
8 | 6 |
|
9 | | -Quickstart (local) |
| 7 | +### Prerequisites |
| 8 | +- **Docker** & **Docker Compose** |
| 9 | +- **Python 3.11+** (for local development) |
10 | 10 |
|
11 | | -1. Create a virtual environment and activate it: |
| 11 | +### Production Deployment |
| 12 | +```bash |
| 13 | +# Clone and deploy in one command |
| 14 | +docker-compose up --build -d |
| 15 | +``` |
| 16 | + |
| 17 | +The API will be available at: [http://localhost:8000](http://localhost:8000) |
| 18 | +API Documentation: [http://localhost:8000/docs](http://localhost:8000/docs) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 🏗️ Tech Stack |
| 23 | + |
| 24 | +### Backend & API |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +### Database & Caching |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +### Infrastructure & DevOps |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## 📁 Project Structure |
12 | 43 |
|
13 | | -```powershell |
14 | | -python -m venv .venv |
15 | | -.\.venv\Scripts\Activate.ps1 |
| 44 | +``` |
| 45 | +. |
| 46 | +├── app/ |
| 47 | +│ ├── api/ |
| 48 | +│ │ ├── routes/ # API endpoint handlers |
| 49 | +│ │ │ ├── auth.py |
| 50 | +│ │ │ ├── appointment.py |
| 51 | +│ │ │ ├── doctor.py |
| 52 | +│ │ │ └── patient.py |
| 53 | +│ │ └── deps.py # Dependency injection |
| 54 | +│ ├── core/ # Core application logic |
| 55 | +│ │ ├── config.py # Configuration management |
| 56 | +│ │ ├── security.py # Authentication & authorization |
| 57 | +│ │ ├── cache.py # Redis caching layer |
| 58 | +│ │ ├── rate_limiter.py # Request rate limiting |
| 59 | +│ │ └── notifications.py # Notification utilities |
| 60 | +│ ├── crud/ # Database operations layer |
| 61 | +│ │ ├── crud_base.py # Base CRUD operations |
| 62 | +│ │ ├── crud_user.py |
| 63 | +│ │ ├── crud_patient.py |
| 64 | +│ │ ├── crud_doctor.py |
| 65 | +│ │ └── crud_appointment.py |
| 66 | +│ ├── db/ # Database layer |
| 67 | +│ │ ├── models.py # SQLAlchemy models |
| 68 | +│ │ └── session.py # Database session management |
| 69 | +│ ├── schemas/ # Pydantic schemas |
| 70 | +│ │ ├── user.py |
| 71 | +│ │ ├── patient.py |
| 72 | +│ │ ├── doctor.py |
| 73 | +│ │ ├── appointment.py |
| 74 | +│ │ └── medical_record.py |
| 75 | +│ └── tests/ # Test suites |
| 76 | +│ ├── test_api.py |
| 77 | +│ ├── test_crud.py |
| 78 | +│ └── test_security.py |
| 79 | +├── docker-compose.yml # Multi-service orchestration |
| 80 | +├── Dockerfile # Main application container |
| 81 | +├── Dockerfile.notification # Notification worker container |
| 82 | +└── notification_service.py # Async notification processor |
16 | 83 | ``` |
17 | 84 |
|
18 | | -2. Install dependencies: |
| 85 | +--- |
19 | 86 |
|
20 | | -```powershell |
21 | | -pip install -r requirements.txt |
| 87 | +## 🐳 Docker Services |
| 88 | + |
| 89 | +The system runs as a multi-container application: |
| 90 | + |
| 91 | +| Service | Purpose | Port | Health Check | |
| 92 | +|---------|---------|------|--------------| |
| 93 | +| **app** | FastAPI Application | 8000 | HTTP 200 on /health | |
| 94 | +| **db** | PostgreSQL Database | 5432 | `pg_isready` | |
| 95 | +| **redis** | Redis Cache | 6379 | `redis-cli ping` | |
| 96 | +| **rabbitmq** | Message Queue | 5672/15672 | Built-in | |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## 🛠️ Getting Started |
| 101 | + |
| 102 | +### Option 1: Docker (Recommended) |
| 103 | +```bash |
| 104 | +# Production deployment |
| 105 | +docker-compose up --build -d |
| 106 | + |
| 107 | +# View logs |
| 108 | +docker-compose logs -f app |
| 109 | + |
| 110 | +# Stop services |
| 111 | +docker-compose down |
22 | 112 | ``` |
23 | 113 |
|
24 | | -3. Run the API locally: |
| 114 | +### Option 2: Local Development |
| 115 | +```bash |
| 116 | +# Create virtual environment |
| 117 | +python -m venv .venv |
| 118 | +source .venv/bin/activate # Linux/Mac |
| 119 | +# OR |
| 120 | +.\.venv\Scripts\Activate.ps1 # Windows |
| 121 | + |
| 122 | +# Install dependencies |
| 123 | +pip install -r requirements.txt |
25 | 124 |
|
26 | | -```powershell |
| 125 | +# Run the application |
27 | 126 | uvicorn app.main:app --reload --host 127.0.0.1 --port 8000 |
28 | 127 | ``` |
29 | 128 |
|
30 | | -4. Run tests: |
| 129 | +--- |
| 130 | + |
| 131 | +## 📜 Available Commands |
| 132 | + |
| 133 | +### Docker Commands |
| 134 | +| Command | Description | |
| 135 | +|---------|-------------| |
| 136 | +| `docker-compose up --build -d` | Build and start all services | |
| 137 | +| `docker-compose logs -f [service]` | Follow service logs | |
| 138 | +| `docker-compose down` | Stop and remove containers | |
| 139 | +| `docker-compose exec app [cmd]` | Execute command in app container | |
| 140 | + |
| 141 | +### Development Commands |
| 142 | +| Command | Description | |
| 143 | +|---------|-------------| |
| 144 | +| `uvicorn app.main:app --reload` | Start development server | |
| 145 | +| `pytest -q` | Run test suite quietly | |
| 146 | +| `pytest -v` | Run tests with verbose output | |
| 147 | +| `pytest --cov=app` | Run tests with coverage | |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## 🎯 Core Features |
| 152 | + |
| 153 | +- **🔐 Secure Authentication** – JWT-based auth with password hashing |
| 154 | +- **👥 Role-Based Access Control** – Patient, Doctor, and Admin roles |
| 155 | +- **📅 Appointment Management** – Schedule, reschedule, and cancel appointments |
| 156 | +- **⚡ Real-time Notifications** – Async notification system with RabbitMQ |
| 157 | +- **💾 Intelligent Caching** – Redis-powered response caching |
| 158 | +- **🚀 Rate Limiting** – Request throttling for API protection |
| 159 | +- **📊 Health Checks** – Container and service health monitoring |
| 160 | +- **🔒 Security Hardened** – Password validation, SQL injection protection |
| 161 | + |
| 162 | +--- |
31 | 163 |
|
32 | | -```powershell |
33 | | -pip install pytest |
34 | | -pytest -q |
| 164 | +## 📦 Key Dependencies |
| 165 | + |
| 166 | +### Core Framework |
| 167 | +- `fastapi` – Modern, fast web framework |
| 168 | +- `uvicorn` – ASGI server implementation |
| 169 | +- `pydantic` – Data validation and settings management |
| 170 | + |
| 171 | +### Database & ORM |
| 172 | +- `sqlalchemy` – SQL toolkit and ORM |
| 173 | +- `asyncpg` – Async PostgreSQL driver |
| 174 | +- `alembic` – Database migrations |
| 175 | + |
| 176 | +### Security & Auth |
| 177 | +- `python-jose` – JWT implementation |
| 178 | +- `passlib` – Password hashing |
| 179 | +- `bcrypt` – Secure password hashing |
| 180 | + |
| 181 | +### Cache & Messaging |
| 182 | +- `redis` – Redis client for Python |
| 183 | +- `celery` – Distributed task queue |
| 184 | +- `pika` – RabbitMQ client |
| 185 | + |
| 186 | +### Utilities |
| 187 | +- `python-multipart` – Form data handling |
| 188 | +- `email-validator` – Email validation |
| 189 | +- `python-dotenv` – Environment variable management |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +## ⚙️ Configuration |
| 194 | + |
| 195 | +### Environment Variables |
| 196 | +```bash |
| 197 | +# Database |
| 198 | +DATABASE_URL=postgresql://user:pass@db:5432/healthcare_db |
| 199 | +DB_PASSWORD=your_secure_password |
| 200 | + |
| 201 | +# Cache |
| 202 | +REDIS_URL=redis://redis:6379/0 |
| 203 | + |
| 204 | +# Message Queue |
| 205 | +RABBITMQ_URL=amqp://user:pass@rabbitmq:5672/ |
| 206 | +RABBITMQ_USER=admin |
| 207 | +RABBITMQ_PASSWORD=your_rabbitmq_password |
| 208 | + |
| 209 | +# Security |
| 210 | +SECRET_KEY=your_jwt_secret_key |
35 | 211 | ``` |
36 | 212 |
|
37 | | -Docker / Compose |
| 213 | +### Configuration Files |
| 214 | +- `app/core/config.py` – Centralized configuration management |
| 215 | +- `docker-compose.yml` – Service orchestration |
| 216 | +- `Dockerfile` – Application container definition |
| 217 | +- `Dockerfile.notification` – Worker container definition |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## 🚀 Deployment |
| 222 | + |
| 223 | +### Production with Docker Compose |
| 224 | +1. Set environment variables in `.env` file |
| 225 | +2. Run `docker-compose up --build -d` |
| 226 | +3. Access API at `http://your-server:8000` |
| 227 | +4. Monitor services with `docker-compose logs -f` |
| 228 | + |
| 229 | +### Health Checks |
| 230 | +- API: `GET /health` |
| 231 | +- Database: Automatic health checks in compose |
| 232 | +- Redis: Automatic health checks in compose |
38 | 233 |
|
39 | | -This project includes a `Dockerfile` and `docker-compose.yml`. To run with Docker Compose: |
| 234 | +--- |
40 | 235 |
|
41 | | -```powershell |
42 | | -docker-compose up --build |
| 236 | +## ⚡ Performance & Security |
| 237 | + |
| 238 | +- **Multi-stage Docker builds** for optimized image sizes |
| 239 | +- **Non-root user execution** for enhanced security |
| 240 | +- **Connection pooling** for database efficiency |
| 241 | +- **Request rate limiting** to prevent abuse |
| 242 | +- **JWT token expiration** for session security |
| 243 | +- **Password strength validation** with bcrypt hashing |
| 244 | + |
| 245 | +--- |
| 246 | + |
| 247 | +## 🧪 Testing |
| 248 | + |
| 249 | +```bash |
| 250 | +# Run all tests |
| 251 | +pytest |
| 252 | + |
| 253 | +# Run with coverage |
| 254 | +pytest --cov=app --cov-report=html |
| 255 | + |
| 256 | +# Run specific test module |
| 257 | +pytest app/tests/test_api.py -v |
43 | 258 | ``` |
44 | 259 |
|
45 | | -Repository layout (key files) |
46 | | -- `app/` — FastAPI application and routes |
47 | | -- `core/` — configuration, security helpers, notifications |
48 | | -- `crud/` — CRUD layer for DB models |
49 | | -- `db/` — SQLAlchemy models and session |
50 | | -- `schemas/` — Pydantic schemas |
51 | | -- `tests/` — pytest tests (basic smoke tests on this branch) |
52 | | - |
53 | | -Notes |
54 | | -- This branch `feat/testing-docs` adds baseline tests and documentation. |
55 | | -- For issues or contributions, open a pull request against `main` and assign to `turabbb`. |
| 260 | +--- |
| 261 | + |
| 262 | +## 🤝 Contributing |
| 263 | + |
| 264 | +1. Fork the repository |
| 265 | +2. Create your feature branch |
| 266 | + ```bash |
| 267 | + git checkout -b feature/amazing-feature |
| 268 | + ``` |
| 269 | +3. Commit your changes |
| 270 | + ```bash |
| 271 | + git commit -m 'Add amazing feature' |
| 272 | + ``` |
| 273 | +4. Push to the branch |
| 274 | + ```bash |
| 275 | + git push origin feature/amazing-feature |
| 276 | + ``` |
| 277 | +5. Open a Pull Request |
| 278 | + |
| 279 | +--- |
| 280 | + |
| 281 | +## 📄 License |
| 282 | + |
| 283 | +This project is licensed under the **MIT License**. |
| 284 | +See the `LICENSE` file for more information. |
| 285 | + |
| 286 | +--- |
| 287 | + |
| 288 | +### 🏥 Built with ❤️ for Modern Healthcare Management |
| 289 | + |
| 290 | +Delivering secure, scalable healthcare APIs with cutting-edge technology. |
0 commit comments