# mailpace/mailpace-rails architecture

> Architecture diagram of the GitHub repository mailpace/mailpace-rails, 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/mailpace/mailpace-rails
- Repository: https://github.com/mailpace/mailpace-rails

## Overview

##### Project Type Analysis
This is a Rails gem that serves as an integration layer between Rails applications and MailPace's email service, providing both outbound email delivery through ActionMailer and inbound email processing through ActionMailbox.

##### Main Components

A. Core Components:
- Rails Application (Host Application)
- MailPace Rails Gem
- MailPace API Service
- ActionMailer Integration
- ActionMailbox Integration

B. Key Flows:
- Outbound Email Flow
- Inbound Email Flow
- Authentication Flow

**[Component Representation Guide]**
- Rectangles: Main systems/applications
- Rounded Rectangles: Internal gem components

**[Rails Application] ←→ [MailPace Rails Gem] ←→ [MailPace API Service]**

**Rails Application**
- ActionMailer
- ActionMailbox

**MailPace Rails Gem**
- Delivery Method
- Ingress Controller
- Configuration Module

**MailPace API Service**
- Email Sending API
- Inbound Webhook Handler

##### Key Flows to Highlight

Outbound Email Flow:
**ActionMailer → Delivery Method → MailPace API → Email Recipient**

Inbound Email Flow:
**Email Sender → MailPace → Webhook → ActionMailbox Ingress → Rails Application**

##### Important Details

Authentication Elements:
- API Token configuration
- Ingress authentication for webhooks
- Idempotency key handling

Feature Indicators:
- Email tagging support
- -unsubscribe functionality
- Idempotent request handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Rails["Rails Application"]
        AM[ActionMailer]
        AMB[ActionMailbox]
        BaseMailbox["Base Mailbox"]
    end

    subgraph MPG["MailPace Rails Gem"]
        Core["Core Implementation"]
        Engine["Gem Engine"]
        DM["Delivery Method"]
        IC["Ingress Controller"]
        Config["Configuration Module"]
        Version["Version Manager"]
    end

    subgraph MPS["MailPace API Service"]
        API["Email Sending API"]
        WH["Webhook Handler"]
    end

    subgraph Testing["Testing Infrastructure"]
        MT["Mailer Tests"]
        IT["Ingress Tests"]
        EH["Email Helpers"]
        direction TB
        subgraph ExampleMailers["Example Mailers"]
            BM["Basic Mailer"]
            CM["Complex Mailer"]
            IM["Idempotent Mailer"]
            LM["List Unsubscribe Mailer"]
            TM["Tagged Mailer"]
        end
    end

    AM --> DM
    DM --> API
    WH --> IC
    IC --> AMB
    Config --> Core
    Engine --> Core
    Version --> Core

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef rails fill:#b8d4ff,stroke:#333
    classDef mailpace fill:#90EE90,stroke:#333
    classDef external fill:#FFB366,stroke:#333
    classDef testing fill:#E6E6E6,stroke:#333

    class AM,AMB,BaseMailbox rails
    class Core,Engine,DM,IC,Config,Version mailpace
    class API,WH external
    class MT,IT,EH,ExampleMailers,BM,CM,IM,LM,TM testing

    click Core "https://github.com/mailpace/mailpace-rails/blob/master/lib/mailpace-rails.rb"
    click Engine "https://github.com/mailpace/mailpace-rails/blob/master/lib/mailpace-rails/engine.rb"
    click IC "https://github.com/mailpace/mailpace-rails/blob/master/app/controllers/action_mailbox/ingresses/mailpace/inbound_emails_controller.rb"
    click MT "https://github.com/mailpace/mailpace-rails/blob/master/test/mailpace/mailer_test.rb"
    click IT "https://github.com/mailpace/mailpace-rails/blob/master/test/mailpace/ingress_test.rb"
    click EH "https://github.com/mailpace/mailpace-rails/blob/master/test/mailpace/email_helper.rb"
    click BM "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailers/test_mailer.rb"
    click CM "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailers/complex_mailer.rb"
    click IM "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailers/idempotent_mailer.rb"
    click LM "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailers/list_unsubscribe_mailer.rb"
    click TM "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailers/tag_mailer.rb"
    click Version "https://github.com/mailpace/mailpace-rails/blob/master/lib/mailpace-rails/version.rb"
    click BaseMailbox "https://github.com/mailpace/mailpace-rails/blob/master/test/dummy/app/mailboxes/application_mailbox.rb"
```
