# oxen-io/session-desktop architecture

> Architecture diagram of the GitHub repository oxen-io/session-desktop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oxen-io/session-desktop
- Repository: https://github.com/oxen-io/session-desktop

## Overview

##### Main Components

a. Client-Side Components:
- Frontend UI Layer (React/TypeScript based on ts/components structure)
- Message Processing Layer
- Encryption/Decryption Module
- Local Storage/Database
- Attachment Handling System

b. Network Components:
- Oxen Service Nodes Integration
- Onion Routing System
- Message Relay System

##### Key Architectural Elements

a. Core Services (represent as separate blocks):
- Message Queue System (ts/session/sending/MessageQueue.ts)
- Attachment Management (ts/session/utils/Attachments.ts)
- Encryption Services (ts/session/crypto/)
- Profile Management (ts/session/profile_manager/)
- Configuration Management (ts/node/config/)

- API Integration Layer (ts/session/apis/)
- Service Node Communication (ts/session/apis/snode_api/)
- Open Group Communication (ts/session/apis/open_group_api/)

##### Data Flow Representation

- Message Flow: User → Encryption → Onion Routing → Service Nodes
- Attachment Flow: Attachment → Encryption → Storage → Transmission
- Configuration Sync: Local Config ↔ Network Sync

- Encryption Layer
- Onion Routing
- Service Node Authentication
- Message Privacy Controls

##### Specific Implementation Details

Create subsections for:
a. Frontend Architecture:
- Component Hierarchy
- State Management (Redux based on ts/state/)
- UI Theme System (ts/themes/)

b. Backend Services:
- Database Operations
- File Handling
- Worker Processes (ts/webworker/)

##### Integration Points

Connections with:
- Service Nodes Network
- File Servers
- Push Notification Services
- Open Group Servers

- Blue: Core application components
- Green: Security/encryption components
- Orange: External services
- Gray: Infrastructure components

##### Lines
- Solid: Direct communication

##### Labels
- Component names
- Data flow descriptions
- API endpoints
- Security protocol indicators

Keep the abstraction level high enough to be understandable but detailed enough to show the privacy-focused nature of the application and its decentralized architecture.

Showing how the application maintains user privacy through its various security mechanisms while enabling seamless messaging functionality.

- Decentralized architecture
- End-to-end encryption
- Onion routing for IP address obfuscation
- Integration with Oxen Service Nodes
- Offline message storage
- Multi-platform support

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Frontend UI Layer"]
        MP["Message Processing"]
        ED["Encryption/Decryption"]
        LS[("Local Storage/DB")]
        AH["Attachment Handler"]
        MQ["Message Queue"]
        PM["Profile Manager"]
        CM["Config Manager"]
        TH["Theme System"]
        WP["Worker Processes"]
        SM["State Management"]
    end

    subgraph Network
        SN["Service Nodes"]
        OR["Onion Routing"]
        MR["Message Relay"]
    end

    subgraph External
        OGS["Open Group Servers"]
        FS["File Servers"]
        PNS["Push Notification Services"]
    end

    %% Core Application Flow
    UI --> MP
    MP --> ED
    ED --> MQ
    MQ --> OR
    OR --> SN
    SN --> MR
    MR --> ED
    ED --> MP
    MP --> UI

    %% Attachment Flow
    AH --> ED
    ED --> FS
    FS --> ED
    
    %% Configuration and State
    CM --> SM
    PM --> SM
    SM --> UI
    TH --> UI

    %% External Services
    SN --> OGS
    SN --> PNS
    
    %% Storage
    MP --> LS
    AH --> LS
    PM --> LS

    %% Background Processes
    WP -.-> MP
    WP -.-> AH

    %% Click Events
    click UI "https://github.com/oxen-io/session-desktop/tree/unstable/ts/components/"
    click MP "https://github.com/oxen-io/session-desktop/tree/unstable/ts/session/messages/"
    click ED "https://github.com/oxen-io/session-desktop/tree/unstable/ts/session/crypto/"
    click LS "https://github.com/oxen-io/session-desktop/blob/unstable/ts/node/sql.ts"
    click AH "https://github.com/oxen-io/session-desktop/blob/unstable/ts/session/utils/AttachmentsV2.ts"
    click MQ "https://github.com/oxen-io/session-desktop/blob/unstable/ts/session/sending/MessageQueue.ts"
    click PM "https://github.com/oxen-io/session-desktop/blob/unstable/ts/session/profile_manager/ProfileManager.ts"
    click CM "https://github.com/oxen-io/session-desktop/tree/unstable/ts/node/config/"
    click TH "https://github.com/oxen-io/session-desktop/tree/unstable/ts/themes/"
    click WP "https://github.com/oxen-io/session-desktop/tree/unstable/ts/webworker/"
    click SM "https://github.com/oxen-io/session-desktop/tree/unstable/ts/state/"
    click SN "https://github.com/oxen-io/session-desktop/tree/unstable/ts/session/apis/snode_api/"
    click OR "https://github.com/oxen-io/session-desktop/tree/unstable/ts/session/onions/"
    click OGS "https://github.com/oxen-io/session-desktop/tree/unstable/ts/session/apis/open_group_api/"

    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef security fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white

    class UI,MP,MQ,PM,CM,TH,WP,SM core
    class ED,OR,SN,MR security
    class OGS,FS,PNS external
    class LS storage

    %% Legend
    subgraph Legend
        C1["Core Component"]:::core
        S1["Security Component"]:::security
        E1["External Service"]:::external
        ST1[("Storage")]:::storage
    end
```
