# earthcomfy/django-ecommerce-api architecture

> Architecture diagram of the GitHub repository earthcomfy/django-ecommerce-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/earthcomfy/django-ecommerce-api
- Repository: https://github.com/earthcomfy/django-ecommerce-api

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/Consumer"):::client
    Nginx("Nginx Reverse Proxy"):::nginx
    Client -->|"HTTP_Request"| Nginx

    subgraph "Django Web Application"
        DjangoAPI("Core API"):::api
        subgraph "Apps"
            Orders("Orders App"):::app
            Payment("Payment App"):::app
            Products("Products App"):::app
            Users("Users App"):::app
        end
    end

    Nginx -->|"Routes_Request"| DjangoAPI
    DjangoAPI -->|"Handles_Orders"| Orders
    DjangoAPI -->|"Handles_Payment"| Payment
    DjangoAPI -->|"Handles_Products"| Products
    DjangoAPI -->|"Handles_Users"| Users

    DjangoAPI -->|"DB_Operations"| Postgres("PostgreSQL Database"):::db
    DjangoAPI -->|"Queues_Task"| Celery("Celery Workers"):::celery
    Celery -->|"Uses_Broker"| Redis("Redis"):::db
    Payment -->|"Processes_Payment"| Stripe("Stripe Payment Service"):::external

    subgraph "Deployment Configurations"
        Dockerfile("Dockerfile"):::deployment
        dockerCompose("docker-compose.yml"):::deployment
        dockerComposeProd("docker-compose.prod.yml"):::deployment
        envExample(".env.example"):::deployment
    end

    %% Click Events
    click DjangoAPI "https://github.com/earthcomfy/django-ecommerce-api/blob/master/manage.py"
    click DjangoAPI "https://github.com/earthcomfy/django-ecommerce-api/tree/master/config/"
    click Orders "https://github.com/earthcomfy/django-ecommerce-api/tree/master/orders/"
    click Payment "https://github.com/earthcomfy/django-ecommerce-api/tree/master/payment/"
    click Products "https://github.com/earthcomfy/django-ecommerce-api/tree/master/products/"
    click Users "https://github.com/earthcomfy/django-ecommerce-api/tree/master/users/"
    click Celery "https://github.com/earthcomfy/django-ecommerce-api/blob/master/config/celery.py"
    click Celery "https://github.com/earthcomfy/django-ecommerce-api/blob/master/payment/tasks.py"
    click Nginx "https://github.com/earthcomfy/django-ecommerce-api/tree/master/nginx/"
    click Dockerfile "https://github.com/earthcomfy/django-ecommerce-api/tree/master/Dockerfile"
    click dockerCompose "https://github.com/earthcomfy/django-ecommerce-api/blob/master/docker-compose.yml"
    click dockerComposeProd "https://github.com/earthcomfy/django-ecommerce-api/blob/master/docker-compose.prod.yml"
    click envExample "https://github.com/earthcomfy/django-ecommerce-api/blob/master/.env.example"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef nginx fill:#F4D03F,stroke:#B7950B,stroke-width:2px;
    classDef api fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef app fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef db fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef external fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef deployment fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef celery fill:#FADBD8,stroke:#943126,stroke-width:2px;
```
