# endorama/2ami architecture

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

## Overview

##### Project Type Analysis
This is a security-focused CLI application written in Go that manages Two-Factor Authentication (2FA) secrets. The primary purpose is to securely store and retrieve 2FA secrets using the system keyring.

##### Main Components

a. Core Components:
- CLI Interface (main.go)
- Secret Management System (secret-string.go)
- Keyring Integration (keyring.go)
- Backup System (backup.go)
- Storage Handler (storage.go)
- Formatting Layer (formatter.go)

b. External Dependencies:
- System Keyring
- OTP Generation System

**┌─ User Interface Layer ─────────────────┐**
- CLI Interface             │
- ┬───────────────────┘
- ↓
**┌─ Business Logic Layer ─────────────────┐**
- ┌─────────────┐      ┌────────────┐  │
- Secret   │ ←──→ │    OTP     │  │
- Management │      │ Generation │  │
- ┘      └────────────┘  │
- ↕                   ↕          │
- ┌─────────────┐      ┌────────────┐  │
- Formatter  │      │   Backup   │  │
- ┘      └────────────┘  │
- ┬───────────────────┘
- ↓
**┌─ Storage Layer ──────────────────────┐**
- ┌─────────────┐    ┌────────────┐  │
- Keyring   │ ←→ │  Storage   │  │
- Interface  │    │  Handler   │  │
- ┘    └────────────┘  │
- ┘

##### Important Elements to Highlight

a. Security Flow:
- How secrets are encrypted/decrypted
- Temporary memory usage during operations
- Secure storage in system keyring

b. Data Flow:
- User input through CLI
- Secret retrieval from keyring
- OTP generation process
- Backup operations

##### Implementation Details

- The separation between secret storage and usage
- The temporary nature of secret presence in memory
- The interaction with system keyring
- The backup and recovery mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef logic fill:#2ecc71,stroke:#27ae60,color:white
    classDef storage fill:#e67e22,stroke:#d35400,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef infra fill:#9b59b6,stroke:#8e44ad,color:white

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]:::ui
    end

    %% Business Logic Layer
    subgraph Logic
        SecretMgmt["Secret Management"]:::logic
        OTPGen["OTP Generation"]:::logic
        Formatter["Formatter"]:::logic
        Backup["Backup System"]:::logic
    end

    %% Storage Layer
    subgraph Storage
        KeyringInt["Keyring Interface"]:::storage
        StorageHandler["Storage Handler"]:::storage
    end

    %% Test Components
    subgraph Testing
        TestSuite["Test Suite"]:::test
    end

    %% Infrastructure
    subgraph Infrastructure
        BuildDeploy["Build/Deploy"]:::infra
        DevSetup["Development Setup"]:::infra
    end

    %% Relationships
    CLI --> SecretMgmt
    CLI --> OTPGen
    SecretMgmt <--> KeyringInt
    SecretMgmt <--> Formatter
    SecretMgmt <--> Backup
    OTPGen <--> Formatter
    KeyringInt <--> StorageHandler
    TestSuite -.-> SecretMgmt
    TestSuite -.-> Formatter
    TestSuite -.-> CLI
    BuildDeploy -.-> CLI
    DevSetup -.-> CLI

    %% Click events for component mapping
    click CLI "https://github.com/endorama/2ami/blob/master/main.go"
    click SecretMgmt "https://github.com/endorama/2ami/blob/master/secret-string.go"
    click KeyringInt "https://github.com/endorama/2ami/blob/master/keyring.go"
    click Backup "https://github.com/endorama/2ami/blob/master/backup.go"
    click StorageHandler "https://github.com/endorama/2ami/blob/master/storage.go"
    click Formatter "https://github.com/endorama/2ami/blob/master/formatter.go"
    click TestSuite "https://github.com/endorama/2ami/blob/master/formatter_test.go"
    click BuildDeploy "https://github.com/endorama/2ami/blob/master/.github/workflows/release.yml"
    click DevSetup "https://github.com/endorama/2ami/tree/master/script/setup"

    %% Legend
    subgraph Legend
        UI_Legend["User Interface"]:::ui
        Logic_Legend["Business Logic"]:::logic
        Storage_Legend["Storage"]:::storage
        Test_Legend["Testing"]:::test
        Infra_Legend["Infrastructure"]:::infra
        Direct["→ Direct Flow"]
        Optional["-.-> Optional Flow"]
    end
```
