How daodao97/chatmcp works
Main Components
• Frontend/UI Layer:
• This is built primarily with Flutter (see the “lib” directory containing UI pages under “lib/page”, widgets under “lib/widgets”, and various layouts).
• It includes components such as chat interfaces, setting pages (for configuring LLM API keys and MCP server settings) and preview screens (as evidenced by the assets preview images).
• Business Logic and Service Layer:
• This covers providers (in “lib/provider”) managing state for chat, settings, and MCP server interactions.
• There is also a “dao” (data access objects) layer (in “lib/dao”) to handle database operations and persistence (for example, storing chat history).
• LLM & MCP Communication:
• The “lib/llm” directory contains different clients for various LLM providers (OpenAI, Claude, OLLama, DeepSeek) alongside utilities and models.
• The “lib/mcp” directory shows integration with MCP protocol components, including client interfaces, models, and both SSE and stdio based communications.
• Data and Configuration Management:
• Use of SQLite (via sqflite or sqflite_common_ffi) is indicated by database files (e.g., “assets/test.db”) and initialization scripts in “lib/dao/init_db.dart”.
• There is also configuration management for the MCP server found in assets and documented in the README (“mcp_server.json”).
• Native Platform Integrations:
• Separate directories for Android, iOS, macOS, Linux, Windows highlight native configurations needed by Flutter to deploy on each platform. These include native build configurations, platform-specific assets, and project files.
Relationships and Interactions
• The UI components (chat pages, settings pages) interact with provider classes to mediate state changes and user inputs.
• These providers depend on the service layer (LLM and MCP clients) to send chat requests, retrieve responses, and update the UI.
• When user interactions require database operations (e.g., saving chat history), the provider layer makes calls to the DAO components.
• The LLM clients interact over network or local process using the MCP protocol (which could be via SSE or standard IO channels) to coordinate with external or embedded servers.
• Underlying configuration files and assets are loaded at startup to provide localization (from “lib/l10n”), UI theming (light/dark mode support), and visual previews.
Architectural Patterns and Design Principles
• Separation of concerns: clear division between UI, state management (provider), backend services (LLM/MCP clients), and persistence (DAO).
• Use of a modular architecture: subdirectories group corresponding functionalities (e.g., “llm”, “dao”, “mcp”).
• Cross-platform abstraction: Flutter code in “lib” abstracts the UI and business logic so that platform-specific folders only contain configuration and native code necessary for deployment.
• Extensibility: the layered design allows for adding new LLM providers or MCP server functionalities without major refactoring.
Relevant Technologies, Frameworks, & Libraries
• Flutter (for cross-platform UI development).
• Dart (programming language used in the “lib” directory).
• SQLite (as the database via sqflite or sqflite ffi on Linux).
• Provider or similar state management solutions in Dart.
• Native configuration files and build systems for Android (Gradle), iOS (Xcode), macOS, Linux, and Windows.
• External API integrations (e.g., OpenAI, Claude, OLLama, DeepSeek).
• UI Layer (Chat, Settings, Widgets)
• Provider Layer (State Management for Chat, Settings, MCP Server)
• Service Layer (LLM Clients, MCP Client using SSE/STDIO)
• Data Access Layer (DAO components and database)
• External Configurations/Assets and Localization Modules
• Native Integration Components (group these by Android, iOS, Desktop)
• Data flow: from the UI to providers, from providers to back-end services, and vice versa.
• Dependencies: i.e., the UI depends on providers; providers depend on DAO and network modules.
• For example, use blue rectangles for UI, green for business logic/providers, orange for service/network components, and yellow for persistence.
• Critical integration points like:
• MCP Server communication (potentially highlighting protocols like SSE).
• LLM API management and key configuration settings.
• Database interactions (via SQL and SQLite files).