This is a boilerplate project for building web applications using FastAPI framework with PostgreSQL as the database backend, all orchestrated with Docker environment.
- FastAPI: FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints.
- PostgreSQL: PostgreSQL is a powerful, open-source object-relational database system known for its reliability, robustness, and performance.
- Pydantic: Pydantic is used for data validation and settings management, enabling easy serialization and validation of data structures.
- SQLAlchemy: SQLAlchemy is a SQL toolkit and Object-Relational Mapping (ORM) library for Python, providing a full suite of well-known enterprise-level persistence patterns.
- Alembic: Alembic is a lightweight database migration tool for usage with SQLAlchemy, allowing for easy schema migrations.
- Docker Compose: Docker Compose is used for orchestrating the FastAPI application and PostgreSQL database within Docker containers.
Before getting started, ensure you have the following installed on your system:
- Docker
- Docker Compose
-
Clone this repository:
git clone [email protected]:nrjadkry/fastapi_boilerplate.git
-
Navigate into the project directory:
cd fastapi-postgres-boilerplate
-
Create a
.env
file in the project root using theenv_sample.txt
provided.cp env_sample.txt .env
-
Create a docker-compose file. Update it according to your choice
cp docker-compose.local.yml docker-compose.yml
-
Start the application and PostgreSQL database containers using Docker Compose:
docker-compose up -d
Once Docker containers are up and running, the FastAPI application will be available at http://localhost:8001
.
- app: Contains the main application code.
- api: API routers and endpoints.
- core: Core application modules and configurations.
- db: Database related code including SQLAlchemy models and database connection setup.
- schemas: Pydantic models for request/response payloads.
- alembic: Contains database migration scripts managed by Alembic.
- tests: Unit and integration tests.
- docker-compose.yml: Docker Compose configuration file for orchestrating the FastAPI application and PostgreSQL database.
Contributions are welcome! Please fork this repository and submit a pull request with your changes.