# meyse/chat-dapp architecture

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

- Interactive diagram: https://gitdiagram.com/meyse/chat-dapp
- Repository: https://github.com/meyse/chat-dapp

## Overview

##### Project type and purpose
- This is a desktop full-stack application built with Tauri (Rust) on the backend and SvelteKit + TypeScript on the frontend.
- From the file names and components (ChatInterface, OnboardingFlow, PersistencePrompt) it’s a chat client that integrates with VerusID and uses local credential storage and RPC calls under the hood.

##### File structure
- Top-level:
- `src/` — SvelteKit application with:
– `app.html`, `app.css`, router (`routes/`), shared components (`lib/components/`), utilities, types and assets.
- Configuration files for Vite, Tailwind, TypeScript, Svelte, VS Code, Git.
- The separation of `src-tauri` vs `src` indicates a clear two-tier architecture: frontend UI and native backend.

##### README for insights
- Confirms the tech stack: Tauri + SvelteKit + TypeScript + Vite.

a. Main components
- Frontend (SvelteKit + Vite + TypeScript)
- Tauri runtime (JavaScript ↔ Rust IPC layer)
- Backend modules (Rust):
– `credentials.rs` (key management)
– `settings.rs` (app config persistence)
– `verus_rpc.rs` (external RPC calls)
– `lib.rs` / `main.rs` (entry point, command registration)
- External services:
– VerusID RPC endpoint (blockchain chat interface)
- OS resources:
– File system (local JSON or SQLite storage)
– Secure storage (keychain, if used)
- Build toolchain:
– Vite (dev server / bundler)
– Cargo (Rust build)
b. Relationships and interactions
1. User interacts with Svelte components (Chat UI, Onboarding, Settings).
2. Frontend calls `window.__TAURI__.invoke("commandName", payload)`.
3. Tauri runtime marshals to Rust functions (in `main.rs`).
4. Rust handlers perform:
– Local IO (read/write settings or credentials).
– RPC calls to external VerusID/chat service.
5. Rust returns results via IPC back to the UI.
6. UI updates state, re-renders components.
c. Architectural patterns and design principles
- Two-tier (UI vs native backend) with clear IPC boundary
- Component-driven UI (SvelteKit)
- Single-source-of-truth in Rust modules for persistence and RPC logic
- Configuration as code (Tauri config, Tailwind, Vite, Cargo)
d. Relevant technologies/frameworks/libraries
- Frontend: SvelteKit, Vite, Tailwind CSS, TypeScript
- Backend: Tauri, Rust, Cargo
- IPC: Tauri’s `invoke` API
- External: VerusID RPC

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Application" 
        direction TB
        A1["App HTML Template"]:::config
        A2["Static Assets"]:::external
        A3["Vite Configuration"]:::config
        A4["Tailwind Configuration"]:::config
        subgraph "UI Components" 
            direction TB
            ChatUI["ChatInterface"]:::frontend
            Onboarding["OnboardingFlow"]:::frontend
            PersistencePrompt["PersistencePromptModal"]:::frontend
            SettingsView["SettingsView"]:::frontend
            subgraph "Chat Sub-Components"
                direction TB
                ConversationsList["ConversationsList"]:::frontend
                ConversationView["ConversationView"]:::frontend
                MessageInput["MessageInput"]:::frontend
                NewChatModal["NewChatModal"]:::frontend
            end
            subgraph "Onboarding Sub-Components"
                direction TB
                WelcomeStep["WelcomeStep"]:::frontend
                BlockchainStep["BlockchainStep"]:::frontend
                CredentialsStep["CredentialsStep"]:::frontend
                VerusIdStep["VerusIdStep"]:::frontend
            end
            subgraph "Settings Sub-Components"
                direction TB
                ConfirmDelete["ConfirmDeleteModal"]:::frontend
            end
        end
    end

    %% IPC Layer
    subgraph "Tauri IPC Bridge" 
        direction TB
        IPC["Tauri invoke API"]:::ipc
        MainCmds["Command Registration"]:::ipc
    end

    %% Backend Layer
    subgraph "Rust Backend Modules" 
        direction TB
        Lib["Tauri Library Module"]:::backend
        Creds["Credentials Management"]:::backend
        SettingsMod["Settings Persistence"]:::backend
        VerusRPC["Verus RPC Wrapper"]:::backend
        MainRust["main.rs (Entry Point)"]:::backend
    end

    %% External and OS
    subgraph "External Services & OS" 
        direction TB
        VerusExt["VerusID RPC Endpoint"]:::external
        FileSys["File System (JSON/SQLite)"]:::os
        Keychain["Secure Storage (Keychain)"]:::os
    end

    %% Build Toolchain
    subgraph "Build Toolchain" 
        direction TB
        Vite["Vite"]:::config
        Cargo["Cargo"]:::config
        BuildScript["Tauri Build Script"]:::config
        CargoToml["Cargo.toml"]:::config
        TauriConf["tauri.conf.json"]:::config
        MacConf["tauri.macos.conf.json"]:::config
    end

    %% Connections
    %% Frontend to IPC
    ChatUI -->|"invoke(command)"| IPC
    Onboarding -->|"invoke(command)"| IPC
    PersistencePrompt -->|"invoke(command)"| IPC
    SettingsView -->|"invoke(command)"| IPC

    %% IPC to Rust handlers
    IPC --> MainRust
    MainRust --> Lib
    MainRust --> Creds
    MainRust --> SettingsMod
    MainRust --> VerusRPC

    %% Rust modules to OS and external
    Creds -->|"read/write"| FileSys
    SettingsMod -->|"read/write"| FileSys
    Creds -->|"secure store"| Keychain
    VerusRPC -->|"HTTP/WebSocket"| VerusExt

    %% Rust back to IPC to Frontend
    VerusRPC --> IPC
    SettingsMod --> IPC
    Creds --> IPC

    %% Build relationships
    Vite --> A1
    Cargo --> MainRust
    BuildScript --> Cargo
    CargoToml --> Cargo
    TauriConf --> BuildScript
    MacConf --> BuildScript

    %% Click Events
    click A1 "https://github.com/meyse/chat-dapp/blob/main//src/app.html"
    click A2 "https://github.com/meyse/chat-dapp/tree/main//static"
    click A3 "https://github.com/meyse/chat-dapp/blob/main/vite.config.js"
    click A4 "https://github.com/meyse/chat-dapp/blob/main/tailwind.config.js"
    click ChatUI "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/ChatInterface.svelte"
    click Onboarding "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/OnboardingFlow.svelte"
    click PersistencePrompt "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/chat/PersistencePromptModal.svelte"
    click ConversationsList "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/chat/ConversationsList.svelte"
    click ConversationView "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/chat/ConversationView.svelte"
    click MessageInput "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/chat/MessageInput.svelte"
    click NewChatModal "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/chat/NewChatModal.svelte"
    click WelcomeStep "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/onboarding/WelcomeStep.svelte"
    click BlockchainStep "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/onboarding/BlockchainStep.svelte"
    click CredentialsStep "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/onboarding/CredentialsStep.svelte"
    click VerusIdStep "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/onboarding/VerusIdStep.svelte"
    click SettingsView "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/settings/SettingsView.svelte"
    click ConfirmDelete "https://github.com/meyse/chat-dapp/blob/main//src/lib/components/settings/ConfirmDeleteModal.svelte"
    click MainCmds "https://github.com/meyse/chat-dapp/blob/main//src-tauri/src/main.rs"
    click Lib "https://github.com/meyse/chat-dapp/blob/main//src-tauri/src/lib.rs"
    click Creds "https://github.com/meyse/chat-dapp/blob/main//src-tauri/src/credentials.rs"
    click SettingsMod "https://github.com/meyse/chat-dapp/blob/main//src-tauri/src/settings.rs"
    click VerusRPC "https://github.com/meyse/chat-dapp/blob/main//src-tauri/src/verus_rpc.rs"
    click BuildScript "https://github.com/meyse/chat-dapp/blob/main//src-tauri/build.rs"
    click TauriConf "https://github.com/meyse/chat-dapp/blob/main//src-tauri/tauri.conf.json"
    click MacConf "https://github.com/meyse/chat-dapp/blob/main//src-tauri/tauri.macos.conf.json"
    click CargoToml "https://github.com/meyse/chat-dapp/blob/main//src-tauri/Cargo.toml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef ipc fill:#E8D0FF,stroke:#6A0DAD,color:#6A0DAD;
    classDef backend fill:#D0FFD6,stroke:#028A0F,color:#028A0F;
    classDef external fill:#FFE8D0,stroke:#D9730D,color:#D9730D;
    classDef os fill:#F0F0F0,stroke:#888888,color:#333333;
    classDef config fill:#FFD0DC,stroke:#D10F4C,color:#D10F4C;
```
