# pimalaya/himalaya architecture

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

- Interactive diagram: https://gitdiagram.com/pimalaya/himalaya
- Repository: https://github.com/pimalaya/himalaya

## Overview

##### High-Level Architecture Overview

The system should be represented as a layered architecture with the following main components:

**┌─────────────────────────────────────────────┐**
- CLI Interface                 │
- ┤
- Command Layer                  │
- ┤
- Backend Adapters               │
- ┬──────────────┬──────────────┤
- IMAP     │    SMTP      │   Others     │
- ┴──────────────┴──────────────┘

##### Core Components

a) CLI Interface (Top Layer):
- Main entry point (src/main.rs)
- CLI parser (src/cli.rs)
- Configuration handler (src/config.rs)

b) Command Layer (Middle Layer):
- Account management (src/account/*)
- Email operations (src/email/*)
- Folder operations (src/folder/*)
- Completion support (src/completion/*)
- Manual pages (src/manual/*)

c) Backend Adapters (Bottom Layer):
- IMAP backend
- SMTP backend
- Maildir backend
- Notmuch backend
- Sendmail backend

##### Data Flow and Interactions

**User Input → CLI Interface → Command Layer → Backend Adapters → Email Servers**

##### Authentication Components

- Password-based auth
- OAuth 2.0 support
- Keyring integration
- PGP encryption options

##### Feature Modules

- IMAP support
- SMTP support
- Maildir support
- Notmuch support
- PGP encryption modules
- OAuth2 support
- Keyring integration

##### Message Handling Flow

Email message lifecycle:
**Composition → Template Processing → Backend Selection → Sending/Receiving**

##### Configuration Management

Configuration sources:
- TOML config files
- System keyring
- Environment variables
- Command-line arguments

##### Implementation Details

Use notes or callouts to highlight:
- Rust-based implementation
- Cargo feature flags
- External dependencies
- Backend abstractions

- Clear separation of concerns between CLI, business logic, and backend implementations
- Pluggable backend architecture
- Security features and authentication flows
- Configuration flexibility
- Command structure hierarchy

- Core components: Solid blue
- Security components: Green
- External interfaces: Orange
- Configuration: Purple

This system design should help developers understand both the high-level architecture and the detailed component interactions while maintaining a clear view of the optional features and security considerations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI
        Main["Main Entry Point"]
        CLIParser["CLI Parser"]
        Config["Configuration Handler"]
    end

    subgraph Commands
        Account["Account Management"]
        Email["Email Operations"]
        Folder["Folder Operations"]
        Completion["Completion Support"]
        Manual["Manual Pages"]
    end

    subgraph MessageHandling
        MsgOps["Message Operations"]
        Template["Template Processing"]
        MsgCmd["Message Commands"]
        Attach["Attachment Handling"]
    end

    subgraph EmailEnvelope
        EnvMgmt["Envelope Management"]
        FlagMgmt["Flag Management"]
    end

    subgraph FolderMgmt
        FolderCmd["Folder Commands"]
        FolderArg["Folder Arguments"]
    end

    subgraph AccountMgmt
        AcctCmd["Account Commands"]
        AcctConfig["Account Configuration"]
    end

    subgraph Backends
        IMAP["IMAP Backend"]:::optional
        SMTP["SMTP Backend"]:::optional
        Maildir["Maildir Backend"]:::optional
        Notmuch["Notmuch Backend"]:::optional
        Sendmail["Sendmail Backend"]:::optional
    end

    subgraph Auth
        Password["Password Auth"]:::security
        OAuth["OAuth 2.0"]:::security
        Keyring["Keyring"]:::security
        PGP["PGP Encryption"]:::security
    end

    Main --> CLIParser
    CLIParser --> Config
    CLIParser --> Commands
    Commands --> Account
    Commands --> Email
    Commands --> Folder
    Commands --> Completion
    Commands --> Manual

    Email --> MessageHandling
    Email --> EmailEnvelope
    Folder --> FolderMgmt
    Account --> AccountMgmt

    MessageHandling --> Backends
    EmailEnvelope --> Backends
    FolderMgmt --> Backends
    AccountMgmt --> Auth
    Auth --> Backends

    classDef default fill:#2374ab
    classDef optional fill:#d3d3d3,stroke-dasharray: 5 5
    classDef security fill:#4CAF50
    
    %% Click events for file mapping
    click Main "https://github.com/pimalaya/himalaya/blob/master/src/main.rs"
    click CLIParser "https://github.com/pimalaya/himalaya/blob/master/src/cli.rs"
    click Config "https://github.com/pimalaya/himalaya/blob/master/src/config.rs"
    click Account "https://github.com/pimalaya/himalaya/tree/master/src/account/"
    click Email "https://github.com/pimalaya/himalaya/tree/master/src/email/"
    click Folder "https://github.com/pimalaya/himalaya/tree/master/src/folder/"
    click Completion "https://github.com/pimalaya/himalaya/tree/master/src/completion/"
    click Manual "https://github.com/pimalaya/himalaya/tree/master/src/manual/"
    click MsgOps "https://github.com/pimalaya/himalaya/tree/master/src/email/message/"
    click Template "https://github.com/pimalaya/himalaya/tree/master/src/email/message/template/"
    click MsgCmd "https://github.com/pimalaya/himalaya/tree/master/src/email/message/command/"
    click Attach "https://github.com/pimalaya/himalaya/tree/master/src/email/message/attachment/"
    click EnvMgmt "https://github.com/pimalaya/himalaya/tree/master/src/email/envelope/"
    click FlagMgmt "https://github.com/pimalaya/himalaya/tree/master/src/email/envelope/flag/"
    click FolderCmd "https://github.com/pimalaya/himalaya/tree/master/src/folder/command/"
    click FolderArg "https://github.com/pimalaya/himalaya/tree/master/src/folder/arg/"
    click AcctCmd "https://github.com/pimalaya/himalaya/tree/master/src/account/command/"
    click AcctConfig "https://github.com/pimalaya/himalaya/blob/master/src/account/config.rs"
```
