A production-style REST API for an e-commerce platform built with Flask, SQLAlchemy, and JWT authentication. Features an ML-powered product recommendation endpoint using sentence transformers and cosine similarity.
Base URL: https://ecommerce-api-8zsy.onrender.com
- Backend: Python, Flask, SQLAlchemy, Flask-Migrate
- Auth: JWT (Flask-JWT-Extended), bcrypt
- ML: Sentence Transformers (all-MiniLM-L6-v2), scikit-learn
- Database: SQLite (development), PostgreSQL (production)
- Deployment: Render
- JWT authentication with role-based access (customer/admin)
- Product search and filtering by category and price
- Pagination on all list endpoints
- ML-powered recommendations using TF-IDF similarity
- Rate limiting on auth endpoints (5 requests/minute)
- Unit tested with pytest
- Deployed on Render with PostgreSQL
git clone https://github.com/your-username/ecommerce-api.git cd ecommerce-api
python -m venv venv venv\Scripts\activate # Windows source venv/bin/activate # Mac/Linux
pip install -r requirements.txt
Copy .env.example to .env and fill in your values.
flask db upgrade
python run.py
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/register | Register new user | No |
| POST | /auth/login | Login and get token | No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /products | List all products | User |
| GET | /products?category=electronics | Filter by category | User |
| GET | /products/:id | Get single product | User |
| POST | /products | Create product | Admin |
| GET | /products/:id/recommendations | ML recommendations | User |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /orders | Place an order | User |
| GET | /orders | Get order history | User |
| GET | /orders/:id | Get single order | User |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /admin/orders | View all orders | Admin |
| PATCH | /admin/orders/:id/status | Update order status | Admin |
| DELETE | /admin/products/:id | Delete product | Admin |
The /products/:id/recommendations endpoint uses semantic similarity
to find related products. Product names and descriptions are encoded
using the all-MiniLM-L6-v2 sentence transformer model, and cosine
similarity is used to rank results.
This means "noise cancelling headphones" and "audio device with sound isolation" would score high similarity even with no shared keywords.
POST /auth/login Content-Type: application/json
{ "email": "user@example.com", "password": "password123" }
Response: { "access_token": "eyJhbGci...", "user": { "id": 1, "email": "user@example.com", "role": "customer" } }