# muun/recovery architecture

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

## Overview

##### Main Components

a) Core Components:
- Recovery Tool Engine (main.go)
- Key Generation System (keys_generator.go)
- Address Generation System (address_generator.go)
- Scanner Module (scanner/)
- Survey Module (cmd/survey/)
- Electrum Client Integration (electrum/)
- Recovery Process Handler (recovery_tool.go)
- Sweeper Component (sweeper.go)

b) External Integrations:
- Electrum Servers
- Bitcoin Network
- User Interface (CLI)

**┌─ User Interface Layer ─────────────────────┐**

- Command Line Interface                   │
- (main.go)                               │

- Core Processing Layer ──────────────────┤

- ┌─ Recovery Process Handler ─┐         │
- (recovery_tool.go)      │         │
- ┬────────────┘         │

- ┌─────────────┼─────────────┐        │

- ▼             ▼             ▼        │
- Keys      Address       Scanner       │
- Generator  Generator    Module        │

- Integration Layer ─────────────────┤

- ┌─ Electrum Client ─┐            │
- Pool Manager   │            │
- ┬────────┘            │

- ┼──────────────────────┘

- ▼
- [External Electrum Servers]

##### Key Relationships to Highlight

a) Data Flow:
- User Input → Recovery Process Handler
- Recovery Process Handler → Key Generation
- Key Generation → Address Generation
- Scanner Module ↔ Electrum Client
- Sweeper → Bitcoin Network

b) Dependencies:
- Electrum Client Pool → External Servers
- Scanner → Electrum Client
- Recovery Tool → Key/Address Generators

##### Implementation Details

- Configuration management
- Logging system (utils/logger.go)
- Version control (version.go)
- Task management system (scanner/task.go)

##### Notes

- Notes about the asynchronous nature of certain operations
- Self-contained nature of the recovery process
- Separation between user data input and processing
- Points where user confirmation is required

##### The robust error handling and validation system

Remember to include version information and any platform-specific considerations, as the tool supports multiple operating systems and architectures.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#FFE4B5,stroke:#FF8C00
    classDef core fill:#B0E0E6,stroke:#4682B4
    classDef external fill:#98FB98,stroke:#228B22
    classDef integration fill:#DDA0DD,stroke:#8B008B

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

    %% Core Processing Layer
    subgraph Core["Core Processing Layer"]
        RPH["Recovery Process Handler"]:::core
        KG["Key Generation System"]:::core
        AG["Address Generation System"]:::core
        SM["Scanner Module"]:::core
        SV["Survey Module"]:::core
        SW["Sweeper Component"]:::core
        TM["Task Management"]:::core
        VC["Version Control"]:::core
        LOG["Logging System"]:::core
    end

    %% Integration Layer
    subgraph Integration["Integration Layer"]
        EC["Electrum Client"]:::integration
        EP["Electrum Pool Manager"]:::integration
        ES["Electrum Servers Config"]:::integration
    end

    %% External Systems
    EXT["External Electrum Servers"]:::external
    BTC["Bitcoin Network"]:::external

    %% Relationships
    CLI --> RPH
    RPH --> KG
    RPH --> AG
    RPH --> SM
    RPH --> SV
    RPH --> SW
    SM --> TM
    SM --> EC
    EC --> EP
    EP --> ES
    ES --> EXT
    SW --> BTC
    
    %% System-wide components
    RPH --> LOG
    RPH --> VC

    %% Click events for component mapping
    click CLI "https://github.com/muun/recovery/blob/master/main.go"
    click KG "https://github.com/muun/recovery/blob/master/keys_generator.go"
    click AG "https://github.com/muun/recovery/blob/master/address_generator.go"
    click SM "https://github.com/muun/recovery/blob/master/scanner/scanner.go"
    click SV "https://github.com/muun/recovery/blob/master/survey/survey.go"
    click EC "https://github.com/muun/recovery/blob/master/electrum/client.go"
    click EP "https://github.com/muun/recovery/blob/master/electrum/pool.go"
    click ES "https://github.com/muun/recovery/blob/master/electrum/servers.go"
    click RPH "https://github.com/muun/recovery/blob/master/recovery_tool.go"
    click SW "https://github.com/muun/recovery/blob/master/sweeper.go"
    click TM "https://github.com/muun/recovery/blob/master/scanner/task.go"
    click LOG "https://github.com/muun/recovery/blob/master/utils/logger.go"
    click VC "https://github.com/muun/recovery/blob/master/version.go"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        CORE_L["Core Component"]:::core
        INT_L["Integration Component"]:::integration
        EXT_L["External System"]:::external
    end
```
