How 64-hirobyte/django_ec works
Project Type and Purpose
• This is a monolithic, full-stack Django e-commerce application, containerized with Docker Compose.
• It provides user account management (accounts), product cataloging and administration (item_management, shop), shopping cart (cart), order processing (purchase), and promotional code capabilities (promotion).
File Structure Analysis
• Top-level Docker and deployment configs: Dockerfile, docker-compose.yml, Procfile, .env.
• Django project root under “config/”: ASGI/WGSI entrypoints, settings per environment (base, local, production), URL dispatcher, and shared templates.
• Six Django apps, each representing a business domain:
• accounts (authentication/authorization)
• item_management (CRUD for items)
• shop (public-facing product listing/detail)
• cart (shopping cart lifecycle)
• purchase (order creation, payment, mail, management commands)
• promotion (coupon generation, application)
• Shared static files (CSS/JS) and templates per app, organized under static/ and templates/.
• requirements.txt/runtime.txt define Python dependencies and runtime versions.
Key Insights from README
• Uses Postgres, configured via DATABASE_URL in .env.
• Docker Compose orchestrates two services: “web” (Django app) and “db” (Postgres).
• Exposes port 3000 for web; verifies setup via a simple /hello endpoint.
Main Components
a. External Clients
• Web Browser (or Mobile App)
b. Web Layer (Docker “web” service)
• Gunicorn/ASGI server
• Django project (config + six apps)
• Static file handler (e.g., WhiteNoise or Django staticfiles)
c. Data Layer
• PostgreSQL Database (Docker “db” service)
d. Environment & Deployment
• Docker Compose network
• Environment variables (.env)
• Procfile (Heroku compatibility)
Component Relationships and Data Flows
• Client → HTTP(S) → Gunicorn/ASGI → Django URL router (config/urls.py)
• URL router dispatches to app-specific views (accounts.views, shop.views, etc.)
• Views orchestrate business logic, call models via Django ORM → SQL queries → Postgres
• For order processing, views may invoke management commands (load_prefectures, promotion_code_generate) or send emails via Django’s email backend
• Static assets served directly by WhiteNoise or via a CDN in production
• Docker Compose bridges “web” and “db” on an internal network; web reads DATABASE_URL
Architectural Patterns and Principles
• MVC/MVT:
• Models layer under each app/models.py
• Views/controllers under views.py and forms.py
• Templates under templates/…
• Single codebase, well-encapsulated modular apps by domain
• Environment-specific configuration isolation (base/local/production)
• Stateless web containers, state persisted in Postgres
• Batch tasks via Django management commands
Technologies and Frameworks
• Python/Django (with apps for each bounded context)
• Gunicorn or Uvicorn ASGI server
• PostgreSQL
• Docker & Docker Compose
• WhiteNoise (static files) or external CDN in production
• HTML/CSS/JS for front-end delivered via Django templates