forked from ami-wtag/fastapi-demoapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b04454
commit 5b738a1
Showing
1 changed file
with
65 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,114 @@ | ||
# FastAPI Template: Scalable Backend with PostgreSQL, Alembic, Docker, Pytest, and Async CRUD | ||
# FastAPI Backend Starter Kit | ||
|
||
This repository serves as a professional template for building robust, scalable backend applications using FastAPI. It incorporates a modern tech stack designed to simplify development, ensure maintainability, and enhance testing capabilities. Here's a quick overview of the technologies used and their purpose: | ||
A professional, scalable, and production-ready template for backend applications built with FastAPI. This repository is designed to simplify development, ensure maintainability, and provide robust testing capabilities, making it an ideal starting point for your next project. | ||
|
||
## Key Features and Technologies | ||
- **FastAPI**: A high-performance web framework for building APIs with Python, leveraging modern asynchronous features for speed and scalability. | ||
- **PostgreSQL**: A powerful relational database system, providing robust data storage with support for complex queries and transactions. | ||
- **Alembic**: A lightweight database migration tool, integrated to manage schema migrations efficiently and maintain version control. | ||
- **Docker**: A containerization platform that ensures consistent application behavior across environments, streamlining development and deployment. | ||
- **Pytest**: A versatile testing framework, enabling easy and comprehensive unit and integration tests for improved code reliability. | ||
- **Async CRUD Operations**: Fully asynchronous Create, Read, Update, Delete (CRUD) operations to maximize performance in high-concurrency environments. | ||
- **Flower Workflow Monitoring** (Optional): Integrated support for monitoring and managing background task workflows with tools like Celery. | ||
|
||
## Why This Stack? | ||
This template is designed to give developers a solid foundation for backend development: | ||
- **Performance and Scalability**: FastAPI's async capabilities paired with PostgreSQL ensure smooth handling of high-traffic workloads. | ||
- **Seamless Development**: Alembic simplifies database migrations, while Docker provides consistent development and production environments. | ||
- **Robust Testing**: Pytest enables thorough testing of API endpoints and business logic to catch bugs early in the development cycle. | ||
- **Modern Architecture**: Support for asynchronous workflows and containerization aligns with best practices in contemporary software development. | ||
|
||
Use this template as a starting point to build production-grade backend systems with ease and confidence. | ||
|
||
## Getting Started | ||
- **FastAPI**: A high-performance web framework for building APIs with Python, leveraging asynchronous features for speed and scalability. | ||
- **PostgreSQL**: A robust relational database system supporting complex queries and transactions. | ||
- **Alembic**: An efficient database migration tool to manage schema changes with version control. | ||
- **Docker**: Ensures consistent application behavior across environments, simplifying development and deployment. | ||
- **Pytest**: Enables comprehensive unit and integration testing for improved reliability. | ||
- **Async CRUD Operations**: Provides fully asynchronous Create, Read, Update, and Delete operations for high-concurrency scenarios. | ||
- **Flower (Optional)**: Workflow monitoring and management for background tasks with Celery. | ||
|
||
### Set Up Pipenv and Install Dependencies | ||
## Why Choose This Template? | ||
|
||
1. Export the variable for Pipenv: | ||
- **Performance and Scalability**: Asynchronous processing and robust database integration handle high-traffic applications effortlessly. | ||
- **Ease of Development**: Dockerized setup ensures consistency across development, testing, and production environments. | ||
- **Enhanced Reliability**: Comprehensive testing with Pytest reduces bugs and ensures code stability. | ||
- **Modern Architecture**: Adheres to contemporary software development best practices, supporting scalability and maintainability. | ||
|
||
```bash | ||
$ export PIPENV_VENV_IN_PROJECT=1 | ||
``` | ||
## Use Cases | ||
|
||
2. Activate the virtual environment: | ||
- **API-Driven Applications**: Build RESTful APIs with FastAPI and PostgreSQL. | ||
- **Microservices**: Create scalable and containerized microservices with Docker. | ||
- **Data-Intensive Systems**: Handle high-concurrency data processing with async operations. | ||
- **Task Automation**: Monitor and manage workflows for background tasks using Celery and Flower. | ||
|
||
```bash | ||
$ pipenv shell | ||
``` | ||
## Getting Started | ||
|
||
3. Install the required packages: | ||
### Prerequisites | ||
|
||
```bash | ||
$ make install | ||
``` | ||
- Install [Docker](https://www.docker.com/). | ||
- Install [Pipenv](https://pipenv.pypa.io/en/latest/). | ||
|
||
### Initialize Alembic | ||
### Installation | ||
|
||
1. Initiate Alembic: | ||
1. Clone the repository: | ||
|
||
```bash | ||
$ make build | ||
git clone https://github.com/your-username/fastapi-backend-starter-kit.git | ||
cd fastapi-backend-starter-kit | ||
``` | ||
|
||
2. Create a revision for the initial table (e.g., 'book' table): | ||
2. Set up the virtual environment: | ||
|
||
```bash | ||
$ make makemigrations | ||
export PIPENV_VENV_IN_PROJECT=1 | ||
pipenv shell | ||
``` | ||
|
||
### Build and Run with Docker | ||
|
||
1. Build the Docker images: | ||
3. Install dependencies: | ||
|
||
```bash | ||
$ make build | ||
make install | ||
``` | ||
|
||
2. Make migrations: | ||
### Running the Application | ||
|
||
1. Build Docker images: | ||
|
||
```bash | ||
$ make makemigrations | ||
make build | ||
``` | ||
|
||
3. Migrate the database: | ||
2. Apply migrations: | ||
|
||
```bash | ||
$ make migrate | ||
make makemigrations | ||
make migrate | ||
``` | ||
|
||
4. Run the application: | ||
3. Start the application: | ||
|
||
```bash | ||
$ make run | ||
make run | ||
``` | ||
|
||
Now, the project will be running on `http://localhost:8000` | ||
Access the application at `http://localhost:8000`. | ||
|
||
### Pgadmin4 | ||
### Additional Services | ||
|
||
http://localhost:5050 | ||
- **PgAdmin4**: Manage your PostgreSQL database at `http://localhost:5050`. | ||
- **Flower**: Workflow monitoring at `http://localhost:5556`. | ||
|
||
## Testing | ||
|
||
To run tests using Pytest, execute the following command within the virtual environment: | ||
Run tests using Pytest: | ||
|
||
```bash | ||
$ make test | ||
make test | ||
``` | ||
|
||
## Flower | ||
## API Documentation | ||
|
||
Navigate to http://localhost:5556 to view the dashboard. You should see one worker ready to go. | ||
- **Swagger UI**: `http://localhost:8000/docs` | ||
- **ReDoc**: `http://localhost:8000/redoc` | ||
|
||
## Documentation | ||
## Contributing | ||
|
||
``` | ||
swagger - http://localhost:8000/docs | ||
redoc - http://localhost:8000/redoc | ||
``` | ||
Contributions are welcome! Please follow the guidelines below: | ||
|
||
1. Fork the repository. | ||
2. Create a feature branch. | ||
3. Commit your changes. | ||
4. Submit a pull request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. | ||
|
||
--- | ||
|
||
Start building your next scalable backend application with ease and confidence using this FastAPI Backend Starter Kit. |