A backend API for an e-commerce system built with FastAPI, modular architecture, MySQL, and containerized using Docker. It includes user management, product catalog, inventory control, orders, payments, and an audit logging system.
·FastAPI ·SQLAlchemy ORM ·MySQL 8.0 ·Pydantic ·Docker & Docker Compose ·Uvicorn ·Python 3.12+
app/ │ ├── models/ · SQLAlchemy models (User, Order, Payment, etc.) ├── schemas/ · Pydantic validation schemas ├── routers/ · API endpoints (CRUD routes) ├── services/ · Business logic (Orders, Payments) ├── db/ · Database configuration ├── utils/ · Auth, helpers ├── seed_script.py · Initial data seeding
·User registration and authentication ·Role-based access (admin / user)
·Full CRUD for products ·Predefined categories ·Inventory management
·Create orders with multiple items ·Automatic total calculation ·Order ↔ OrderItems relationship
·Simulated payment processing ·Extensible providers (fake, Stripe, PayPal ready) ·Payment states (pending, success, failed)
·pending_payment ·paid ·cancelled ·shipped (extensible)
Event tracking for: ·Order creation ·Payments ·Status changes ·User actions
- Clone the repository git clone https://github.com/yourusername/ecommerce-api.git cd ecommerce-api
- Create .env file DATABASE_URL=mysql+pymysql://root:1234@db:3306/ecommerce
- Start containers docker compose up --build
- Access the API API: http://localhost:8000 Swagger Docs: http://localhost:8000/docs
·API Service ·FastAPI application running on port 8000 ·Database Service ·MySQL 8.0 ·Persistent storage via Docker volumes
Order Flow User → Create Order → OrderItems → Payment → Update Order Status → Audit Log Payment Flow Create Payment ↓ Validate Order ↓ Fake Payment Provider (success/failure) ↓ Update Payment Status ↓ Update Order State ↓ Create Audit Log Event
·Order State Machine ·Decoupled payment service ·Audit logging system (Stripe-inspired) ·Layered / clean-ish architecture ·Fully containerized with Docker ·Ready for microservices evolution
Includes a seed script that creates:
·Admin user Default categories: ·Electronics ·Food ·Cleaning ·Home ·python seed_script.py
·Password hashing ·Role-based access control ·Authentication-ready structure (JWT extensible) ·Protected service layers
·Stripe integration ·Pytest test suite ·Pagination for endpoints ·Redis caching layer ·Advanced logging (ELK stack) ·Deployment (AWS / Render / Railway) ·CI/CD with GitHub Actions
This project was built as an advanced backend engineering practice focused on scalable architecture, clean design, and real-world system patterns