# kc-7/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/kc-7/ecommerce
- Repository: https://github.com/kc-7/ecommerce

## Overview

##### Overall Project Type and Purpose
- This is a full‑stack e‑commerce web application built with Django. It’s designed to offer custom printed products featuring AI‑generated art. It also includes an administrative portal (powered by Jazzmin), integrated payment processing (Stripe), external file storage (AWS S3), and a relational database (PostgreSQL via ElephantSQL on Heroku).
- The readme and file tree show that the application is divided carefully into multiple Django apps such as “about”, “avatar”, “bag”, “blog”, “checkout”, “products”, and “profiles”. This modular (MVC pattern) structure is key to the system’s internal architecture.

##### Main Components/Subsystems
- Client/Presentation Layer:
– Web Browser (user devices accessing the site). This layer is responsible for rendering HTML/CSS/JS that is generated by Django templates.
– Mobile and Desktop clients with responsive UI (since the README details extensive responsiveness testing).

- Web Application Server (Business Logic Layer):
– Django Project (“ecommerce”) deployed on Heroku. This central server routes HTTP requests via Django URL routing, then directs them to the appropriate views/controllers in each app.
– Multiple Django apps (about, avatar, bag, blog, checkout, products, profiles) each with their own models, views, templates, forms, and tests.
– An Admin Portal using Jazzmin for administrative functionality and custom management (e.g., product CRUD, blog and about page management, and custom avatar generation).

- Data Persistence Layer:
– A relational database (using PostgreSQL via ElephantSQL on production; support for sqlite in development). All models (users, orders, products, blog pages, avatar attributes, etc.) persist here.
– Data migrations and schema definitions are part of each app.

- External Services and Integrations:
– Payment Gateway: Stripe integration (with configuration for test and live modes, webhooks, and secure keys).
– File Storage and CDN: AWS S3 is used for static and media file storage. The Django-storages integration with boto3 handles upload/download.
– Authentication & Social Login: Django-allauth is set up for user registration, login, email verifications, etc.
– Cloudflare DNS and SSL: For custom domain support, HTTPS enforcement, and additional security.
– Deployment Tools: Git (with GitHub) for version control and Heroku as the hosting platform (including Procfile configuration).
– Other: Services like CKEditor for rich-text editing; various JavaScript and CSS frameworks (Bootstrap, custom styles) used in the front end.

##### Relationships and Interactions
- The browser makes secure HTTPS requests to Heroku’s hosted Django server.
- The Django server routes requests across its modular apps based on URL patterns. For example:
– Public users access product listings, blog pages, and profile pages.
– Administrative users access the Jazzmin‑enhanced admin portal where CRUD actions occur.
- The business logic interacts with the database to read/write models.
- Payment flows are managed via Stripe: checkout views prepare order data, redirect users or confirm transactions, and listen for webhook events (handled by Django views like webhook_handler.py).
- Static assets and media files are served from AWS S3 based on custom storage backends defined in settings.
- Additional integrations such as AWS S3, Cloudflare, and allauth are connected via well‑defined configuration (environment variables are set on Heroku, for example).

