A multi-vendor e-commerce backend built with Django 5, DRF, and Celery/Redis, developed as part of the Maktab130 Final Project.
For a quick start, jump to the Quick Start section below.
- Features
- Repository Structure
- Tech Stack
- Quick Start
- Environment Variables (.env)
- Celery & Redis Architecture
- Database & Migrations
- Admin User
- API Documentation
- Authentication
- Commit Convention & Branching
- Soft Delete & BaseModel
- Admin Panel & Branding
- Testing & Code Quality
- Deployment Checklist
- Troubleshooting
- πͺ Multi-vendor marketplace: seller registration, store creation, inventory management.
- π¦ Product catalog: nested categories, product attributes, image galleries.
- π Cart & Checkout: persistent cart, discount handling, order snapshot.
- π³ Payments: record and verify transactions (Zarinpal-ready).
- π€ Authentication: JWT + OTP with custom user and address book.
- βοΈ Celery & Redis: asynchronous background jobs and notifications.
- π§± Soft Delete: recoverable records for all domain models.
- π§° API-first design: complete OpenAPI documentation via
drf-spectacular.
config/ # Settings, URLs, Celery app, ASGI/WSGI
core/ # BaseModel, Soft Delete logic, shared utils
accounts/ # Authentication, OTP, Profile, Address
catalog/ # Category & Product management
marketplace/ # Store & vendor models
sales/ # Cart, Order, Checkout
payments/ # Payment records, verification, callbacks
reviews/ # (optional) Ratings and reviews
static/ # Static assets (local)
frontend/ # Optional React (Vite) frontend
docker/ # Dockerfile & docker-compose.yml
docs/ # Documentation, ERD, API schemas
π ERD β available in docs/myapp_models.png
| Layer | Technology |
|---|---|
| Backend | Python 3.11, Django 5, DRF |
| Auth | SimpleJWT, OTP |
| Async | Celery 5, Redis |
| Database | SQLite (dev) / PostgreSQL (prod) |
| API Docs | drf-spectacular, Swagger UI |
| Admin UI | Jazzmin |
| Testing | pytest, flake8 |
Recommended for consistency and deployment parity.
Step-by-step:
# 1. Copy environment file
cp .env.example .env
# 2. Build and start all services (web, redis, celery, celery-beat)
docker compose up --build -d
# 3. Apply migrations
docker compose exec web python manage.py migrate
# 4. Create admin user
docker compose exec web python manage.py createsuperuser
# 5. View logs
docker compose logs -f web
docker compose logs -f celery
docker compose logs -f redisDefault URLs:
- API β http://127.0.0.1:8000
- Admin β
/admin/ - Swagger β
/api/schema/swagger-ui/
π To stop containers:
docker compose downRequirements: Python 3.11, Redis (optional)
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # and update values
python manage.py migrate
python manage.py runserverRun Celery manually:
celery -A config worker -l info
celery -A config beat -l infoDJANGO_DEBUG=True
DJANGO_SECRET_KEY=change-me
ALLOWED_HOSTS=127.0.0.1,localhost
# Database
DB_ENGINE=sqlite
DB_NAME=db.sqlite3
# or PostgreSQL
# DB_ENGINE=postgres
# DB_NAME=maktab130
# DB_USER=postgres
# DB_PASSWORD=postgres
# DB_HOST=127.0.0.1
# DB_PORT=5432
# Redis
REDIS_URL=redis://redis:6379/0
# JWT
SIMPLE_JWT_ACCESS_LIFETIME_MIN=30
SIMPLE_JWT_REFRESH_LIFETIME_DAYS=7
# Admin Branding
ADMIN_SITE_TITLE=Maktab130 Admin
ADMIN_SITE_HEADER=Maktab130
ADMIN_LOGO=/static/img/logo.png ββββββββββββββββββββββββββββββββ
β Django Backend β
β (views, models, signals) β
ββββββββββββββββ¬ββββββββββββββββ
β
sends async task
β
βΌ
ββββββββββββββββ
β Celery β β Task queue manager
ββββββββ¬ββββββββ
β
publishes job
β
βΌ
ββββββββββββββββ
β Redis β β Message broker & cache
ββββββββ¬ββββββββ
β
pulls job
βΌ
ββββββββββββββββ
β Worker β β Executes async tasks
ββββββββββββββββ
Flow:
- Django triggers a task (e.g., send email).
- Celery pushes it into Redis.
- Worker executes it asynchronously.
- Logs/results stored in DB or cache.
python manage.py makemigrations
python manage.py migrateSwitch to PostgreSQL easily by updating your .env values and restarting the app.
python manage.py createsuperuserThen log in at /admin/.
| Path | Description |
|---|---|
/api/accounts/register/ |
Register new user |
/api/accounts/login/ |
Obtain JWT tokens |
/api/accounts/token/refresh/ |
Refresh access token |
/api/accounts/request-otp/, /verify-otp/ |
OTP verification |
/api/myuser/ |
View/update profile |
/api/myuser/address/ |
Manage addresses |
/api/categories/ |
Public categories |
/api/stores/ |
Public stores |
/api/mycart/, /add_to_cart/{id}/ |
Manage shopping cart |
/api/orders/checkout/ |
Convert cart to order |
/api/payments/verify/ |
Verify payment |
Swagger UI β /api/schema/swagger-ui/
ReDoc β /api/schema/redoc/
Use JWT Bearer Tokens:
Authorization: Bearer <access_token>
Example login request:
curl -X POST http://127.0.0.1:8000/api/accounts/login/ \
-H "Content-Type: application/json" \
-d '{"identifier":"user@example.com", "password":"yourpass"}'Follow Conventional Commits:
feat: new featurefix: bug fixrefactor: structural improvementdocs: documentationtest: testingchore: config/infra
Examples:
feat(accounts): add OTP verification flow
fix(cart): correct total price calculation
chore(gitignore): ignore static/icons/*.svg
Workflow:
- Develop features in
feature/* - Merge into
dev - Merge
dev β mainvia Pull Request
- All models (except User) inherit from
core.BaseModel. - Includes
deleted_atfield and a custom manager/queryset. - Deleted records remain in DB but hidden by default.
- Benefits: recoverability, audit history, data safety.
- Indexed on
(deleted_at, updated_at)for performance.
- Jazzmin integration for modern UI.
- Custom theme (e.g.
flatly), logos, and CSS. static/css/admin.cssfor typography and fonts (e.g. IRANYekanX).
pytest -q
flake8- Unit tests cover Accounts, Catalog, Sales, and Payments.
- Smoke tests via DRF + cURL recommended.
DEBUG=False- Valid
ALLOWED_HOSTS - PostgreSQL database ready
- Collect static files:
python manage.py collectstatic --noinput
- Run with Gunicorn/Uvicorn + Nginx
- Secure environment variables (
SECRET_KEY,JWT,CORS, etc.)
- CRLF/LF warning (Windows):
git config --global core.autocrlf true - Docker Desktop issues: restart service with admin rights.
- Static files not loading: verify
STATICFILES_DIRSor runcollectstatic.
π‘ Found a bug or improvement idea?
Open an issue or send a pull request β contributions are welcome!
Made with β€οΈ for Maktab130 Final Project.