A production-grade RESTful API for an e-commerce platform built with FastAPI, PostgreSQL, and Docker.
Live Render hosting URL - https://e-commerce-platform-app-latest.onrender.com/docs

- Product management (create, list)
- Order processing with stock validation
- Comprehensive error handling
- Cloud based Postgres Database hosting over Render (https://render.com/)
- Database migrations with Alembic
- Structured logging
- Unit and integration tests
- Docker support
- Live Render Hosting (available live for limited period)
- API Specification and Schema (localhost url) : Swagger http://127.0.0.1:8000/docs#/ Redoc http://127.0.0.1:8000/redoc
- Python 3.13+
- FastAPI
- PostgreSQL
- SQLAlchemy
- Alembic
- Poetry
- Docker
- pytest
This FastAPI-based e-commerce platform demonstrates production-grade practices through a thoughtfully designed order management system. The application uses a junction table (OrderItem) approach for handling order-product relationships, enabling efficient tracking of pricing, maintaining order integrity, and supporting complex queries. The data model leverages SQLAlchemy with PostgreSQL, implementing proper foreign key constraints and relationships between Products, Orders, and OrderItems tables.
The application architecture follows best practices with clear separation of concerns: models for database schema, Pydantic schemas for validation, services for business logic, and controllers for API endpoints. Error handling is implemented through custom exception classes and proper HTTP status codes. The codebase is production-ready with features like input validation, stock management, transactional integrity, and comprehensive logging. The application is containerized using Docker for consistent deployment, with separate configurations for development and production environments.
The system includes unit tests for business logic and integration tests for API endpoints using pytest. Database migrations are handled through Alembic, ensuring smooth schema updates. The application is configured for deployment on Render with PostgreSQL database integration, demonstrating real-world deployment practices. Documentation is automatically generated through FastAPI's built-in Swagger UI, making API exploration and testing straightforward.
Main tables: Products, Orders, OrderItems (junction table)
Benefits of junction table (OrderItems) approach:
- Maintains historical pricing with price_at_time
- Enables many-to-many relationship between Orders and Products
- Stores quantity and subtotal per item
- Preserves order data even if products change/delete
- Easier reporting and analytics
Models (SQLAlchemy) Schemas (Pydantic) Services (Business logic) Routes (API endpoints)
- Clone the repository:
git clone
cd e-commerce_platform_app- Install dependencies with Poetry:
poetry install- Set up environment variables:
Create a
.envfile with:
DATABASE_URL=postgresql://user:password@localhost:5432/ecommerce_db
- Run database migrations:
poetry run alembic upgrade head- Start the development server:
poetry run uvicorn app.main:app --reloadRun unit tests:
poetry run pytest tests/unit/Run integration tests:
poetry run pytest tests/integration/- Build the Docker image:
docker build -t e-commerce-platform-app .- Run the container: docker run -d -p 8080:8000 -e DATABASE_URL=postgresql://********************-a.frankfurt-postgres.render.com/ecomdb_0l2p --name e-commerce-app-container e-commerce-platform-app:latest
Once running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
GET /product/all_products- List all productsPOST /product/create_product- Create a new product
POST /order/create_order- Create a new order
The API includes comprehensive error handling for:
- Insufficient stock
- Product not found
- Invalid order creation
- Database errors
Structured logging is implemented using structlog. Logs include:
- Error information
- Business operations
- Fork the repository
- Create a feature branch
- Commit changes
- Push to the branch
- Create a Pull Request
This backend service is available via Render platform where docker container is running from docker registry Render is a cloud platform designed for deploying and hosting applications and services. It simplifies the process of building, deploying, and managing apps by abstracting much of the infrastructure management, allowing developers to focus on their application code.
this backend service is hosted on render - https://e-commerce-platform-app-latest.onrender.com/docs
- Authentication using OAuth
- CI/CD deployment
- scaling using K8s
- performance monitoring using Grafana or Datadog or Dynatrace
- Rate limiting
- UUID support
- https security
- api versioning