A template backend project with FastAPI and Flask APIs, Nginx, Redis, and PostgreSQL in Docker.
This project provides a template backend with two APIs built using FastAPI and Flask frameworks. It includes an Nginx server as the API gateway, Redis for caching, and PostgreSQL as the database. The Docker environment ensures easy setup and deployment, making it convenient for developers to use this template as a starting point for their backend projects.
To use this template backend, you need to have Docker installed on your system. Follow the steps below to set up and run the project:
-
Clone this repository to your local machine:
git clone https://github.com/S3L1M/Backend-System.git
-
Navigate to the project directory:
cd Backend-System
-
Build the Docker images and start containers:
./run.sh
The APIs will be accessible through API gateway (Ngnix) at http://localhost:8000/inventory
(FastAPI) and http://localhost:8000/accounts
(Flask) once the containers are up and running.
This template backend provides two different APIs using FastAPI and Flask frameworks. You can use any of these APIs based on your preference and requirements. The API endpoints are detailed in endpoints section.
By defualt, inventory database will be populated with dummy data with the following code in inventory-service/app.py
file.
# Add dummy product data
db = SessionLocal()
for i in range(1, 101):
name = f'Product_{i}'
price = round(random.uniform(1.99, 999.99), 2)
description = lorem.get_sentence(count=2)
product = Product(name=name, price=price, description=description)
db.add(product)
db.commit()
db.close()
Add or remove services by modifying docker-compose.yaml
file.
You can add the following (redis commander) to docker-compose.yaml
to view redis cache
redis-commander:
container_name: redis-commander
hostname: redis-commander
image: rediscommander/redis-commander:latest
environment:
- REDIS_HOSTS=redis:caching-db:6379
ports:
- "8081:8081"
- GET
/products
: Get all products. - GET
/products/{name}
: Get a product by its name. - GET
/products/search
: Search for products based on a keyword.
Query parameters:keyword
: string *required
- GET
/products/price-range
: Get products within a specified price range.
Query parameters:min-price
: float *requiredmax-price
: float *required
- GET
/users/<username>
: Get a user data. - POST
/users
: Create a new user.
Request Body: *requiredNote: Authentication is NOT implemented. Recommended:{ "username": "<string>" "email": "<string>" "password": "<string>" }
Keycloak
- FastAPI
- Flask
- Nginx
- Redis
- PostgreSQL
- Docker
Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the Apache 2.0 License. Feel free to use it as a template for your backend projects.