Skip to content

jarifMohammed/flash-cart

Repository files navigation

FlashCart – Manage Flash Sales

FlashCart is a backend system designed for limited edition product drops. It handles high traffic, real time inventory and safe checkout using Redis.

The project demonstrates real world backend concepts such as:

  • Redis caching
  • MongoDB persistence
  • JWT authentication
  • Role based access (Admin/User)
  • Dockerized microservices

Node.js TypeScript MongoDB Redis Docker

Flash-cart-image

Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • MongoDB
  • Redis
  • JWT Authentication
  • Docker & Docker Compose

Project Structure

flash-cart/
├── src/
│   ├── controllers/
│   ├── routes/
│   ├── models/
│   ├── middlewares/
│   ├── config/
│   ├── types/
│   ├── app.ts
│   └── server.ts
├── docker-compose.yml
├── Dockerfile
├── tsconfig.json
├── package.json
└── README.md

Installation & Local Usage

1. Clone the repository

git clone https://github.com/km-saifullah/flash-cart.git
cd flash-cart

2. Install dependencies

npm install

3. Setup environment variables

Create a .env file:

PORT=5000
MONGO_URI=mongodb://localhost:27017/flashcart
REDIS_URL=redis://localhost:6379
JWT_SECRET=flashcart_secret

4. Start MongoDB & Redis

# MongoDB
mongod

# Redis
redis-server

5. Run the project

npm run dev

API runs at:

http://localhost:5000

Docker Setup

Run entire stack

docker-compose up --build

Services:

  • API → Node.js
  • MongoDB → Database
  • Redis → Cache & inventory

API Endpoints Overview

1. Authentication

Method Endpoint Description
POST /api/v1/auth/signup Register new user
POST /api/v1/auth/login Login User

2. Products (MongoDB + Redis Cache)

Method Endpoint Description
GET /api/v1/products Get all products
GET /api/v1/products/:id Get product by ID (Redis first)
POST /api/v1/products Admin only: create product
GET /api/v1/products/trending Top 3 most viewed products

3. Flash Sale (Redis)

Method Endpoint Description
POST /api/v1/sales/start/:id Push stock from Mongo to Redis
GET /api/v1/sales/stock/:id Get real time stock
POST /api/v1/sales/reserve/:id Reserve stock using Redis

4. Orders

Method Endpoint Description
POST /api/v1/orders Create order after reservation
GET /api/v1/orders View user orders
DELETE /api/v1/orders/:id Cancel order & restore stock

How the APIs Work

  • Admin creates product → stored in MongoDB

  • Admin starts sale → stock pushed to Redis

  • Users reserve stock

  • Successful reservation → order saved in MongoDB

  • Cancel order → Redis stock increment + Mongo update

  • Product views tracked → Redis Sorted Set

Security Features

  • JWT authentication
  • Role‑based authorization
  • Redis atomic inventory handling
  • Admin only protected routes

License

This project is licensed under the MIT License

Conclusion

FlashCart demonstrates how to design a scalable, production ready backend capable of handling flash sales with high concurrency, real time inventory and safe checkout.

Happy Coding!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors