Giter VIP home page Giter VIP logo

backend-system's Introduction

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.

backend-system's People

Contributors

s3l1m avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.