Skip to content

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micro-Cart

Python 3.12+ FastAPI MySQL OpenTelemetry MIT License

A microservices-based e-commerce platform built with Python, FastAPI, MySQL, MongoDB, Redis.

Designed with clean architecture principles — domain-driven design, generic repository pattern, and containerized deployments using Docker Compose.

Services

Service Description Status
Product Catalog Categories and product management Active
User Management User registration and profiles Planned
Cart & Checkout Shopping cart and checkout flow Planned
Order Management Order processing and tracking Planned
Payment Payment gateway integration Planned
Authentication Auth and token management Planned

Tech Stack

  • Language: Python 3.14
  • Framework: FastAPI (async)
  • ORM: SQLAlchemy 2.0 (async, DeclarativeBase)
  • Database: MySQL 8
  • Migrations: Liquibase
  • Containerization: Docker, Docker Compose
  • Dependency Management: Poetry
  • Architecture: Microservices, Generic Repository Pattern

Skills Demonstrated

  • Zero-trust token authentication — every request is validated in two steps: local JWT signature verification via token-validator (no network call), then a session/revocation check against Auth Service.
  • Generic repository pattern — a single async base repository handles CRUD for all SQLAlchemy models; new entities require zero data-access boilerplate.
  • Service-per-domain decomposition — each microservice (Product, User, Cart, Order, Payment) is independently deployable with its own database, Makefile, and Docker Compose.
  • Compose-based local orchestrationmake up from the mono-repo root starts all services, databases, and migrations with a single command; per-service shortcuts (make product-up) enable focused development.
  • Infrastructure-as-code observability — logs, traces, and metrics are injected via instrumentation-hub with zero observability code in business logic.
  • Liquibase schema migrations — database changes are versioned YAML changesets applied automatically on container startup.
  • Pydantic settings + environment-driven config — all secrets, ports, and feature flags are loaded from environment variables, making services 12-factor compliant.

Project Structure

services/
└── product_service/
    ├── .env                        # shared config (ports, db name, etc.)
    └── components/
        ├── docker-compose.yaml     # root compose (includes db + app)
        ├── Makefile                # aggregate make targets
        ├── product_service_app/    # FastAPI application
        │   ├── src/api/
        │   │   ├── controllers/    # REST endpoints
        │   │   ├── services/       # business logic
        │   │   ├── repos/          # generic repository layer
        │   │   ├── models/         # SQLAlchemy entities
        │   │   ├── dtos/           # request/response schemas
        │   │   └── exceptions/     # custom exceptions
        │   └── smoke_tests/        # post-deploy smoke tests
        └── product_service_db/     # database + Liquibase migrations

Getting Started

Option A — Dev Container (Recommended)

Prerequisites: VS Code, Docker Desktop, Dev Containers extension

  1. Clone this repo
  2. Configure services/product_service/.env and export secrets:
    export PRODUCT_SERVICE_MYSQL_ROOT_PASSWORD=yourpassword
    export PRODUCT_SERVICE_SECRET_KEY=yourjwtsecret
  3. Open micro-cart/ in VS Code
  4. Click Reopen in Container when prompted
  5. All services (Product API, MySQL, Liquibase, phpMyAdmin) start automatically
  6. Product API: http://localhost:3002/product-service/docs

Start OAAS and Auth Service first.

As new services are added, they are included in docker-compose.yaml — no devcontainer changes needed.

Option B — Makefile

Prerequisites: Docker & Docker Compose, Make

  1. Configure services/product_service/.env and export secrets
  2. Run from the repo root:
    export PRODUCT_SERVICE_MYSQL_ROOT_PASSWORD=yourpassword
    export PRODUCT_SERVICE_SECRET_KEY=yourjwtsecret
    make up       # starts ALL services
    make ps       # check health

Make Commands

All commands run from the repo root (micro-cart/):

Command Description
make up Start all services (creates network automatically)
make stop Stop all services
make down Stop + remove all services
make clean Full teardown (containers, volumes, caches)
make build Rebuild all images (no cache)
make ps Show container status
make logs Follow all logs
make test Run tests for all services
make fmt Format code (ruff)
make lint Lint code (ruff)

Per-service shortcuts: make product-up, make product-stop, make product-down, make product-test, etc.

Service Endpoints

Service URL
Product API http://localhost:3002/product-service/docs
MySQL (Product) localhost:3001
phpMyAdmin (Product) http://localhost:3003

Authentication

Each microservice validates incoming requests in two steps:

  1. JWT signature + claims — validated locally using token-validator via the Auth Service JWKS endpoint (no network call to Auth Service API).
  2. Session / revocation check — calls Auth Service POST /session-status to confirm the token hasn’t been revoked.

See the Product Service README for configuration details.


Testing

Layer Scope
Unit Service logic, controllers, decorators
Functional Full request cycle via FastAPI TestClient
Smoke Post-deploy HTTP tests against running containers
make test       # all services
make product-test   # product service only

Related Repositories

Repository Purpose
Auth Service JWT authentication and RBAC
OAAS Observability stack (Grafana, Loki, Tempo, Prometheus)
Instrumentation Hub Client library for OpenTelemetry instrumentation
Token Validator RS256 JWT validation library with JWKS support

License

MIT — Copyright © 2026 Dilip Kumar Sharma.

About

Microservices e-commerce platform — FastAPI, clean architecture, token-based auth, Docker Compose

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages