# brafdlog/caspion architecture

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

- Interactive diagram: https://gitdiagram.com/brafdlog/caspion
- Repository: https://github.com/brafdlog/caspion

## Overview

##### Main Components Identification

The system consists of three main packages following Electron's architecture:
- Main Process (packages/main)
- Renderer Process (packages/renderer)
- Preload Scripts (packages/preload)

##### Key Architectural Elements

a. Frontend Layer (Renderer):
- React-based UI components
- Store management system
- Account management interface
- Exporter configurations

b. Backend Layer (Main):
- Bank scraping system
- Configuration management
- Transaction processing
- Export system
- Logging and analytics

c. Integration Points:
- Bank APIs (via israeli-bank-scrapers)
- Export destinations (YNAB, Google Sheets, CSV, JSON)
- OAuth2 authentication for Google Sheets

**[User Interface Layer]**

**[Electron Framework]**

**[Core Application Layer]**

**[External Services Layer]**

##### Important Flows to Highlight

a. Transaction Flow:
**[Bank Scraper] -> [Transaction Processor] -> [Category Calculator] -> [Exporter]**

b. Authentication Flow:
**[UI] -> [Config Manager] -> [Encryption] -> [Secure Storage]**

c. Export Flow:
**[Transaction Store] -> [Export Manager] -> [Output Vendors] -> [External Services]**

##### Notes for Implementation

- Maintain consistent styling and naming
- Version information
- Notes for important security considerations
- Document all external service dependencies

This system design should capture the essence of Caspion as a desktop application that securely handles financial data while providing automated expense tracking and export capabilities.

Remember to emphasize the security aspects, as this application deals with sensitive financial information, and show how the system maintains separation of concerns between the UI, core logic, and external integrations.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        ReactUI["React UI Components"]:::ui
        Store["Store Management"]:::ui
        AccMgmt["Account Management"]:::ui
    end

    subgraph EF["Electron Framework"]
        EventBridge["Event Bridge"]:::security
        Preload["Preload Scripts"]:::security
    end

    subgraph Core["Core Application Layer"]
        direction TB
        ConfigMgr["Configuration Management"]:::core
        Security["Security/Encryption"]:::security
        TxProc["Transaction Processing"]:::core
        BankScraper["Bank Scraping System"]:::core
        Logger["Logging and Analytics"]:::core
        ExportMgr["Export System"]:::core
    end

    subgraph External["External Services Layer"]
        direction TB
        subgraph Banks["Bank APIs"]
            IsraeliBankAPI["Israeli Bank Scrapers"]:::external
        end

        subgraph ExportServices["Export Services"]
            direction TB
            OAuth["OAuth2 Authentication"]:::security
            CSV["CSV Export"]:::external
            JSON["JSON Export"]:::external
            YNAB["YNAB Export"]:::external
            GSheets["Google Sheets Export"]:::external
        end
    end

    %% Connections
    ReactUI --> EventBridge
    Store --> EventBridge
    AccMgmt --> EventBridge
    EventBridge --> Preload
    Preload --> ConfigMgr
    Preload --> TxProc
    Preload --> ExportMgr
    
    ConfigMgr --> Security
    BankScraper --> IsraeliBankAPI
    BankScraper --> TxProc
    TxProc --> ExportMgr
    ExportMgr --> CSV
    ExportMgr --> JSON
    ExportMgr --> YNAB
    ExportMgr --> GSheets
    GSheets --> OAuth
    
    %% Logging connections
    TxProc --> Logger
    BankScraper --> Logger
    ExportMgr --> Logger

    %% Styling
    classDef ui fill:#3498db
    classDef core fill:#2ecc71
    classDef external fill:#f1c40f
    classDef security fill:#e74c3c
    classDef storage fill:#9b59b6

    %% Click events
    click ReactUI "https://github.com/brafdlog/caspion/tree/master/packages/renderer/src/components/"
    click Store "https://github.com/brafdlog/caspion/tree/master/packages/renderer/src/store/"
    click AccMgmt "https://github.com/brafdlog/caspion/tree/master/packages/renderer/src/components/accounts/"
    click EventBridge "https://github.com/brafdlog/caspion/blob/master/packages/preload/src/eventsBridge.ts"
    click Preload "https://github.com/brafdlog/caspion/tree/master/packages/preload/"
    click ConfigMgr "https://github.com/brafdlog/caspion/blob/master/packages/main/src/backend/configManager/configManager.ts"
    click Security "https://github.com/brafdlog/caspion/tree/master/packages/main/src/backend/configManager/encryption/"
    click TxProc "https://github.com/brafdlog/caspion/blob/master/packages/main/src/backend/transactions/transactions.ts"
    click BankScraper "https://github.com/brafdlog/caspion/blob/master/packages/main/src/backend/import/bankScraper.ts"
    click Logger "https://github.com/brafdlog/caspion/tree/master/packages/main/src/logging/"
    click ExportMgr "https://github.com/brafdlog/caspion/blob/master/packages/main/src/backend/export/exportTransactions.ts"
    click OAuth "https://github.com/brafdlog/caspion/blob/master/packages/main/src/backend/export/outputVendors/googleSheets/googleAuth.ts"
    click CSV "https://github.com/brafdlog/caspion/tree/master/packages/main/src/backend/export/outputVendors/csv/"
    click JSON "https://github.com/brafdlog/caspion/tree/master/packages/main/src/backend/export/outputVendors/json/"
    click YNAB "https://github.com/brafdlog/caspion/tree/master/packages/main/src/backend/export/outputVendors/ynab/"
    click GSheets "https://github.com/brafdlog/caspion/tree/master/packages/main/src/backend/export/outputVendors/googleSheets/"
```
