# itsriprod/deskthing architecture

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

- Interactive diagram: https://gitdiagram.com/itsriprod/deskthing
- Repository: https://github.com/itsriprod/deskthing

## Overview

##### Main Components

a. Desktop Application (DeskThingServer)
- Electron-based main process
- React-based renderer process
- IPC communication layer

b. Car Thing Device
- Custom firmware
- Web application client
- ADB connection

c. External Services Integration
- Spotify API
- Discord Integration
- Weather Services
- Other third-party services

##### Key Architectural Elements

a. Server-Side Architecture (Main Process)
- Handlers Layer (/src/main/handlers/)
- Services Layer (/src/main/services/)
- Stores Layer (/src/main/stores/)

b. Client-Side Architecture (Renderer Process)
- Components Layer (/src/renderer/src/components/)
- Pages Layer (/src/renderer/src/pages/)
- Stores Layer (/src/renderer/src/stores/)

**[Desktop Application]**
- Main Process
- Handlers (ADB, Auth, Device, etc.)
- Services (Apps, Client, Mappings)
- Stores (Settings, Logging, Connections)

- Renderer Process
- UI Components
- Pages/Routes
- State Management

**[Car Thing Device]**
- Custom Firmware
- Web Application
- Control Interface

**[External Services]**
- Spotify API
- Discord API
- Weather API
- Other Services

##### Connection Flows

- Blue: Data flow
- Green: Control flow
- Red: Error handling
- Orange: Event broadcasting

##### Important Relationships to Highlight

a. Desktop App ↔ Car Thing
- ADB communication
- Web application deployment
- Device control

b. Desktop App ↔ External Services
- API authentication
- Data synchronization
- Event handling

c. Internal Communication
- IPC between main and renderer processes
- Store updates and state management
- Event handling system

##### Additional Elements

- Version information
- System requirements
- Critical security boundaries
- Extensibility points for apps

##### Implementation Details to Note

- Rectangles: Core components
- Hexagons: External services
- Rounded rectangles: User interfaces

##### Architectural Patterns to Emphasize

- Event-driven architecture
- Component-based UI structure
- Service-oriented backend
- Plugin system for apps

Remember to include the app ecosystem aspect, showing how third-party apps can be integrated into the system, as this is a key feature of the DeskThing platform.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Desktop["Desktop Application"]
        MainProcess["Main Process"]:::main
        
        subgraph Handlers["Handlers Layer"]
            AuthHandler["Auth Handler"]:::handler
            DeviceHandler["Device Handler"]:::handler
            MusicHandler["Music Handler"]:::handler
            ADBHandler["ADB Handler"]:::handler
        end
        
        subgraph Services["Services Layer"]
            AppServices["App Services"]:::service
            ClientServices["Client Services"]:::service
            MappingServices["Mapping Services"]:::service
            
            subgraph ClientComponents["Client Components"]
                ExpressServer["Express Server"]:::server
                WebSocket["WebSocket Server"]:::server
            end
            
            subgraph AppManagement["App Management"]
                AppManager["App Manager"]:::app
                AppInstaller["App Installer"]:::app
                AppRunner["App Runner"]:::app
            end
        end
        
        subgraph Stores["Main Process Stores"]
            SettingsStore[(Settings Store)]:::store
            LoggingStore[(Logging Store)]:::store
            ConnectionsStore[(Connections Store)]:::store
        end
        
        subgraph Renderer["Renderer Process"]
            Components["UI Components"]:::ui
            Pages["Pages/Routes"]:::ui
            RendererStores["State Management"]:::ui
        end
        
        IPC{"IPC Communication"}:::comm
    end
    
    subgraph CarThing["Car Thing Device"]
        Firmware["Custom Firmware"]
        WebApp["Web Application"]
        Control["Control Interface"]
    end
    
    subgraph External["External Services"]
        SpotifyAPI["Spotify API"]:::ext
        DiscordAPI["Discord API"]:::ext
        WeatherAPI["Weather API"]:::ext
        OtherAPI["Other Services"]:::ext
    end
    
    %% Connections
    MainProcess --> Handlers
    MainProcess --> Services
    MainProcess --> Stores
    MainProcess <--> IPC
    IPC <--> Renderer
    
    ClientServices --> ClientComponents
    AppServices --> AppManagement
    
    ADBHandler <--> CarThing
    WebSocket <--> WebApp
    ExpressServer --> WebApp
    
    MainProcess <--> External
    
    %% Click Events
    click MainProcess "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/index.ts"
    click AuthHandler "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/handlers/authHandler.ts"
    click DeviceHandler "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/handlers/deviceHandler.ts"
    click MusicHandler "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/handlers/musicHandler.ts"
    click ADBHandler "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/handlers/adbHandler.ts"
    click AppServices "https://github.com/ItsRiprod/DeskThing/tree/main/src/main/services/apps/"
    click ClientServices "https://github.com/ItsRiprod/DeskThing/tree/main/src/main/services/client/"
    click MappingServices "https://github.com/ItsRiprod/DeskThing/tree/main/src/main/services/mappings/"
    click ExpressServer "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/services/client/expressServer.ts"
    click WebSocket "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/services/client/websocket.ts"
    click AppManager "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/services/apps/appManager.ts"
    click AppInstaller "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/services/apps/appInstaller.ts"
    click AppRunner "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/services/apps/appRunner.ts"
    click SettingsStore "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/stores/settingsStore.ts"
    click LoggingStore "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/stores/loggingStore.ts"
    click ConnectionsStore "https://github.com/ItsRiprod/DeskThing/blob/main/src/main/stores/connectionsStore.ts"
    click Components "https://github.com/ItsRiprod/DeskThing/tree/main/src/renderer/src/components/"
    click Pages "https://github.com/ItsRiprod/DeskThing/tree/main/src/renderer/src/pages/"
    click RendererStores "https://github.com/ItsRiprod/DeskThing/tree/main/src/renderer/src/stores/"
    click IPC "https://github.com/ItsRiprod/DeskThing/blob/main/src/shared/types/ipcTypes.ts"
    
    %% Styles
    classDef main fill:#f9f,stroke:#333,stroke-width:2px
    classDef handler fill:#aaf,stroke:#333
    classDef service fill:#afa,stroke:#333
    classDef store fill:#faa,stroke:#333
    classDef server fill:#ffa,stroke:#333
    classDef app fill:#aff,stroke:#333
    classDef ui fill:#faf,stroke:#333
    classDef comm fill:#fff,stroke:#f66,stroke-width:2px
    classDef ext fill:#ddd,stroke:#333
```
