Skip to content

MohammadYR/Custom-Shop-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

build codeql license coverage

πŸ›οΈ Custom Shop Backend (Django + DRF)

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.


πŸ“š Table of Contents


✨ Features

  • πŸͺ 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.

🧩 Repository Structure

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


βš™οΈ Tech Stack

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

πŸš€ Quick Start

1️⃣ Run with Docker

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 redis

Default URLs:

πŸ›‘ To stop containers:

docker compose down

2️⃣ Run Locally (No Docker)

Requirements: 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 runserver

Run Celery manually:

celery -A config worker -l info
celery -A config beat -l info

🧾 Environment Variables (.env)

DJANGO_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

βš™οΈ Celery & Redis Architecture

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚        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:

  1. Django triggers a task (e.g., send email).
  2. Celery pushes it into Redis.
  3. Worker executes it asynchronously.
  4. Logs/results stored in DB or cache.

πŸ—„οΈ Database & Migrations

python manage.py makemigrations
python manage.py migrate

Switch to PostgreSQL easily by updating your .env values and restarting the app.


πŸ‘‘ Admin User

python manage.py createsuperuser

Then log in at /admin/.


πŸ“˜ API Documentation

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/


πŸ” Authentication

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"}'

πŸͺ„ Commit Convention & Branching

Follow Conventional Commits:

  • feat: new feature
  • fix: bug fix
  • refactor: structural improvement
  • docs: documentation
  • test: testing
  • chore: 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 β†’ main via Pull Request

🧱 Soft Delete & BaseModel

  • All models (except User) inherit from core.BaseModel.
  • Includes deleted_at field 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.

πŸ§‘β€πŸ’Ό Admin Panel & Branding

  • Jazzmin integration for modern UI.
  • Custom theme (e.g. flatly), logos, and CSS.
  • static/css/admin.css for typography and fonts (e.g. IRANYekanX).

πŸ§ͺ Testing & Code Quality

pytest -q
flake8
  • Unit tests cover Accounts, Catalog, Sales, and Payments.
  • Smoke tests via DRF + cURL recommended.

🚒 Deployment Checklist

  • 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.)

🧯 Troubleshooting

  • CRLF/LF warning (Windows):
    git config --global core.autocrlf true
  • Docker Desktop issues: restart service with admin rights.
  • Static files not loading: verify STATICFILES_DIRS or run collectstatic.

πŸ’‘ Found a bug or improvement idea?
Open an issue or send a pull request β€” contributions are welcome!


Made with ❀️ for Maktab130 Final Project.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors