Skip to content

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.

Notifications You must be signed in to change notification settings

ilyesHamdiii/Healthcare-API--fastapi

Repository files navigation

Healthcare API (FastAPI)

Description

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.

Tech Stack

  • 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

Motivation

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.


Why Build This Project?

  • 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.

How to Experience the API

  1. Clone the repository:

    git clone ilyesHamdiii/Healthcare-API--fastapi
    cd Health care api
  2. Create and activate a virtual environment (if not using Docker):

    python -m venv myvenv
    myvenv\Scripts\activate
  3. Install dependencies (if not using Docker):

    pip install -r requirements.txt
  4. Set up environment variables:

    • Copy .env.example to .env and fill in your database credentials and SECRET_KEY.
  5. 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.
  6. Initialize the database:

    • (If using Alembic or similar, run migrations. Otherwise, tables are auto-created on startup.)
  7. Start the API server (manual, if not using Docker):

    uvicorn app.main:app --reload
  8. Explore the interactive docs:

    • ⚠️ Note: The create user role 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.

Live Demo

Try the deployed app here:
https://healthcare-api-fastapi.onrender.com/docs

Project Structure

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

Folder Summaries

  • 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.

Contributing

Feel free to open issues or submit pull requests for improvements or new features!


License

MIT License (or specify your license

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published