https://github.com/ahnaf19/fast-cart
fast-cart is a microservices-based e-commerce backend designed for high performance and scalability.
https://github.com/ahnaf19/fast-cart
fastapi microservices postgresql python redis
Last synced: about 2 months ago
JSON representation
fast-cart is a microservices-based e-commerce backend designed for high performance and scalability.
- Host: GitHub
- URL: https://github.com/ahnaf19/fast-cart
- Owner: Ahnaf19
- License: mit
- Created: 2025-03-21T00:01:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-01T06:14:41.000Z (6 months ago)
- Last Synced: 2026-01-04T21:55:34.229Z (6 months ago)
- Topics: fastapi, microservices, postgresql, python, redis
- Language: Python
- Homepage:
- Size: 142 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-cart
**fast-cart** is a microservices-based e-commerce backend designed for high performance and scalability.
## Project Overview
The project is designed to consist of two microservices:
1. **Inventory Service**:
This service manages product inventory, including stock levels, product details, and updates. It interacts with a redis database for storage, using redis for caching as well.
2. **Payment Service**:
This service handles payment processing, order validation, and transaction management, stored in postgresql. It also interacts with the Inventory Service to validate stock availability before processing payments. It also uses redis for caching as well.
3. **Inventory Frontend**
This service provides a user interface for managing inventory. It allows users to:
- View product details and stock levels.
- Add, update, or delete products.
- Monitor inventory changes in real-time.
The frontend is built using **React** for a responsive and dynamic user experience. It communicates with the Inventory Service via RESTful APIs to fetch and update data.
### Setup Instructions
1. Navigate to the `inventory-frontend` directory.
2. Install dependencies:
```sh
npm install
```
3. Start the development server:
```sh
npm run dev
```
4. Access the application at `http://localhost:3000`.
4. **Payment Frontend**
> in progress
5. **Event Driven Architecture**
Event-driven architecture enables seamless communication between the Payment and Inventory services using Redis Streams. When a payment is processed, the Payment Service publishes an event to a Redis stream. The Inventory Service subscribes to this stream, listens for payment events, and updates stock levels accordingly. This decoupled approach ensures scalability, real-time updates, and fault tolerance in the system. Also makes it easier to catch rare edge cases.
### Key Technologies
- **FastAPI**: For building high-performance APIs with Python.
- **Redis**: For caching and message brokering between microservices.
- **Redis Stream**: Used for event driven architecture.
- **SQL Database**: For persistent storage of inventory and payment data.
- **Docker**: For containerizing the microservices for easy deployment and scalability.
- **GitHub Actions**: For CI/CD pipelines to ensure code quality and automated testing.
- **Pre-commit Hooks**: For enforcing code formatting and linting standards.
### Microservice Interaction
The two microservices will communicate with each other using RESTful APIs with `FastAPI`. `Redis` will be used as a message broker for asynchronous tasks, such as updating inventory after a successful payment: part of event driven architecture.
### Future Enhancements
[x] Use SQL for persistant storage and redis for caching.
[ ] Add authentication and authorization mechanisms.
[x] Implement monitoring and logging for better observability.
[ ] Explore deployment options such as Kubernetes for scaling the microservices.
This project aims to serve as a robust starting point for building scalable and maintainable microservices with Python.
> [!NOTE]
> [Check Milestones](#milestones) below to track project progress.
---
> Being developed on: python 3.10.16

     
      
  
---
## Docker Build & Run
To build and run the application using Docker, follow these steps:
---
### Prerequisites
Ensure you have Docker installed on your machine. You can download it from [here](https://www.docker.com/products/docker-desktop).
#### Build Docker Image
> [!IMPORTANT]
> `Docker Daemon` or `Docker Desktop` must be running while building Docker Image.
Navigate to the root directory of the repo where the `Dockerfile` is located and run the following command to build the Docker image:
```sh
docker build -t fastcart:latest .
```
#### Run Docker Container
After building the Docker image, you can run it using the following command:
```sh
docker run -dp 8000:8000 :latest
```
or give the container a name:
```sh
docker run -dp 8000:8000 --name -latest :latest
```
This will start the application in a Docker container. The application can be accessed at `http://localhost:8000` e.g. `127.0.0.1:8000`
> [!NOTE]
> `-dp` (`-d` & `-p`) tag runs the container in detached mode (in the background, terminal is available to use right away) and container port `8000` is mapped to local port `8000`.
#### Stopping the Container
To stop the running container, first find the container ID using:
```sh
docker ps
```
Then stop the container using:
```sh
docker stop
```
---
## Run locally with Uvicorn
> this part is yet to be updated with repo structure
- [optional but recommended] create a venv and activate it
- Install dependencies:
```sh
pip install -r requirements.txt
```
- start Uvicorn server:
```sh
uvicorn app.main:app --reload
```
- `ctrl+c` to break the server.
---
## Milestones
- [x] develop inventory api ๐ค
- [x] develop payment api โจ
- [x] Interact between the microservices ๐
- [ ] unit testing ๐งช
- [ ] write comprehensive readme ๐
- [ ] write readme-dev ๐
- [ ] dockerize the repo ๐ณ
- [x] Code Auto-formatting & Linting with Pre-commit (check-yaml, end-of-file-fixer, trailing-whitespace, black, isort, mypy, flake8, bandit) ๐จ
- [x] add GitHub Action for format checks โ
- [ ] Study deploy requirement and deploy! ๐
---
## Collaborate & Contribute
Bug reports, issues, forks and pull requests are always welcome!
---
## License
This project is available as open source under the MIT License. See the [LICENSE](./LICENSE) file for details.