# iotaledger/firefly architecture

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

- Interactive diagram: https://gitdiagram.com/iotaledger/firefly
- Repository: https://github.com/iotaledger/firefly

## Overview

##### Project type and purpose
- This is a monorepo for Firefly Shimmer, the official desktop wallet for the IOTA/Shimmer network.
- It’s built as an Electron-based full-stack desktop application with a Svelte/TypeScript UI (“packages/desktop”) and a shared TypeScript library of components, stores, and domain logic (“packages/shared”).
- Key use cases: account/profile management, transaction signing (including Ledger hardware support), token and NFT management, governance proposals, deep links, app updates and notifications.

##### High-level architecture from the file tree
- “packages/desktop”:
– Electron main process (electron/main.js) responsible for OS integration: native menus, deep-link handling, auto-updates, notification, stronghold encryption.
– Electron preload script (electron/preload.js) that exposes a safe IPC API to the renderer.
– Renderer process: Svelte UI components, views, feature flags, routers, stores, styling, assets, and business logic orchestrated by shared library.
– Build scripts and configuration (webpack, electron-builder, postcss, tsconfig).
- “packages/shared”:
– Core domain logic and state management (TS “lib” folder) covering account management, profile manager, wallet-rs bindings, network client, ledger integration, market price polling, governance logic, layer-2, token/NFT orchestration, i18n, error handling, utility modules, routing.
– Stores and context providers (Svelte stores) for each domain.
– Tests and mocks.
- Top-level: CI/CD workflows, linting configuration, docs and specifications, handbook guides, localization, contribution templates.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Electron Main Process"
        direction TB
        EM_main["main.js"]:::main
        libMain["lib modules"]:::os
    end

    subgraph "Electron Preload Bridge"
        direction TB
        preload["preload.js"]:::bridge
        aboutPreload["aboutPreload.js"]:::bridge
        errorPreload["errorPreload.js"]:::bridge
    end

    subgraph "Renderer Process"
        direction TB
        App["App.svelte"]:::ui
        subgraph Views
            direction TB
            splash["Splash.svelte"]:::ui
            login["login/"]:::ui
            onboarding["onboarding/"]:::ui
            dashboardView["dashboard/"]:::ui
            stronghold["update-stronghold/"]:::ui
        end
        comp["components/"]:::ui
        routers["lib/routers"]:::domain
        features["features"]:::domain
    end

    subgraph "Shared Library"
        direction TB
        subgraph "UI Components"
            sharedComp["components/"]:::ui
            assets["assets/"]:::ui
        end
        subgraph "Domain Logic & State"
            core["lib/core"]:::domain
            contexts["lib/contexts"]:::domain
            aux["lib/auxiliary"]:::domain
            sharedFeatures["lib/features"]:::domain
        end
        tests["lib/tests & __mocks__"]:::shared
        locales["locales"]:::shared
    end

    subgraph "External Services"
        direction TB
        nodeAPI["IOTA/Shimmer Node API"]:::external
        marketAPI["Market Price API"]:::external
        ledgerHW["Ledger Device"]:::external
        updateServer["Auto-update Server"]:::external
        osDeep["OS Deep-link Registry"]:::external
        fileSys["File System"]:::external
    end

    %% Flows
    App -->|"IPC Renderer"| preload
    preload -->|"IPC Main"| EM_main
    EM_main -->|"File I/O"| fileSys
    EM_main -->|"HID"| ledgerHW
    EM_main -->|"OS Deep-link"| osDeep
    EM_main -->|"Update Check"| updateServer
    EM_main -->|"Error/Notify"| App

    App -->|"UI uses"| comp
    App -->|"Routing"| routers
    App -->|"Feature Flags"| features
    comp -->|"uses"| sharedComp
    comp -->|"uses"| contexts
    routers -->|"interfaces"| sharedFeatures
    features -->|"flags"| sharedFeatures

    comp -->|"actions"| core
    routers -->|"helpers"| aux
    contexts -->|"state"| core
    sharedFeatures -->|"feature interfaces"| core

    core -->|"HTTP/API"| nodeAPI
    core -->|"HTTP/API"| marketAPI
    core -->|"Binary Signing"| ledgerHW
    core -->|"Stronghold Ops"| EM_main

    %% Click events
    click EM_main "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/electron/main.js"
    click libMain "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/electron/lib"
    click preload "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/electron/preload.js"
    click aboutPreload "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/electron/lib/aboutPreload.js"
    click errorPreload "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/electron/lib/errorPreload.js"
    click App "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/App.svelte"
    click splash "https://github.com/iotaledger/firefly/blob/develop/packages/desktop/views/Splash.svelte"
    click login "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/views/login/"
    click onboarding "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/views/onboarding/"
    click dashboardView "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/views/dashboard/"
    click stronghold "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/views/update-stronghold/"
    click comp "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/components"
    click routers "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/lib/routers"
    click features "https://github.com/iotaledger/firefly/tree/develop/packages/desktop/features"
    click sharedComp "https://github.com/iotaledger/firefly/tree/develop/packages/shared/components"
    click assets "https://github.com/iotaledger/firefly/tree/develop/packages/shared/assets"
    click core "https://github.com/iotaledger/firefly/tree/develop/packages/shared/lib/core"
    click contexts "https://github.com/iotaledger/firefly/tree/develop/packages/shared/lib/contexts"
    click aux "https://github.com/iotaledger/firefly/tree/develop/packages/shared/lib/auxiliary"
    click sharedFeatures "https://github.com/iotaledger/firefly/tree/develop/packages/shared/lib/features"
    click tests "https://github.com/iotaledger/firefly/tree/develop/packages/shared/lib/tests"
    click locales "https://github.com/iotaledger/firefly/tree/develop/packages/shared/locales"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef domain fill:#d4edda,stroke:#333,stroke-width:1px
    classDef os fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef main fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef bridge fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef shared fill:#f0f0f0,stroke:#333,stroke-width:1px
```
