How infinilabs/coco-app works
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