# amazingcoderpro/email-distribution-management-system architecture

> Architecture diagram of the GitHub repository amazingcoderpro/email-distribution-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amazingcoderpro/email-distribution-management-system
- Repository: https://github.com/amazingcoderpro/email-distribution-management-system

## Overview

##### Project type and purpose
- This is a full-stack Email-Direct-Marketing (EDM) system built on Django.
- It exposes a REST API for a separate JS frontend (dist), integrates with Shopify (OAuth + Webhooks), Google Analytics, and an EMS (email sending) service, and runs scheduled data-processing/email tasks.

##### File structure
- Top-level:
- manage.py, run_task.py – entry points for web and batch processes
- config.py – centralizes settings
- Pipfile/Pipfile.lock – Python deps via Pipenv
- “edm/”: Django project (urls.py, wsgi.py)
- “app/”: Core Django app (models, views, serializers, filters, middleware, migrations)
- “sdk/”: External-service clients:
– sdk/shopify – OAuth, Webhook handling, data fetch
– sdk/googleanalytics – OAuth + reporting API
– sdk/ems – send email via EMS API
- “task/”: Batch jobs invoked by run_task.py (customer-group processing, data migration, recommendations, statistics, email template dispatch)
- “bin/”: Deployment scripts & configs for Gunicorn & Supervisor

##### README for deployment & architecture hints
- MySQL database initialization via raw SQL inserts
- Nginx serves static frontend (dist/) and proxies “/api” to Gunicorn:8000
- Supervisor manages two processes: Gunicorn (web) and run_task.py (workers)

a. Main components:
- Client Browser (JS frontend)
- Nginx (static file server + reverse proxy)
- Supervisor → Gunicorn (Django WSGI)
- Django Application
– URL Router (edm/urls.py + app/urls.py)
– API Views (app/views)
– Serializers (app/serializers)
– Business Filters/Services (app/filters, app/utils)
– ORM Models & Migrations (app/models, app/migrations)
- MySQL Database
- Supervisor → run_task.py (Batch Worker)
– task modules (task/*.py)
- External Services (Shopify, Google Analytics, EMS)

b. Relationships & data flows:
- Browser ↔ Nginx:
– GET “/” → static HTML/CSS/JS
– GET/POST “/api/*” → proxied → Gunicorn:8000
- Nginx → Gunicorn → Django: WSGI calls → Views → Serializers → Models → MySQL
- Django ↔ External SDKs: HTTP calls for OAuth flows, data fetch, webhook handling
- Scheduler (Supervisor) launches run_task.py on cron or interval → Task modules → read/write DB & call External APIs asynchronously

c. Architectural patterns & principles:
- Monolithic MVC (Django) with clear layers (views, serializers, filters, models)
- Reverse-proxy pattern (Nginx) separating static vs dynamic content
- Asynchronous processing via separate worker processes
- Dependency injection via sdk/ modules

d. Key technologies/frameworks:
- Python 3 + Django, Pipenv
- Gunicorn + Supervisor (bin/gunicorn.py, supervisord.conf)
- Nginx
- MySQL
- JavaScript frontend (built into dist/)
- External APIs: Shopify, Google Analytics, EMS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Browser\n(JS Frontend)"]:::client

    %% Infrastructure
    subgraph "Infrastructure"
        Nginx["Nginx\n(80: Static + Reverse Proxy)"]:::infra
        Supervisor["Supervisor"]:::infra
        Gunicorn["Gunicorn\n(WSGI Server)"]:::infra
    end

    %% Django Application
    subgraph "Django Application" 
        manage["manage.py"]:::app
        config["config.py"]:::app

        subgraph "Entry & Routing"
            URLs["edm/urls.py"]:::app
            WSGI["edm/wsgi.py"]:::app
        end

        subgraph "Core App (MVC)"
            Router["app/urls.py"]:::app
            Views["app/views/*.py"]:::app
            Serializers["app/serializers/*.py"]:::app
            Filters["app/filters/*.py"]:::app
            Models["app/models.py"]:::app
            Migrations["app/migrations/"]:::app
            Middleware["app/middleware.py"]:::app
            Utils["app/utils/*.py"]:::app
        end
    end

    %% Data Store
    MySQL[(MySQL Database)]:::db

    %% SDKs
    subgraph "External SDKs"
        Shopify["sdk/shopify/"]:::ext
        GA["sdk/googleanalytics/"]:::ext
        EMS["sdk/ems/ems_api.py"]:::ext
    end

    %% Batch Processing
    subgraph "Batch Processing"
        runTask["run_task.py"]:::app
        subgraph "Task Modules"
            CG["task/customer_group_processor.py"]:::app
            DM["task/data_migrate.py"]:::app
            SDP["task/shopify_data_processor.py"]:::app
            EDP["task/ems_data_processor.py"]:::app
            PR["task/product_recommendation.py"]:::app
            SS["task/store_statistics.py"]:::app
            ET["task/template_task_processor.py"]:::app
            DBU["task/db_util.py"]:::app
        end
    end

    %% Real-time Pipeline
    Browser -->|"GET /, /api/*"| Nginx
    Nginx -->|"Proxy to 8000"| Gunicorn
    Gunicorn -->|"WSGI Call"| WSGI
    WSGI -->|"Route URL"| URLs
    URLs -->|"app routing"| Router
    Router -->|"invoke endpoint"| Views
    Views -->|"serialize"| Serializers
    Serializers -->|"filter/validate"| Filters
    Filters -->|"ORM operations"| Models
    Models -->|"run migrations"| Migrations
    Models -->|"DB Query"| MySQL

    Views -->|"OAuth/Webhook"| Shopify
    Views -->|"OAuth/API"| GA
    Views -->|"Send Email"| EMS

    %% Batch Pipeline
    Supervisor -->|"launch web"| Gunicorn
    Supervisor -->|"schedule job"| runTask
    runTask -->|"execute"| CG & DM & SDP & EDP & PR & SS & ET & DBU
    CG & DM & SDP & EDP & PR & SS & ET & DBU -->|"DB Query"| MySQL
    CG & DM & SDP & EDP & PR & SS & ET & DBU -->|"async HTTP"| Shopify & GA & EMS

    %% Click Events
    click manage "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/manage.py"
    click config "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/config.py"
    click URLs "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/edm/urls.py"
    click WSGI "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/edm/wsgi.py"
    click Router "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/app/urls.py"
    click Views "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/app/views"
    click Serializers "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/app/serializers"
    click Filters "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/app/filters"
    click Models "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/app/models.py"
    click Migrations "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/app/migrations/"
    click Middleware "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/app/middleware.py"
    click Utils "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/app/utils"
    click Shopify "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/sdk/shopify/"
    click GA "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/sdk/googleanalytics/"
    click EMS "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/sdk/ems/ems_api.py"
    click runTask "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/run_task.py"
    click CG "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/customer_group_processor.py"
    click DM "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/data_migrate.py"
    click SDP "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/shopify_data_processor.py"
    click EDP "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/ems_data_processor.py"
    click PR "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/product_recommendation.py"
    click SS "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/store_statistics.py"
    click ET "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/template_task_processor.py"
    click DBU "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/task/db_util.py"
    click Gunicorn "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/bin/gunicorn.py"
    click Supervisor "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/bin/supervisord"
    click MySQL "https://github.com/amazingcoderpro/email-distribution-management-system/tree/master/Pipfile"
    click MySQL "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/Pipfile.lock"
    click MySQL "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/README.md"
    click MySQL "https://github.com/amazingcoderpro/email-distribution-management-system/blob/master/.gitignore"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef infra fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef app fill:#E3F2FD,stroke:#1565C0,color:#1565C0;
    classDef db fill:#F5F5F5,stroke:#9E9E9E,color:#424242;
    classDef ext fill:#FFF3E0,stroke:#EF6C00,color:#E65100;
```
