# greenmail-mail-test/greenmail architecture

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

- Interactive diagram: https://gitdiagram.com/greenmail-mail-test/greenmail
- Repository: https://github.com/greenmail-mail-test/greenmail

## Overview

##### Main Components
a. Core Mail Server Components:
- SMTP Server (com.icegreen.greenmail.smtp)
- IMAP Server (com.icegreen.greenmail.imap)
- POP3 Server (com.icegreen.greenmail.pop3)
- In-Memory Store (com.icegreen.greenmail.store)
- User Management (com.icegreen.greenmail.user)

b. Integration Components:
- JUnit 4 Support (greenmail-junit4)
- JUnit 5 Support (greenmail-junit5)
- Spring Integration (greenmail-spring)
- Standalone Server (greenmail-standalone)
- Web Application (greenmail-webapp)

##### Component Relationships

a. Core Components:
- Protocol servers (SMTP, IMAP, POP3) connecting to the In-Memory Store
- User Management component connecting to all protocol servers
- Configuration component feeding into all servers

b. Integration Layers:
- How test frameworks (JUnit4, JUnit5, Spring) interact with the core components
- Standalone and webapp containers wrapping the core components

##### Key Architectural Elements

a. Protocol Layer:
- ┌─────────────────────────────────────────┐
- Protocol Servers             │
- ┬──────────┬──────────────────┤
- SMTP    │  IMAP    │     POP3         │
- Server  │  Server  │     Server       │
- ┴──────────┴──────────────────┘

b. Storage Layer:
- ┌─────────────────────────────────────────┐
- In-Memory Mail Store           │
- ┬─────────────────────┤
- Message Store  │    User Store       │
- ┴─────────────────────┘

c. Integration Layer:
- ┌─────────────────────────────────────────┐
- Integration Frameworks          │
- ┬──────────┬──────────────────┤
- JUnit4  │  JUnit5  │     Spring       │
- ┴──────────┴──────────────────┘

##### Additional Elements
- A configuration component showing how ServerSetup and GreenMailConfiguration feed into the system
- External interfaces for SMTP (port 25), IMAP (port 143), and POP3 (port 110)
- SSL/TLS variants of the protocols
- API endpoints for the standalone and webapp versions

- ┌─────────────────────┐
- ┬───────────┤
- ► │ Direct    │
- ►   │ Event     │
- ····►   │ Config    │
- ┴───────────┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef storage fill:#90EE90,stroke:#333,stroke-width:2px
    classDef integration fill:#FFB366,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6E6,stroke:#333,stroke-width:2px
    
    %% Configuration Layer
    subgraph ConfigLayer
        Config["Configuration"]:::config
    end
    click Config "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/configuration/GreenMailConfiguration.java"

    %% Protocol Servers Layer
    subgraph ProtocolServers
        SMTP["SMTP Server"]:::core
        IMAP["IMAP Server"]:::core
        POP3["POP3 Server"]:::core
        
        SMTPHandler["SMTP Handler"]:::core
        IMAPHandler["IMAP Handler"]:::core
        POP3Handler["POP3 Handler"]:::core
        
        SMTP --> SMTPHandler
        IMAP --> IMAPHandler
        POP3 --> POP3Handler
    end
    click SMTP "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/smtp/SmtpServer.java"
    click IMAP "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapServer.java"
    click POP3 "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/pop3/Pop3Server.java"
    click SMTPHandler "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/smtp/SmtpHandler.java"
    click IMAPHandler "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapHandler.java"
    click POP3Handler "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/pop3/Pop3Handler.java"

    %% Storage Layer
    subgraph StorageLayer
        Store["In-Memory Store"]:::storage
        UserMgmt["User Management"]:::storage
    end
    click Store "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/store/InMemoryStore.java"
    click UserMgmt "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/java/com/icegreen/greenmail/user/UserManager.java"

    %% Integration Layer
    subgraph IntegrationLayer
        JUnit4["JUnit 4 Support"]:::integration
        JUnit5["JUnit 5 Support"]:::integration
        Spring["Spring Integration"]:::integration
        Standalone["Standalone Server"]:::integration
        WebApp["Web Application"]:::integration
    end
    click JUnit4 "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-junit4/src/main/java/com/icegreen/greenmail/junit4/GreenMailRule.java"
    click JUnit5 "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-junit5/src/main/java/com/icegreen/greenmail/junit5/GreenMailExtension.java"
    click Spring "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-spring/src/main/java/com/icegreen/greenmail/spring/GreenMailBean.java"
    click Standalone "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-standalone/src/main/java/com/icegreen/greenmail/standalone/GreenMailStandaloneRunner.java"
    click WebApp "https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-webapp/src/main/java/com/icegreen/greenmail/webapp/GreenMailListener.java"

    %% Relationships
    Config --> SMTP
    Config --> IMAP
    Config --> POP3
    
    SMTPHandler --> Store
    IMAPHandler --> Store
    POP3Handler --> Store
    
    UserMgmt --> SMTPHandler
    UserMgmt --> IMAPHandler
    UserMgmt --> POP3Handler
    
    JUnit4 --> SMTP
    JUnit4 --> IMAP
    JUnit4 --> POP3
    
    JUnit5 --> SMTP
    JUnit5 --> IMAP
    JUnit5 --> POP3
    
    Spring --> SMTP
    Spring --> IMAP
    Spring --> POP3
    
    Standalone --> SMTP
    Standalone --> IMAP
    Standalone --> POP3
    
    WebApp --> SMTP
    WebApp --> IMAP
    WebApp --> POP3

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Storage Components"]:::storage
        L3["Integration Components"]:::integration
        L4["Configuration"]:::config
    end
```
