Skip to content

jeremyjsx/orderly

Repository files navigation

Orderly

A scalable e-commerce backend built with FastAPI, featuring authentication, role-based access control, async processing with RabbitMQ, and real-time order tracking via WebSockets.

Features

  • Authentication: JWT with refresh tokens, password hashing (Argon2), rate limiting
  • Authorization: Role-based access (USER, ADMIN, DRIVER)
  • Products & Categories: Full CRUD with pagination, filters, and search
  • Shopping Cart: Stock validation, quantity management
  • Orders: State machine transitions, shipping addresses, driver assignment
  • Real-time Tracking: WebSocket-based order tracking with driver location updates
  • Async Processing: RabbitMQ for payment processing with retry and dead-letter queues
  • Caching: Redis caching for products and categories with automatic invalidation
  • Observability: Prometheus metrics, correlation IDs, structured JSON logging
  • Infrastructure: Health checks, CORS, rate limiting

Architecture

Architecture

Quick Start

Prerequisites

  • Python 3.11+
  • Docker & Docker Compose
  • Make

1. Clone and Setup

git clone https://github.com/jeremyjsx/orderly.git
cd orderly

# Create virtual environment
make venv

# Install dependencies
make install

# Setup environment
cp .env.example .env

2. Start Services

# Start infrastructure (DB, Redis, RabbitMQ, S3, Prometheus, Grafana)
make dev

# Apply database migrations
make migrate

# Start the API server with hot-reload
make run

3. Access the API

Development

Local Development (recommended)

make dev          # Start infrastructure only
make run          # Start API with hot-reload

Full Docker

make docker-build   # Build API image
make docker-up      # Start all services
make docker-logs    # View API logs
make docker-down    # Stop all services

Testing

make test       # Run all tests
make lint       # Lint code
make format     # Format code

Project Structure

app/
β”œβ”€β”€ api/                    # API router aggregation
β”œβ”€β”€ core/                   # Config, security, redis, middleware
β”‚   β”œβ”€β”€ config.py           # Pydantic settings
β”‚   β”œβ”€β”€ security.py         # JWT, password hashing
β”‚   β”œβ”€β”€ redis.py            # Redis client, tokens, cache
β”‚   β”œβ”€β”€ rate_limit.py       # Sliding window rate limiter
β”‚   β”œβ”€β”€ middleware.py       # Rate limit middleware
β”‚   β”œβ”€β”€ logging.py          # Structured logging with correlation IDs
β”‚   β”œβ”€β”€ s3.py               # S3 image uploads
β”‚   └── schemas.py          # Shared schemas
β”œβ”€β”€ db/                     # Database session
β”œβ”€β”€ events/                 # Async processing
β”‚   β”œβ”€β”€ client.py           # RabbitMQ connection
β”‚   β”œβ”€β”€ orders/             # Order events + WebSocket
β”‚   └── payments/           # Payment worker
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ auth/               # Login, register, refresh
β”‚   β”œβ”€β”€ cart/               # Shopping cart
β”‚   β”œβ”€β”€ categories/         # Product categories
β”‚   β”œβ”€β”€ health/             # Health checks
β”‚   β”œβ”€β”€ orders/             # Orders + shipping
β”‚   β”œβ”€β”€ products/           # Product catalog
β”‚   └── users/              # User management
└── main.py                 # App entry point

Tech Stack

Category Technology
Framework FastAPI
Database PostgreSQL + SQLAlchemy (async)
Cache Redis
Message Queue RabbitMQ
Auth JWT + Argon2
Real-time WebSockets
Monitoring Prometheus + Grafana
Migrations Alembic
Testing pytest + httpx
Containerization Docker

Environment Variables

See .env.example for all available configuration options.

Key variables:

  • DATABASE_URL: PostgreSQL connection string
  • REDIS_URL: Redis connection string
  • RABBITMQ_URL: RabbitMQ connection string
  • JWT_SECRET_KEY: Secret for JWT signing (change in production!)
  • CORS_ORIGINS: Allowed origins (comma-separated or *)

About

πŸ›’ Scalable e-commerce backend with auth, roles, async processing and real-time order tracking

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages