# tijn/devmail architecture

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

- Interactive diagram: https://gitdiagram.com/tijn/devmail
- Repository: https://github.com/tijn/devmail

## Overview

##### Main Components

a) Core Server Components:
- SMTP Server (receives emails)
- POP3 Server (delivers emails)
- In-Memory Store (temporary email storage)

b) Supporting Components:
- Configuration System
- Logging System
- Session Management

**[Client Layer]**

**[Server Layer]**

**[Storage Layer]**

##### Specific Component Relationships

a) Client Layer:
- Developer Applications (SMTP clients)
- Email Clients (POP3 clients like Thunderbird)

b) Server Layer:
- SMTP Server (src/devmail/smtp_server.cr)
- POP Server (src/devmail/pop_server.cr)
- Generic Server Base (src/devmail/generic_server.cr)
- Session Management
- SMTP Sessions (src/devmail/smtp_session.cr)
- POP Sessions (src/devmail/pop_session.cr)

c) Storage Layer:
- In-Memory Store (src/devmail/store.cr)

##### Flow Representation

- Incoming mail flow: Client Apps → SMTP Server → Store
- Outgoing mail flow: Store → POP3 Server → Email Clients
- Session management flows
- Configuration and logging interactions

##### Additional Elements

Annotations for:
- Port numbers for SMTP and POP3
- Temporary nature of storage
- System startup methods (launchd/systemd)

##### Key Points to Emphasize

- The ephemeral nature of the storage (in-memory only)
- The development/testing purpose of the system
- The simple flow of emails (SMTP → Store → POP3)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef client fill:#e1f5fe,stroke:#01579b
    classDef server fill:#e8f5e9,stroke:#1b5e20
    classDef storage fill:#fff3e0,stroke:#e65100
    classDef support fill:#f5f5f5,stroke:#424242
    classDef session fill:#e8f5e9,stroke:#1b5e20,stroke-dasharray: 5 5

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        SMTPClient["SMTP Clients\n(Developer Apps)"]:::client
        POP3Client["POP3 Clients\n(Email Clients)"]:::client
    end

    %% Server Layer
    subgraph ServerLayer["Server Layer"]
        %% Core Servers
        GenServer["Generic Server Base"]:::server
        SMTPServer["SMTP Server\n(Port 2525)"]:::server
        POP3Server["POP3 Server\n(Port 1100)"]:::server
        
        %% Session Management
        SMTPSession["SMTP Session\nHandler"]:::session
        POPSession["POP3 Session\nHandler"]:::session
        BaseSession["Base Session\nManagement"]:::session
        
        %% Support Systems
        Config["Configuration\nSystem"]:::support
        Logger["Logging\nSystem"]:::support
        Startup["Startup Services\n(launchd/systemd)"]:::support
    end

    %% Storage Layer
    subgraph StorageLayer["Storage Layer"]
        Store["In-Memory Store\n(Temporary Storage)"]:::storage
    end

    %% Relationships
    SMTPClient --> SMTPServer
    POP3Server --> POP3Client
    
    GenServer --> SMTPServer
    GenServer --> POP3Server
    
    SMTPServer --> SMTPSession
    POP3Server --> POPSession
    
    BaseSession --> SMTPSession
    BaseSession --> POPSession
    
    SMTPSession --> Store
    Store --> POPSession
    
    Config --> ServerLayer
    Logger --> ServerLayer
    
    %% Click events for component mapping
    click SMTPServer "https://github.com/tijn/devmail/blob/main/src/devmail/smtp_server.cr"
    click POP3Server "https://github.com/tijn/devmail/blob/main/src/devmail/pop_server.cr"
    click Store "https://github.com/tijn/devmail/blob/main/src/devmail/store.cr"
    click GenServer "https://github.com/tijn/devmail/blob/main/src/devmail/generic_server.cr"
    click Config "https://github.com/tijn/devmail/blob/main/src/devmail/config.cr"
    click Logger "https://github.com/tijn/devmail/blob/main/src/devmail/log.cr"
    click BaseSession "https://github.com/tijn/devmail/blob/main/src/devmail/session.cr"
    click SMTPSession "https://github.com/tijn/devmail/blob/main/src/devmail/smtp_session.cr"
    click POPSession "https://github.com/tijn/devmail/blob/main/src/devmail/pop_session.cr"
    click Startup "https://github.com/tijn/devmail/blob/main/startup/launchd/local.devmail.plist"
    click Startup "https://github.com/tijn/devmail/blob/main/startup/systemd/devmail.service"

    %% Legend
    subgraph Legend
        Client["Client Component"]:::client
        ServerComp["Server Component"]:::server
        SessionComp["Session Component"]:::session
        StorageComp["Storage Component"]:::storage
        SupportComp["Support Component"]:::support
    end
```
