# leehack/flutter-mcp-ai-chat architecture

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

- Interactive diagram: https://gitdiagram.com/leehack/flutter-mcp-ai-chat
- Repository: https://github.com/leehack/flutter-mcp-ai-chat

## Overview

- Frontend (Flutter UI Layer):
- Visual components such as the Chat Screen (lib/chat_screen.dart) and the Settings Screen (lib/settings_screen.dart).
- That these UI elements interact with the underlying business logic.
- Business Logic and State Management:
- Components like chat_state.dart and the settings_service.dart encapsulate the application state and the logic for managing settings.
- GeminiService (lib/gemini_service.dart) as it likely handles interactions that connect the UI with external systems.
- MCP Communication Layer:
- MCP-specific components—mcp_client.dart and mcp_server_config.dart—and indicate that these modules handle the configuration, management, and communication with MCP servers (using the dart_mcp package).
- Data Storage/Local Persistence:
- Demonstrate that API keys and possibly other configuration data are handled securely using local storage (such as SharedPreferences).
- Platform-Specific Build/Deployment:
- Separate nodes or groups for Android, iOS, macOS, Linux, Windows, and web to represent the multi-platform build targets. Show that all these platform-specific directories eventually run the same underlying Flutter code.

##### Relationships and Data Flow
- UI → Business Logic:
- Business Logic ↔ MCP Communication:
- Data Storage Interaction:
- Multi-Platform Integration:

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Make it clear that the UI layer is decoupled from business logic and external communications. This separation is key to a maintainable architecture.
- Modularity and Extensibility:
- That core functionalities such as API key management, MCP server management, and custom environment variable handling are implemented as separate modules within the project.
- Multi-Platform Readiness:
- That the project contains platform-specific directories (e.g., android, ios, macos, etc.) that adapt the same underlying Flutter code to different environments.

##### Relevant Technologies and Frameworks
- Flutter Framework: Central to the UI and overall application lifecycle.
- dart_mcp Package: Used for MCP server communications.
- SharedPreferences (or similar): For storing API keys and local configuration.
- Platform-specific build and configuration tools:
- Android (Kotlin, Gradle),
- iOS/macOS (Swift/Objective-C, Xcode),
- Linux/Windows (CMake for C++ bootstrapping parts),
- Web (HTML, JavaScript glue from Flutter tooling).

## Diagram (Mermaid)

```mermaid
flowchart TD

  subgraph "Flutter App (lib)"
    %% UI Layer
    subgraph "UI Layer"
      CS("Chat Screen"):::ui
      SS("Settings Screen"):::ui
    end

    %% Business Logic & State Management Layer
    subgraph "Business Logic & State Management"
      CState("Chat State"):::business
      SService("Settings Service"):::business
      GService("Gemini Service"):::business
    end

    %% MCP Communication Layer
    subgraph "MCP Communication"
      MCPClient("MCP Client"):::mcp
      MCPConfig("MCP Server Config"):::mcp
    end

    LocalStore["Local Storage (SharedPreferences)"]:::storage

    FlutterCore["Flutter App Code"]:::core
  end

  %% Platform-Specific Build Targets
  subgraph "Platform-Specific Build Targets"
    Android("Android Build"):::platform
    iOS("iOS Build"):::platform
    macOS("macOS Build"):::platform
    Linux("Linux Build"):::platform
    Windows("Windows Build"):::platform
    Web("Web Build"):::platform
  end

  %% Relationships and Data Flow
  CS -->|"triggers"| CState
  SS -->|"updates"| SService
  SService -->|"persists"| LocalStore
  GService <-->|"communicates"| MCPClient
  GService <-->|"configures"| MCPConfig

  %% Deployment Flow from Flutter App to Platforms
  FlutterCore -->|"deployed_on"| Android
  FlutterCore -->|"deployed_on"| iOS
  FlutterCore -->|"deployed_on"| macOS
  FlutterCore -->|"deployed_on"| Linux
  FlutterCore -->|"deployed_on"| Windows
  FlutterCore -->|"deployed_on"| Web

  %% Click Events
  click CS "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/chat_screen.dart"
  click SS "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/settings_screen.dart"
  click CState "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/chat_state.dart"
  click SService "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/settings_service.dart"
  click GService "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/gemini_service.dart"
  click MCPClient "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/mcp_client.dart"
  click MCPConfig "https://github.com/leehack/flutter-mcp-ai-chat/blob/main/lib/mcp_server_config.dart"
  click Android "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/android/"
  click iOS "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/ios/"
  click macOS "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/macos/"
  click Linux "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/linux/"
  click Windows "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/windows/"
  click Web "https://github.com/leehack/flutter-mcp-ai-chat/tree/main/web/"

  %% Styles
  classDef ui fill:#cce5ff,stroke:#00579C,stroke-width:2px;
  classDef business fill:#d4edda,stroke:#155724,stroke-width:2px;
  classDef mcp fill:#fff3cd,stroke:#856404,stroke-width:2px;
  classDef storage fill:#f8d7da,stroke:#721c24,stroke-width:2px;
  classDef core fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
  classDef platform fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
