Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

Repository files navigation

CI Python Django DRF PostgreSQL Docker tests lint types

🍺 Hop & Barley

Language / Мова: English | Π£ΠΊΡ€Π°Ρ—Π½ΡΡŒΠΊΠ°

A full-stack e-commerce shop for home-brewing ingredients β€” Django web UI + DRF REST API, on PostgreSQL & Docker.

πŸ”— Live Demo

Free hosting β€” first load may take ~40s to wake. Demo login: admin / check Render dashboard for password.


Table of Contents


Features

Area What's included
Catalog Product listing with pagination, search, category & price filters, sorting by price / newest / popularity
Product page Full details, average star rating, review section β€” reviewable only after "delivered" status
Cart Session-based cart: add, remove, update quantity, stock validation, live total
Checkout Shipping form, order creation, email notification to user & admin
Account Registration, login/logout (session auth), order history with status filter, profile & password edit
Admin Custom analytics dashboard, role-based permissions (superuser / Manager), search, filters, bulk actions
REST API JWT-protected endpoints for products, orders, cart, reviews, users; Swagger/OpenAPI docs
Deployment Docker + docker-compose, Render Blueprint (render.yaml), WhiteNoise for static files

Tech Stack

Layer Technology
Backend Django 4.2, Python 3.11
REST API Django REST Framework 3.17, SimpleJWT
API Docs drf-spectacular (Swagger/OpenAPI)
Database PostgreSQL 15
Auth Session (web UI) + JWT (API)
Static files WhiteNoise
Containerisation Docker, docker-compose
Deployment Render (free tier, Docker runtime)
Testing pytest-django, pytest-cov
Linting flake8, mypy

Project Structure

hop-and-barley/
β”œβ”€β”€ api/                  # DRF ViewSets, serializers, JWT endpoints
β”œβ”€β”€ config/               # Django settings, URLs, WSGI
β”œβ”€β”€ docker/               # entrypoint.sh (migrate β†’ seed β†’ start)
β”œβ”€β”€ orders/               # Order & cart logic, analytics view, admin
β”œβ”€β”€ pages/                # Static content pages (Guides, Community)
β”œβ”€β”€ payments/             # Payment model (mock)
β”œβ”€β”€ products/             # Product & category models, catalog views
β”œβ”€β”€ reviews/              # Review model & submission view
β”œβ”€β”€ static/               # CSS, JS, product images
β”œβ”€β”€ templates/            # Django HTML templates
β”œβ”€β”€ tests/                # API & integration tests
β”œβ”€β”€ users/                # Registration, profile, password change
β”œβ”€β”€ .github/workflows/    # GitHub Actions CI
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ render.yaml           # Render deployment blueprint
β”œβ”€β”€ requirements.txt
└── manage.py

Quick Start β€” Docker

The fastest way to get a running instance with demo data:

git clone https://github.com/marko-onechance/django_brew_shop.git
cd django_brew_shop
docker-compose up --build

On first start the entrypoint automatically:

  1. Runs all database migrations
  2. Seeds the demo product catalog with images
  3. Creates a Manager permission group
  4. Creates a demo superuser (admin / admin1234)

Open http://localhost:8000 β€” the shop is ready.


Local Development

Prerequisites

  • Python 3.11+
  • PostgreSQL 15 running locally (or use Docker just for DB)
  • pip

Setup

# 1. Clone & create virtual environment
git clone https://github.com/marko-onechance/django_brew_shop.git
cd django_brew_shop
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

# 2. Install dependencies
pip install -r requirements.txt

# 3. Configure environment
cp .env.example .env
# Edit .env β€” set DATABASE_NAME / USER / PASSWORD / HOST to match your local PG

# 4. Apply migrations and seed demo data
python manage.py migrate
python manage.py seed_catalog
python manage.py create_roles
python manage.py create_demo_admin   # creates admin / admin1234

# 5. Start the dev server
python manage.py runserver

Open http://localhost:8000


REST API & JWT

Base URL: /api/
Interactive docs: http://localhost:8000/api/docs/

Authentication flow

# 1. Obtain tokens
curl -X POST http://localhost:8000/api/users/login/ \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "admin1234"}'

