How earthcomfy/django-ecommerce-api works
Project Type & Purpose
• The project is a full-stack backend API built with Django Rest Framework for e-commerce functionalities.
• It handles user registration (via email and phone), ordering, product management, payments (integrated with Stripe), and other ecommerce operations.
• It uses Docker for containerized development/production, with support for asynchronous tasks (Celery + Redis) and a reverse proxy (Nginx).
Analyzing the File Structure
• Top-Level Configuration Files: Notice files like Dockerfile, docker-compose.yml (and a production variant), .env.example, and pre-commit configs. These indicate containerized, production-ready deployments.
• Config Directory: Contains settings split between base, development, and production alongside ASGI/WGSI configurations and a Celery setup. This centralizes project configuration.
• Individual Django Apps:
• orders, payment, products, and users apps each maintain their own models, views, serializers, permissions, and migrations, reflecting a modular design.
• The users app even includes custom authentication backends, meaning authentication logic may be multifaceted.
• Nginx Directory: Contains the Dockerfile and nginx.conf for setting up a reverse proxy to route incoming web traffic.
• Additional Files: manage.py and other standard Django files for command handling.
a. Main Components to Include:
• Client/Consumer: External clients (e.g., browsers, mobile apps) interacting via API endpoints.
• Nginx: Acting as the reverse proxy/load balancer sitting in front of the Django application.
• Django Web Application: Represent the core application with the following subdivisions:
• API Endpoints (set up via Django Rest Framework)
• Modular apps: orders, payment, products, users.
• Common project configuration (config folder with settings, ASGI, WSGI, Celery integration)
• Database: PostgreSQL used as the primary relational database.
• Celery & Redis: For background tasks (e.g., asynchronous payment processing or order handling) – Celery workers communicate via Redis as a broker.
• External Payment Service (Stripe): Highlight the integration with Stripe for handling payments.
b. Relationships & Interactions:
• Client requests flow through Nginx and are routed to the Django Web Application.
• Django API layers process HTTP requests, interact with PostgreSQL for CRUD operations, and trigger asynchronous tasks via Celery.
• Celery workers process background tasks, leveraging Redis for message brokering.
• When processing payments, the Django application communicates with Stripe.
• Each Django app (orders, payment, products, users) contributes specialized endpoints and domain logic, interacting with the common database.
c. Architectural Patterns & Design Principles:
• Separation of Concerns: Clear modularization of different ecommerce domains (orders, users, etc.).
• Containerization: Docker and docker-compose define different containers for the web service, Nginx, Celery worker, and potentially the database.
• Asynchronous Processing: Use of Celery and Redis.
• API-First Design: Built on Django Rest Framework lends itself to a service-oriented architecture.
d. Relevant Technologies:
• Django & Django Rest Framework – Foundation for the API.
• PostgreSQL – Data persistence.
• Celery & Redis – Task processing mechanism.
• Nginx – Reverse proxy.
• Docker – Containerization.
• Stripe – External payment integration.
• DRF Spectacular – For API documentation.