# itsnotgoodname/smtpbridge architecture

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

- Interactive diagram: https://gitdiagram.com/itsnotgoodname/smtpbridge
- Repository: https://github.com/itsnotgoodname/smtpbridge

## Overview

##### Main Components

a. Input Services Layer:
- SMTP Server (smtp/*)
- HTTP Server (web/http/*)
- IMAP Server (imap/*)

b. Core Processing Layer:
- Envelope Processing System (internal/envelope/*)
- Rule Engine (internal/rule/*)
- Message Queue System (internal/mailman/*)

c. Output Services Layer:
- Endpoint System (internal/endpoint/*)
- Multiple Senders (internal/senders/*)
- Telegram
- Shoutrrr
- Apprise
- Console
- Script

d. Storage Layer:
- Database (internal/database/*)
- File Storage (internal/file/*)

e. Supporting Systems:
- Authentication System (internal/auth/*)
- Retention Policy Manager (internal/retention/*)
- Trace/Logging System (internal/trace/*)
- Health Check System

**[Input Layer]**
- ↓
**[Core Layer]**
- ↓
**[Output Layer]**
- ↑
**[Storage Layer]**

##### Component Relationships

- Email → SMTP/HTTP Server → Envelope Processing
- Envelope Processing → Rule Engine → Message Queue
- Message Queue → Endpoint System → Various Senders
- All components ↔ Storage Layer
- All components → Trace System

##### Important Details

a. Configuration Elements:
- Config file locations
- Authentication points
- Health check endpoints

b. Key Processing Flows:
- Email reception flow
- Rule matching process
- Message delivery pipeline
- Retention policy execution

##### Technical Specifications to Note

- Supported protocols (SMTP, HTTP, IMAP)
- Authentication points
- Template processing points
- Where rules are evaluated

##### Implementation Notes

- The modular nature of the sender system
- The template-based message processing
- The rule-based routing system
- The retention policy mechanism

##### Special Attention Areas

- Separation between email reception and message delivery
- How the rule engine interfaces with both envelope processing and endpoint selection
- Queue-based nature of the mailman system
- Demonstrate how the retention policy affects both database and file storage

This system design should reflect the application's primary purpose of bridging email communications to various messaging services while maintaining a clear separation of concerns and robust processing pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef output fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:white

    subgraph InputLayer["Input Services Layer"]
        SMTP["SMTP Server"]:::input
        HTTP["HTTP Server"]:::input
        IMAP["IMAP Server"]:::input
    end

    subgraph CoreLayer["Core Processing Layer"]
        ENV["Envelope Processing"]:::core
        RULE["Rule Engine"]:::core
        QUEUE["Message Queue"]:::core
    end

    subgraph OutputLayer["Output Services Layer"]
        EP["Endpoint System"]:::output
        subgraph Senders["Sender Services"]
            TG["Telegram"]:::output
            SH["Shoutrrr"]:::output
            AP["Apprise"]:::output
            CON["Console"]:::output
            SCR["Script"]:::output
        end
    end

    subgraph StorageLayer["Storage Layer"]
        DB["Database"]:::storage
        FS["File Storage"]:::storage
    end

    subgraph SupportLayer["Supporting Systems"]
        AUTH["Authentication"]:::support
        RET["Retention Policy"]:::support
        TRACE["Trace/Logging"]:::support
        HEALTH["Health Check"]:::support
    end

    %% Connections
    SMTP & HTTP & IMAP --> ENV
    ENV --> RULE
    RULE --> QUEUE
    QUEUE --> EP
    EP --> TG & SH & AP & CON & SCR

    %% Storage connections
    ENV & RULE & QUEUE & EP -.-> DB
    ENV & RULE & QUEUE & EP -.-> FS

    %% Support system connections
    ENV & RULE & QUEUE & EP -.-> TRACE
    ENV & RULE & QUEUE & EP -.-> AUTH
    DB & FS -.-> RET

    %% Click events
    click SMTP "https://github.com/ItsNotGoodName/smtpbridge/blob/master/smtp/smtp.go"
    click HTTP "https://github.com/ItsNotGoodName/smtpbridge/blob/master/web/http/server.go"
    click IMAP "https://github.com/ItsNotGoodName/smtpbridge/blob/master/imap/server.go"
    click ENV "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/envelope/envelope.go"
    click RULE "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/rule/rule.go"
    click QUEUE "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/mailman/mailman.go"
    click EP "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/endpoint/endpoint.go"
    click TG "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/senders/telegram.go"
    click SH "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/senders/shoutrrr.go"
    click AP "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/senders/apprise.go"
    click CON "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/senders/console.go"
    click SCR "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/senders/script.go"
    click DB "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/database/database.go"
    click FS "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/file/file.go"
    click AUTH "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/auth/auth.go"
    click RET "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/retention/retention.go"
    click TRACE "https://github.com/ItsNotGoodName/smtpbridge/blob/master/internal/trace/trace.go"

    %% Legend
    subgraph Legend
        I["Input Services"]:::input
        C["Core Processing"]:::core
        O["Output Services"]:::output
        S["Storage"]:::storage
        SP["Support Systems"]:::support
    end
```
