How khoaxuandang/python-django-ecommerce works
Project type and purpose
• This is a monolithic, full-stack Django e-commerce application.
• Purpose: allow users to browse products (by category), manage their cart, place orders, and handle user accounts (registration, login, password reset).
File structure
• Top-level Django project: greatkart/ (contains settings.py, urls.py, ASGI/WSGI entry points).
• Five domain apps under project root:
• accounts (user management)
• carts (shopping-cart logic)
• category (product categorization)
• orders (order processing, payments)
• store (product listing and detail)
• Shared resources:
• templates/ (HTML with Django template inheritance)
• static/ & greatkart/static/ (CSS, JS, fonts, images)
• Configuration files: manage.py, .gitignore
README for additional insights
• Confirms feature set: product browsing, cart, checkout, admin panel.
• Uses Django’s ORM, built-in admin, context processors, forms, and email for notifications.
Architectural pattern and layers
The project follows Django’s MTV (Model-Template-View) pattern within a layered architecture. We’ll further subdivide into six layers:
A. Presentation (UI) Layer
• Templates (templates/*.html)
• Static assets (CSS, JS, fonts, images in static/ and greatkart/static/)
B. Web Framework Layer
• URL Dispatcher (greatkart/urls.py + each app’s urls.py)
• Middleware & Context Processors (e.g., carts/context_processors.py, category/context_processors.py)
• Request/Response Handling (ASGI/WSGI entry points)
C. Application (Service) Layer
• Views (accounts/views.py, store/views.py, orders/views.py, etc.)
• Forms (accounts/forms.py, orders/forms.py, store/forms.py)
• Business Logic orchestrating models and external calls
D. Domain (Model) Layer
• Models (accounts/models.py, carts/models.py, etc.)
• Migrations (app/migrations/)
E. Data Access Layer
• Django ORM (database connection via settings.py)
• QuerySets, model managers
F. Infrastructure & External Services
• Database (PostgreSQL/MySQL/SQLite configured in settings.py)
• Static file storage (local filesystem or CDN)
• Email server (SMTP for password reset & order notifications)
• Optional: Payment gateway API (integrated via orders app)
Main components & interactions
1. Web Browser (client)
– Sends HTTP(S) requests
– Renders HTML/CSS/JS
2. Load Balancer / Web Server (optional in deployment)
– Routes to the Django application
3. Django Application
– URL Dispatcher → Middleware → Views
– Views invoke Forms & Models
– Models persist or fetch data via ORM
4. Database
– Stores user, product, cart, order, category data
5. Static File Server / CDN
– Serves CSS, JS, images, fonts
6. Email Service (SMTP)
– Sends verification, password reset, order emails
7. (Optional) Payment Gateway
– Processes payments during checkout