A production-style backend system for a marketplace platform built using FastAPI, PostgreSQL, and AI-powered recommendations.
This project simulates the backend architecture used in modern marketplace platforms by implementing:
- Secure user authentication
- Marketplace item listings
- Keyword-based search system
- AI-powered recommendation engine
- Marketplace analytics APIs
- Containerised deployment using Docker
Interactive API documentation via Swagger UI:
http://127.0.0.1:8000/docs
Swagger provides a full interactive interface for testing all API endpoints.
The objective of this project is to design and implement a scalable backend architecture for a marketplace platform.
Users of the platform can:
- Register and authenticate securely
- Create and manage marketplace listings
- Search items efficiently
- Receive AI-based recommendations
- Analyse marketplace trends using analytics endpoints
The system demonstrates real-world backend architecture patterns used in production systems.
| Category | Tools |
|---|---|
| Language | Python |
| Backend Framework | FastAPI |
| Database | PostgreSQL |
| ORM | SQLAlchemy |
| Authentication | JWT |
| Security | Bcrypt Password Hashing |
| Machine Learning | Scikit-learn |
| Infrastructure | Docker |
| Documentation | Swagger / OpenAPI |
| Version Control | Git & GitHub |
Client
β
FastAPI Backend
β
Authentication Layer (JWT)
β
Marketplace Services
ββ User Management
ββ Item Listing
ββ Search Engine
ββ AI Recommendation Engine
ββ Analytics Service
β
PostgreSQL Database
The backend follows a modular service-oriented architecture.
graph TD
Client[Client Application]
API[FastAPI Backend]
Auth[Authentication Service]
ItemService[Item Listing Service]
Search[Search Engine]
AI[Recommendation Engine]
Analytics[Analytics Service]
DB[(PostgreSQL Database)]
Client --> API
API --> Auth
API --> ItemService
API --> Search
API --> AI
API --> Analytics
Auth --> DB
ItemService --> DB
Search --> DB
AI --> DB
Analytics --> DB
The system uses a relational database with the following core entities.
erDiagram
USER {
int id
string username
string email
string password_hash
}
ITEM {
int id
string title
float price
string category
string description
int seller_id
}
USER ||--o{ ITEM : creates
Secure authentication system with password hashing and JWT tokens.
Endpoints:
- POST /users/register
- POST /users/login
Validation rules:
- Username must be 6β12 characters
- Password must contain uppercase, lowercase, number, and special character
- Email format validation included
POST /users/register
{
"username": "premnadh",
"email": "prem123@gmail.com",
"password": "Prem@123"
}{
"id": 175,
"username": "premnadh",
"email": "prem123@gmail.com"
}Users can create and manage marketplace listings.
Endpoints:
- POST /items/create
- GET /items
- GET /items/{item_id}
- DELETE /items/{item_id}
Item attributes include:
- title
- price
- category
- description
- seller_id
Marketplace search functionality allows users to find items quickly.
Endpoint:
GET /items/search?q=keyword
Example:
/items/search?q=iphone
Features:
- Keyword search
- Category filtering
The backend includes a content-based recommendation system that suggests similar marketplace items.
Algorithm used:
- TF-IDF vectorisation
- Cosine similarity
Item title + description
β
TF-IDF vectorisation
β
Cosine similarity comparison
β
Top similar items returned
Endpoint:
GET /recommendations/{item_id}
{
"item_id": 52,
"recommended_items": [
{
"id": 48,
"title": "iPhone 12 Pro",
"similarity_score": 0.92
},
{
"id": 37,
"title": "iPhone 11",
"similarity_score": 0.89
}
]
}Analytics endpoints provide insights into marketplace activity.
Endpoints:
- GET /analytics/popular-items
- GET /analytics/top-categories
- GET /analytics/price-distribution
These APIs analyse:
- Most popular listings
- Category trends
- Price distribution patterns
| Method | Endpoint | Description |
|---|---|---|
| POST | /users/register | Register new user |
| POST | /users/login | Authenticate user |
| POST | /items/create | Create marketplace listing |
| GET | /items | Retrieve all items |
| GET | /items/{item_id} | Retrieve specific item |
| DELETE | /items/{item_id} | Delete item |
| GET | /items/search?q= | Search items |
| GET | /recommendations/{item_id} | Get recommended items |
| GET | /analytics/popular-items | Popular listings |
| GET | /analytics/top-categories | Category insights |
| GET | /analytics/price-distribution | Price distribution analysis |
User registers
β
User logs in
β
JWT token generated
β
User creates item listing
β
Items searchable
β
Recommendation engine suggests similar items
To maintain performance as marketplace data grows, the system includes:
- Indexed database queries for faster search
- Pagination support for large item lists
- Asynchronous FastAPI endpoints
- Efficient TF-IDF vectorisation for recommendation computation
- Containerised services enabling scalable deployment
Future performance improvements may include:
- Redis caching
- Background processing using Celery
- Vector databases for large-scale similarity search
Security is implemented using several best practices:
- Password hashing using bcrypt
- JWT-based authentication for stateless sessions
- Input validation using Pydantic schemas
- Protected API endpoints requiring authentication
- SQLAlchemy ORM preventing SQL injection vulnerabilities
Potential security improvements:
- API rate limiting
- OAuth authentication
- Refresh token rotation
Example API requests using curl.
These examples demonstrate how the API can be used programmatically from the command line or other services.
curl -X POST http://127.0.0.1:8000/users/register \
-H "Content-Type: application/json" \
-d '{
"username": "premnadh",
"email": "prem123@gmail.com",
"password": "Prem@123"
}'curl -X POST http://127.0.0.1:8000/users/login \
-H "Content-Type: application/json" \
-d '{
"username": "premnadh",
"password": "Prem@123"
}'Response
{
"access_token": "jwt-token",
"token_type": "bearer"
}curl -X POST http://127.0.0.1:8000/items/create \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "iPhone 13",
"price": 650,
"category": "electronics",
"description": "Excellent condition iPhone",
"seller_id": 175
}'curl "http://127.0.0.1:8000/items/search?q=iphone"curl "http://127.0.0.1:8000/recommendations/52"curl "http://127.0.0.1:8000/analytics/popular-items"Clone repository
git clone https://github.com/premnadh/smart-marketplace-engine.git
Navigate into project
cd smart-marketplace-engine
Install dependencies
pip install -r requirements.txt
Start PostgreSQL container
docker compose up -d
Run the API server
uvicorn app.main:app --reload
Open API documentation
http://127.0.0.1:8000/docs
smart-marketplace-engine
β
βββ app
β βββ api
β β βββ users.py
β β βββ items.py
β β βββ analytics.py
β β
β βββ ai
β β βββ recommender.py
β β
β βββ database
β β βββ db.py
β β
β βββ models
β β βββ user.py
β β βββ item.py
β β
β βββ schemas
β β βββ user_schema.py
β β βββ item_schema.py
β β
β βββ utils
β β βββ auth.py
β β βββ jwt_handler.py
β β
β βββ main.py
β
βββ scripts
β βββ seed_data.py
β
βββ Dockerfile
βββ docker-compose.yml
βββ requirements.txt
βββ README.md
- Secure JWT authentication
- Marketplace item listing system
- Search functionality
- AI-powered recommendation system
- Marketplace analytics APIs
- PostgreSQL database integration
- Docker container deployment
- Modular backend architecture
Potential future upgrades for the system include:
- Advanced search ranking algorithm
- Redis caching for faster API responses
- Real-time recommendation updates
- Frontend marketplace interface
- Cloud deployment (AWS / GCP / Render)
- Microservices-based architecture
Prem Nadh Gajula
Aspiring Data Scientist | Machine Learning Engineer | Backend Developer
Interested in:
- AI systems
- backend architecture
- machine learning applications
If you like this project, consider β starring the repository.