# john-6670/e-commerce-api architecture

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

- Interactive diagram: https://gitdiagram.com/john-6670/e-commerce-api
- Repository: https://github.com/john-6670/e-commerce-api

## Overview

##### Project Type and Purpose
- This is a monolithic Django‑based Web API for an e‑commerce platform (no bundled frontend, only backend/API).
- Purpose: expose REST endpoints for user authentication (with JWT), product management, order processing, email verification and password‑reset flows, plus an admin UI and interactive API docs.

##### File Structure
- Top‑level files:
- manage.py – Django’s CLI entry point
- config/ – project settings (settings.py), URL routing (urls.py), ASGI/WSGI servers
- requirements.txt – pinned dependencies
- Apps (each under its own folder):
- accounts/ – custom user model, authentication, email verification, JWT, permissions, serializers, views, URLs
- products/ – models, serializers, views, URL routing, product‑related utilities
- orders/ – order models, serializers, views, URL routing, signal handlers (automatic cart creation)
- Configured for PostgreSQL, JWT auth, Swagger/ReDoc, console email backend (development).

##### README for Architectural Insights
- Key stacks: Django, Django REST Framework (DRF), PostgreSQL, JWT, Swagger/ReDoc, console or SMTP email backend.
- Flows described: register→verify→login, forgot‑password→reset.
- No explicit microservices—this is a single Django monolith with distinct “apps.”

##### Core Components and Relationships
a. External Clients
- Web or mobile frontend (not in repo)
- Admin user via Django Admin UI
- Swagger/ReDoc UI (auto‑generated docs)
b. API Layer (Django + DRF)
- URL dispatcher (config/urls.py) routes to app views
- Authentication middleware (JWT) sits on every request
c. Business Logic Apps
- Accounts app (registration, login, email, permissions)
- Products app (CRUD, stock, reviews)
- Orders app (cart management, order status)
d. Database
- PostgreSQL storing users, products, orders, migrations under each app
e. External Services
- SMTP (or console) Email Backend for verification & password resets

##### Architectural Patterns & Design Principles
- Monolithic, modularized by Django “apps” (logical separation of concerns).
- DRF serializers & viewsets isolate API contract from models.
- Signal handlers (orders/signals.py) implement event‑driven logic (cart creation).
- Custom permissions (accounts/permissions.py) enforce RBAC.
- Environment‑based configuration (config/settings.py + .env).

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Clients Layer
  subgraph "Clients" 
    direction TB
    WebClient["Web/Mobile Client"]:::external
    AdminUI["Django Admin UI"]:::external
    SwaggerUI["Swagger/ReDoc UI"]:::external
  end

  %% API Gateway & Middleware Layer
  subgraph "API Gateway & Middleware"
    direction TB
    CLI["manage.py"]:::middleware
    ASGI["ASGI Server"]:::middleware
    WSGI["WSGI Server"]:::middleware
    Router["URL Router"]:::middleware
    Auth["JWT Authentication Middleware"]:::middleware
  end

  %% Application Modules Layer
  subgraph "Application Modules"
    direction TB
    Accounts["Accounts App"]:::app
    Products["Products App"]:::app
    Orders["Orders App"]:::app
    Shared["Shared Utils & Serializers"]:::app
  end

  %% Data & External Integrations Layer
  subgraph "Data & External"
    direction TB
    DB["PostgreSQL Database"]:::database
    Email["Email Service (SMTP/Console)"]:::external
  end

  %% Connections: Clients to API
  WebClient -->|"HTTP Requests"| CLI
  AdminUI -->|"HTTP Requests"| CLI
  SwaggerUI -->|"HTTP Requests"| CLI

  %% manage.py launches servers
  CLI --> ASGI
  CLI --> WSGI
  ASGI --> Router
  WSGI --> Router

  %% Routing and auth
  Router --> Auth
  Auth --> Accounts
  Auth --> Products
  Auth --> Orders

  %% App interactions
  Accounts --> Shared
  Products --> Shared
  Orders --> Shared

  %% App to database
  Accounts --> DB
  Products --> DB
  Orders --> DB

  %% Orders signals
  Orders -.->|"signals (async)"| Orders

  %% Email flows
  Accounts -.->|"email verify/reset"| Email
  Email -->|"delivery"| WebClient

  %% Admin UI to apps & DB
  AdminUI --> Accounts
  AdminUI --> Products
  AdminUI --> Orders
  AdminUI --> DB

  %% Swagger UI hook
  Router --> SwaggerUI

  %% Requirement file
  Requirements["requirements.txt"]:::external
  CLI --> Requirements

  %% Click events
  click CLI "https://github.com/john-6670/e-commerce-api/blob/master//manage.py"
  click ASGI "https://github.com/john-6670/e-commerce-api/blob/master//config/asgi.py"
  click WSGI "https://github.com/john-6670/e-commerce-api/blob/master//config/wsgi.py"
  click Router "https://github.com/john-6670/e-commerce-api/blob/master//config/urls.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/apps.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/models.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/managers.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/permissions.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/utils.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/serializers.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/views.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/urls.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/admin.py"
  click Accounts "https://github.com/john-6670/e-commerce-api/blob/master//accounts/tests.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/apps.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/models.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/serializers.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/views.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/urls.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/utils.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/admin.py"
  click Products "https://github.com/john-6670/e-commerce-api/blob/master//products/tests.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/apps.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/models.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/signals.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/serializers.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/views.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/urls.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/admin.py"
  click Orders "https://github.com/john-6670/e-commerce-api/blob/master//orders/tests.py"
  click Requirements "https://github.com/john-6670/e-commerce-api/blob/master//requirements.txt"

  %% Class Definitions
  classDef external fill:#ADD8E6,stroke:#000,color:#000;
  classDef middleware fill:#FFA500,stroke:#000,color:#000;
  classDef app fill:#90EE90,stroke:#000,color:#000;
  classDef database fill:#D3D3D3,stroke:#000,color:#000;
```
