# infinilabs/coco-app architecture

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

- Interactive diagram: https://gitdiagram.com/infinilabs/coco-app
- Repository: https://github.com/infinilabs/coco-app

## Overview

##### Project Type and Purpose
- Coco AI is a full‑stack, cross‑platform desktop/mobile application built with a React/TypeScript front end (using Vite and PNPM) and a Rust back end powered by Tauri.
- Its purpose is to provide a unified search and Gen‑AI chat interface for enterprise data, connecting to external services (Google Workspace, Dropbox, GitHub, etc.) and a remote “coco-server” that handles indexing and search.

##### High‑Level Architectural Components
a. Frontend (src/)
- React UI components (pages, components, hooks, stores, reducers)
- API layer (axiosRequest.ts, tauriFetchClient.ts) for communicating with Tauri or web adapters
- State management (Zustand or similar stores under src/stores)
b. Tauri Runtime & Rust Backend (src‑tauri/)
- Tauri core (main.rs, lib.rs) hosting the WebView
- Command handlers (autostart, shortcut, assistant, search, server modules) exposed to the UI via Tauri Invoke
- Connectors and adapters in Rust (common/connector.rs, server/*) for HTTP, WebSocket, local file system, and capabilities management
- Platform setup code (setup/{linux,mac,windows}.rs)
c. Remote Backend (coco-server)
- External service handling indexing, search queries, authentication, data storage (not in this repo but critical to the system)
d. External Enterprise Data Sources
- Google Workspace, Dropbox, Confluence, GitHub, etc., accessed via connectors in coco-server and/or Tauri back end
e. Local Resources
- File system access for attachments
- Local configuration and cache (via tauri::fs, local folder under common/local)

##### Component Interactions and Data Flow
- The React UI issues commands (e.g., “search,” “start assistant”) via the Tauri Invoke API or HTTP adaptors.
- Tauri’s Rust back end receives and authenticates these commands, then:
- For enterprise data, delegates to HTTP clients or WebSockets to communicate with coco-server.
- For local operations, uses platform‑specific file system code.
- coco-server aggregates data from external services, performs search/index operations, and returns JSON responses over HTTP or WebSockets.
- Rust back end processes responses and sends structured events or return values back to the UI.
- The UI state stores update based on these events, and React re‑renders accordingly.

##### Architectural Patterns and Design Principles
- Separation of concerns: UI vs. native integration vs. remote services.
- Command pattern: distinct modules in Rust expose specific capabilities via Tauri commands.
- Layered state management: React components → hooks → stores → Rust commands.
- Adapter pattern: webAdapter.ts, tauriAdapter.ts, platformAdapter.ts abstract over environments.
- Modular connectors: each external data source has its own connector implementation.

##### Essential Elements to Capture
- Tauri boundary (WebView host vs. Rust permissions)
- Adapters for web vs. desktop modes
- State stores and command handlers
- External coco-server and enterprise connectors
- Local file I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef ui fill:#D0E8FF,stroke:#0288D1;
    classDef native fill:#D0FFD6,stroke:#2E7D32;
    classDef remote fill:#FFE0B2,stroke:#EF6C00;
    classDef external fill:#E0E0E0,stroke:#757575;
    classDef local fill:#F5F5F5,stroke:#9E9E9E;

    subgraph "UI Layer"
        UIComponents["React UI Components"]:::ui
        FrontendPages["Pages"]:::ui
        FrontendHooks["Hooks"]:::ui
        FrontendStores["Stores"]:::ui
        FrontendReducers["Reducers"]:::ui
        MainEntry["Main Entry (Vite)"]:::ui
        subgraph "API & Adapters"
            AxiosClient["Axios HTTP Client"]:::ui
            TauriClient["Tauri Fetch Adapter"]:::ui
            WebAdapter["Web Adapter"]:::ui
            TauriAdapter["Tauri Adapter"]:::ui
            PlatformAdapter["Platform Adapter"]:::ui
        end
        subgraph "State Management"
            AppStore["App Store (Zustand)"]:::ui
            UseWS["useWebSocket Hook"]:::ui
        end
    end

    subgraph "Tauri Host (Rust)"
        TauriMain["main.rs"]:::native
        TauriLib["lib.rs"]:::native
        subgraph "Commands"
            AssistantMod["Command: Assistant"]:::native
            SearchMod["Command: Search"]:::native
            ShortcutMod["Command: Shortcut"]:::native
            AutostartMod["Command: Autostart"]:::native
        end
        subgraph "Common Utilities"
            ConnectorUtil["connector.rs"]:::native
            HTTPUtil["http.rs"]:::native
            DatasourceUtil["datasource.rs"]:::native
            SearchUtil["search.rs"]:::native
            TauriWrappers["tauriWrappers.ts"]:::ui
        end
        subgraph "Local"
            FSCode["file_system.rs"]:::native
            AppLocal["application.rs"]:::native
        end
        subgraph "Server Connectors"
            ServerConnector["connector.rs"]:::native
            HTTPClient["http_client.rs"]:::native
            WebsocketClient["websocket.rs"]:::native
            ServerSearch["search.rs"]:::native
            ServerAttachment["attachment.rs"]:::native
        end
        subgraph "Platform Setup"
            SetupLinux["linux.rs"]:::native
            SetupMac["mac.rs"]:::native
            SetupWindows["windows.rs"]:::native
        end
    end

    subgraph "Remote Backend (coco-server)"
        CocoHTTP["coco-server HTTP API"]:::remote
        CocoWS["coco-server WebSocket"]:::remote
    end

    subgraph "External Enterprise APIs"
        Google["Google Workspace"]:::external
        Dropbox["Dropbox"]:::external
        GitHub["GitHub"]:::external
        Confluence["Confluence"]:::external
    end

    subgraph "Local FS & Config"
        LocalFS["📄 Local File System & Config"]:::local
    end

    UIComponents --> UseWS
    MainEntry -->|"initializes"| UIComponents
    AxiosClient -->|"HTTP (web mode)"| CocoHTTP
    TauriClient -->|"Tauri Invoke"| TauriMain
    WebAdapter -->|used by| AxiosClient
    TauriAdapter -->|used by| TauriClient
    PlatformAdapter -->|abstracts| WebAdapter
    PlatformAdapter -->|abstracts| TauriAdapter
    AppStore --> UseWS
    UseWS --> AppStore

    TauriMain --> TauriLib
    TauriLib --> AssistantMod
    TauriLib --> SearchMod
    TauriLib --> ShortcutMod
    TauriLib --> AutostartMod
    AssistantMod --> ConnectorUtil
    SearchMod --> ServerConnector
    SearchMod --> HTTPClient
    SearchMod --> WebsocketClient
    ServerAttachment --> FSCode
    ServerConnector -->|"delegates to"| CocoHTTP
    HTTPClient -->|"HTTP"| CocoHTTP
    WebsocketClient -->|"WS"| CocoWS
    FSCode --> LocalFS
    AppLocal --> LocalFS

    click UIComponents "https://github.com/infinilabs/coco-app/tree/main/src/components"
    click FrontendPages "https://github.com/infinilabs/coco-app/tree/main/src/pages"
    click FrontendHooks "https://github.com/infinilabs/coco-app/tree/main/src/hooks"
    click FrontendStores "https://github.com/infinilabs/coco-app/tree/main/src/stores"
    click FrontendReducers "https://github.com/infinilabs/coco-app/tree/main/src/reducers"
    click AxiosClient "https://github.com/infinilabs/coco-app/blob/main/src/api/axiosRequest.ts"
    click TauriClient "https://github.com/infinilabs/coco-app/blob/main/src/api/tauriFetchClient.ts"
    click WebAdapter "https://github.com/infinilabs/coco-app/blob/main/src/utils/webAdapter.ts"
    click TauriAdapter "https://github.com/infinilabs/coco-app/blob/main/src/utils/tauriAdapter.ts"
    click PlatformAdapter "https://github.com/infinilabs/coco-app/blob/main/src/utils/platformAdapter.ts"
    click MainEntry "https://github.com/infinilabs/coco-app/blob/main/src/main.tsx"
    click TauriMain "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/main.rs"
    click TauriLib "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/lib.rs"
    click AssistantMod "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/assistant/mod.rs"
    click SearchMod "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/search/mod.rs"
    click ShortcutMod "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/shortcut.rs"
    click AutostartMod "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/autostart.rs"
    click ConnectorUtil "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/common/connector.rs"
    click HTTPUtil "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/common/http.rs"
    click DatasourceUtil "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/common/datasource.rs"
    click SearchUtil "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/common/search.rs"
    click FSCode "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/local/file_system.rs"
    click AppLocal "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/local/application.rs"
    click ServerConnector "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/server/connector.rs"
    click HTTPClient "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/server/http_client.rs"
    click WebsocketClient "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/server/websocket.rs"
    click ServerSearch "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/server/search.rs"
    click ServerAttachment "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/server/attachment.rs"
    click SetupLinux "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/setup/linux.rs"
    click SetupMac "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/setup/mac.rs"
    click SetupWindows "https://github.com/infinilabs/coco-app/blob/main/src-tauri/src/setup/windows.rs"
    click AppStore "https://github.com/infinilabs/coco-app/blob/main/src/stores/appStore.ts"
    click UseWS "https://github.com/infinilabs/coco-app/blob/main/src/hooks/useWebSocket.ts"
    click CommandTypes "https://github.com/infinilabs/coco-app/blob/main/src/types/commands.ts"
    click TauriWrappers "https://github.com/infinilabs/coco-app/blob/main/src/utils/wrappers/tauriWrappers.ts"
```