##### Architectural Patterns and Technologies
- The overall architecture follows the MVC (Model‑View‑Controller) pattern. Django’s projects and apps separate the business logic, presentation, and data layers.
- It is deployed as a monolithic application—one Django project with modular apps—while still using Micro‑service–like external integrations (Stripe, S3).
- Environment configuration and version control (via git) support agile development, as detailed extensively in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Web Client (Browser)"]:::client
    CF["Cloudflare (DNS/SSL)"]:::external
    Client -->|"HTTPS_request"| CF
    CF -->|"Routes"| Server["Django Web Server (ecommerce)"]:::internal
    Server -->|"DB_operations"| DB["Database (PostgreSQL/ElephantSQL)"]:::database
    DB -->|"Query_Response"| Server
    Server -->|"Payment_Calls"| Stripe["Stripe Payment Gateway"]:::external
    Server -->|"StaticMedia"| S3["AWS S3 Storage"]:::external
    Server -->|"Hosted_on"| Heroku["Heroku (Deployment)"]:::deployment

    subgraph "Django Core Apps"
        About["About App"]:::internal
        Avatar["Avatar App"]:::internal
        Bag["Bag App"]:::internal
        Blog["Blog App"]:::internal
        Checkout["Checkout App"]:::internal
        Products["Products App"]:::internal
        Profiles["Profiles App"]:::internal
        Home["Home App"]:::internal
        Admin["Admin Portal (Jazzmin)"]:::internal
    end

    Server --> About
    Server --> Avatar
    Server --> Bag
    Server --> Blog
    Server --> Checkout
    Server --> Products
    Server --> Profiles
    Server --> Home
    Server --> Admin

    subgraph "Avatar App Extras"
        AvatarGenerate["Avatar Generate"]:::internal
        AvatarProbability["Avatar Probability"]:::internal
    end
    Avatar --> AvatarGenerate
    Avatar --> AvatarProbability

    subgraph "Checkout App Extras"
        CheckoutWebhook["Checkout Webhook Handler"]:::internal
        StripeElements["Stripe Elements JS"]:::internal
    end
    Checkout --> CheckoutWebhook
    Checkout --> StripeElements

    subgraph "Deployment & Configuration"
        Manage["manage.py"]:::internal
        Procfile["Procfile"]:::deployment
        Settings["ecommerce/settings.py"]:::internal
        CustomStorages["custom_storages.py"]:::internal
        Allauth["templates/allauth"]:::internal
        Templates["templates"]:::internal
        Static["static"]:::internal
    end
    Manage --- Server
    Procfile --- Server
    Settings --- Server
    CustomStorages --- Server
    Allauth --- Server
    Templates --- Server
    Static --- Server

    %% Click Events
    click Server "https://github.com/kc-7/ecommerce/tree/main/ecommerce"
    click Manage "https://github.com/kc-7/ecommerce/blob/main/manage.py"
    click About "https://github.com/kc-7/ecommerce/tree/main/about"
    click Avatar "https://github.com/kc-7/ecommerce/tree/main/avatar"
    click AvatarGenerate "https://github.com/kc-7/ecommerce/blob/main/avatar/generate.py"
    click AvatarProbability "https://github.com/kc-7/ecommerce/blob/main/avatar/probability.py"
    click Bag "https://github.com/kc-7/ecommerce/tree/main/bag"
    click Blog "https://github.com/kc-7/ecommerce/tree/main/blog"
    click Checkout "https://github.com/kc-7/ecommerce/tree/main/checkout"
    click CheckoutWebhook "https://github.com/kc-7/ecommerce/blob/main/checkout/webhook_handler.py"
    click StripeElements "https://github.com/kc-7/ecommerce/blob/main/checkout/static/checkout/js/stripe_elements.js"
    click Products "https://github.com/kc-7/ecommerce/tree/main/products"
    click Profiles "https://github.com/kc-7/ecommerce/tree/main/profiles"
    click Home "https://github.com/kc-7/ecommerce/tree/main/home"
    click CustomStorages "https://github.com/kc-7/ecommerce/blob/main/custom_storages.py"
    click Allauth "https://github.com/kc-7/ecommerce/tree/main/templates/allauth"
    click Templates "https://github.com/kc-7/ecommerce/tree/main/templates"
    click Static "https://github.com/kc-7/ecommerce/tree/main/static"
    click Procfile "https://github.com/kc-7/ecommerce/tree/main/Procfile"
    click Settings "https://github.com/kc-7/ecommerce/blob/main/ecommerce/settings.py"

    %% Styles
    classDef client fill:#FEE188,stroke:#333,stroke-width:2px;
    classDef internal fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef deployment fill:#D7BDE2,stroke:#7D3C98,stroke-width:2px;
```
