$ show chatboxai/chatbox
Chatbox is a cross-platform desktop AI chat client (Windows/macOS/Linux) built with Electron, React, and TypeScript. It supports 30+ AI providers (OpenAI, Claude, Gemini, DeepSeek, Ollama, etc.) via a unified provider registry and model abstraction layer. The application features agent mode with tool use, sandboxed code execution, MCP server integration, knowledge base RAG, web search, image generation, and a skills marketplace. It uses a hexagonal architecture with ports/adapters in a core package (`@chatbox/core`) that is host-agnostic, and React bindings in `@chatbox/react`. The renderer uses TanStack Router, Zustand/Jotai for state, and Mantine/MUI for UI. The main process handles IPC, OAuth flows, file system sandbox, and analytics. The codebase is large and well-tested (Vitest unit tests, integration tests, contract tests) with a focus on offline-first, local storage, and cross-platform compatibility (desktop, web, mobile via Capacitor). The application is actively maintained with a commercial 'Pro' version that shares code with this open-source Community Edition. Notable engineering patterns include a clean port/adapter separation, in-memory test doubles for all repositories, a session write coordinator that serializes updates and cancels stale queries, a draft tokenization system with web workers, and a provider registry that allows dynamic model discovery. The codebase has some technical debt: multiple UI libraries, legacy migration paths, and commented-out code, but overall demonstrates strong craftsmanship and reusability of its core abstractions.
The LLM identified 6 files worth highlighting for reuse:
Defines clean port interfaces (BlobStoragePort, KeyValueStoragePort, SessionRepositoryPort, SettingsStoragePort, LoggerPort, etc.) that decouple core domain logic from platform-specific implementations. Each port is accompanied by in-memory test doubles (InMemoryBlobStorage, InMemorySessionRepository, etc.) that enable fast, isolated unit testing without mocking frameworks. This pattern allows the core to be reused across Electron, web, and mobile targets with minimal changes.
Coordinates concurrent writes to a session by serializing updates, tracking a read cache, and canceling stale queries to prevent deadlocks and race conditions. It ensures that streaming message updates are checkpointed and terminal writes are applied atomically. This pattern is reusable in any application that needs safe, ordered writes to a shared resource with optimistic UI updates.
Base class for all AI SDK model wrappers (OpenAI, Claude, Gemini, Azure, etc.). Provides common logic for getCallSettings, getProvider, getChatModel, and streaming/non-streaming generation. Subclasses override provider-specific behavior (e.g., Anthropic cache control, Gemini thought signatures). This pattern enables adding new providers with minimal code and ensures consistent error handling and response normalization.
Implements a codec for encoding and decoding blob data (utf8, data-url-base64) with SHA-256 integrity checks. Used in the backup/restore system to serialize session data and attachments into a portable format. The codec is self-contained, has no external dependencies, and can be extracted for any project needing verifiable data serialization.
A complete token estimation subsystem that uses a web worker for off-main-thread draft tokenization, a quick estimate sampler for large texts, FNV-1a digest caching, and a computation queue with result persister. It supports multiple tokenizer types (cl100k_base, DeepSeek heuristics) and provides hooks for React. This is a reusable, well-tested module that could be extracted for any application needing client-side token counting.
Implements a provider registry using defineProvider() with metadata (display name, models, capabilities, API style). Providers are registered at build time and can be discovered dynamically. The registry supports model creation via factory functions, capability inference, and compatibility overlays. This pattern is reusable for any application that needs a plugin-style provider system with runtime discovery.