Skip to content

A Template backend with FastAPI and Flask APIs, Nginx, Redis, and PGSQL in docker

License

Notifications You must be signed in to change notification settings

S3L1M/Backend-System

Repository files navigation

Backend-System

A template backend project with FastAPI and Flask APIs, Nginx, Redis, and PostgreSQL in Docker.

Table of Contents

Description

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.

Installation

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:

  1. Clone this repository to your local machine:

    git clone https://github.com/S3L1M/Backend-System.git
  2. Navigate to the project directory:

    cd Backend-System
  3. 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.

Usage

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.

Architecutre

Inventory dummy data

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()

Services

Add or remove services by modifying docker-compose.yaml file.

Optional

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"

Endpoints

FastAPI

  • 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 *required
    • max-price: float *required

Flask

  • GET /users/<username>: Get a user data.
  • POST /users: Create a new user.
    Request Body: *required
     {
        "username": "<string>"
        "email": "<string>"
        "password": "<string>"
     }
    Note: Authentication is NOT implemented. Recommended: Keycloak

Technologies Used

  • FastAPI
  • Flask
  • Nginx
  • Redis
  • PostgreSQL
  • Docker

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the Apache 2.0 License. Feel free to use it as a template for your backend projects.

About

A Template backend with FastAPI and Flask APIs, Nginx, Redis, and PGSQL in docker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published