# Response:
# { "access": "eyJ...", "refresh": "eyJ..." }

# 2. Use access token in subsequent requests
curl http://localhost:8000/api/orders/ \
  -H "Authorization: Bearer eyJ..."

# 3. Refresh an expired access token
curl -X POST http://localhost:8000/api/users/token/refresh/ \
  -H "Content-Type: application/json" \
  -d '{"refresh": "eyJ..."}'

Key endpoints

Method URL Auth Description
GET /api/products/ β€” Product list (search, filter, paginate)
GET /api/products/{id}/ β€” Product detail
GET/POST /api/products/{id}/reviews/ POST: JWT List or submit a review
GET/POST /api/orders/ JWT User's orders
GET/PATCH/DELETE /api/orders/{id}/ JWT Single order
GET/POST/PATCH/DELETE /api/cart/ β€” Cart management
POST /api/users/register/ β€” Create account
POST /api/users/login/ β€” Obtain JWT tokens
POST /api/users/token/refresh/ β€” Refresh access token
GET /api/docs/ β€” Swagger UI
GET /api/schema/ β€” OpenAPI schema (JSON)

Admin Panel

Access at http://localhost:8000/admin/

  • Products & Categories β€” full CRUD with image upload, slug auto-fill, stock tracking
  • Orders β€” inline order items, bulk status actions (Mark as Shipped / Delivered), revenue action
  • Reviews β€” moderation, filter by rating and product
  • Users β€” manage accounts and group memberships
  • Analytics β€” custom dashboard at /admin/orders/order/analytics/ with:
    • Total revenue, total orders, revenue last 30 days, total users
    • Orders breakdown by status with per-status revenue
    • Top 10 products by units sold and revenue
    • Revenue by category
    • Daily orders chart (last 30 days)

Role-based permissions:

Role Can view Can change Can add Can delete
Superuser βœ… all βœ… all βœ… all βœ… all
Manager βœ… orders, products βœ… orders, products ❌ ❌
Regular user ❌ ❌ ❌ ❌

Tests & Linters

# Run all tests
python -m pytest

# Run with coverage report
python -m pytest --cov=. --cov-report=term-missing

# Lint
flake8 .

# Type checking
mypy . --ignore-missing-imports

Current test suite: 36 tests, all passing.

Coverage areas:

  • Product API (list, detail, 404)
  • Order API (auth-guard, user isolation)
  • User registration & JWT auth
  • Swagger / schema endpoints
  • Product & Category models
  • Product catalog views
  • User registration, login, logout, account page
  • Review model (creation, uniqueness constraint, average rating)

Deployment on Render

The repo includes a render.yaml Blueprint that provisions a free PostgreSQL database and a web service automatically.

Steps:

  1. Push the repository to GitHub
  2. Go to render.com β†’ New β†’ Blueprint
  3. Connect your GitHub repository
  4. Render detects render.yaml and creates both the database and the web service
  5. Click Apply β€” first deploy takes ~3 minutes

On every deploy, the Docker entrypoint runs migrations and re-seeds demo data, so the demo catalog is always populated even after ephemeral storage resets.

Environment variables set automatically by Render:

Variable Source
SECRET_KEY Auto-generated by Render
DATABASE_URL Linked PostgreSQL service
DEBUG False
ALLOWED_HOSTS .onrender.com
SESSION_COOKIE_SECURE True
CSRF_COOKIE_SECURE True

Checklist

  • Project starts with docker-compose up
  • PostgreSQL database
  • Product catalog: filters, search, pagination
  • Product detail page: info, reviews, add-to-cart
  • Cart: manage items, calculate total, stock validation
  • Checkout: order creation, email notification, form validation
  • Account: registration, login, order history, profile editing
  • REST API: JWT auth, Swagger docs, permission scoping
  • Admin panel: analytics, filters, custom actions, role-based access
  • Swagger/OpenAPI docs accessible and functional
  • Type annotations and docstrings throughout
  • Linters (flake8/mypy) pass without critical errors
  • 36 tests β€” all passing
  • README is complete and clear
  • Deployment configured for Render

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages