# victor-sm/craft-mailer architecture

> Architecture diagram of the GitHub repository victor-sm/craft-mailer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/victor-sm/craft-mailer
- Repository: https://github.com/victor-sm/craft-mailer

## Overview

##### Main Components

a. Core Plugin Components:
- Controllers Layer (Mailer_FormController)
- Models Layer (Form, Export, Log, Recipients models)
- Services Layer (Mailer_MainService)
- Records Layer (Log records for persistence)
- Tasks Layer (MailerTask for batch processing)

b. External Systems:
- Craft CMS Core
- Email Server/Service
- Database (for logging)
- File System (for CSV exports)

##### Component Relationships

- User Interface → Controllers (HTTP requests)
- Controllers → Services (business logic flow)
- Services → Models (data handling)
- Services → Tasks (batch email processing)
- Models → Records (database persistence)
- Tasks → Email Server (email delivery)

##### Data Flow Indicators

Primary flows:
- Email Configuration Flow:
- UI → Controller → Service → Models
- Email Sending Flow:
- Service → Task → Email Server
- Logging Flow:
- Service → Log Model → Log Record → Database

##### Integration Points

Connections:
- Craft CMS Integration
- Email Service Integration
- User Group System Integration
- Template System Integration

##### The template processing system

This structure will provide a clear understanding of how the plugin integrates with Craft CMS while maintaining its own distinct functionality for email management and delivery.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Mailer Plugin"
        PluginCore["Plugin Core"]:::core
        
        subgraph "Controller Layer"
            FormController["Form Controller"]:::controller
        end
        
        subgraph "Service Layer"
            MainService["Main Service"]:::service
        end
        
        subgraph "Model Layer"
            FormModel["Form Model"]:::model
            ExportModel["Export Model"]:::model
            LogModel["Log Model"]:::model
            RecipModel["Recipients Model"]:::model
        end
        
        subgraph "Record Layer"
            LogRecord["Log Record"]:::record
        end
        
        subgraph "Task Layer"
            MailerTask["Mailer Task"]:::task
        end
        
        subgraph "Template System"
            Settings["Settings Interface"]:::template
            LogInterface["Logging Interface"]:::template
            MainInterface["Main Interface"]:::template
            TwigTemplates["Twig Templates"]:::template
        end
    end
    
    subgraph "External Systems"
        CraftCMS["Craft CMS Core"]:::external
        EmailServer["Email Server"]:::external
        DB[(Database)]:::storage
        FileSystem[("File System")]:::storage
    end
    
    UI["User Interface"]:::entry
    
    UI --> FormController
    FormController --> MainService
    MainService --> FormModel
    MainService --> ExportModel
    MainService --> LogModel
    MainService --> RecipModel
    MainService --> MailerTask
    LogModel --> LogRecord
    LogRecord --> DB
    ExportModel --> FileSystem
    MailerTask --> EmailServer
    TwigTemplates --> MainService
    
    %% Click Events
    click PluginCore "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/MailerPlugin.php"
    click FormController "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/controllers/Mailer_FormController.php"
    click MainService "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/services/Mailer_MainService.php"
    click FormModel "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/models/Mailer_FormModel.php"
    click ExportModel "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/models/Mailer_ExportModel.php"
    click LogModel "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/models/Mailer_LogModel.php"
    click RecipModel "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/models/Mailer_RecipientsModel.php"
    click LogRecord "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/records/Mailer_LogRecord.php"
    click MailerTask "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/tasks/MailerTask.php"
    click Settings "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/templates/_settings.html"
    click LogInterface "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/templates/_log.html"
    click MainInterface "https://github.com/victor-sm/Craft-Mailer/blob/master/mailer/templates/index.html"
    click TwigTemplates "https://github.com/victor-sm/Craft-Mailer/tree/master/mailer/templates"
    
    %% Styling
    classDef core fill:#a8dadc,stroke:#457b9d
    classDef controller fill:#e63946,stroke:#1d3557
    classDef service fill:#457b9d,stroke:#1d3557
    classDef model fill:#1d3557,stroke:#457b9d
    classDef record fill:#f1faee,stroke:#1d3557
    classDef task fill:#e76f51,stroke:#264653
    classDef template fill:#2a9d8f,stroke:#264653
    classDef external fill:#90be6d,stroke:#43aa8b
    classDef storage fill:#f4a261,stroke:#e76f51
    classDef entry fill:#ffba08,stroke:#e85d04
    
    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Controller"]:::controller
        L3["Service"]:::service
        L4["Model"]:::model
        L5["Record"]:::record
        L6["Task"]:::task
        L7["Template"]:::template
        L8["External System"]:::external
        L9[("Storage")]:::storage
        L10["Entry Point"]:::entry
    end
```
