How zhangheng2022/onechatgpt works
Project Overview and Purpose
• OneChatGPT is an open-source multi-model AI chat platform built with Flutter. Its primary purpose is to offer a unified chat experience that integrates several large language models (OpenAI ChatGPT, Google Gemini, 百度文心一言, and 智谱 ChatGLM). Although mostly focused on Android as noted in the README, the project is set up to compile on multiple platforms (Android, iOS, macOS, Windows, Linux, and web) through Flutter’s cross-platform capabilities.
Analyzing the File Structure
• Top-Level Directories for Platforms: Notice separate directories for android, ios, macos, linux, windows, and web. This division indicates that platform-specific configurations, builds, and resources are kept isolated from the core logic.
• Core Application Code: The lib directory is the heart of the Flutter application. It is further segregated into modules like config, database, models, state, ui, services, and utilities. This modular organization suggests a clean separation between configuration, data handling, UI presentation, and business logic.
• Additional Directories: The presence of .github, pubspec.yaml, and various configuration files tells us that CI/CD pipelines, dependencies, and build instructions are managed systematically.
Key Architectural Components
a. UI Layer:
• Located primarily under the lib/ui directory.
• Contains sub-modules for authentication (login, register, forget_password), chat interface (chat_home, chat widgets), FAQ, indexing (home, person, navigation scaffold), and user info.
• This layer is responsible for rendering the responsive interface and managing user interactions.
b. Business Logic and State Management:
• The lib/state directory contains state handling for authentication, model settings, and theme management.
• Linking to UI via state management techniques (Provider, Bloc or similar) to maintain data consistency.
c. Data Layer:
• The lib/database directory holds definitions for chat records and related details, indicating local persistence (likely using SQLite or Drift-generated code).
• The lib/models folder houses data models for network communication (chat models, request and response schemas) as well as app settings.
d. Service Layer:
• Found in lib/services and includes utilities such as the dio_singleton (which likely handles API requests using the Dio HTTP client).
• This layer bridges the gap between the UI and external services/APIs (for connecting to various AI models).
e. Routing and Configuration:
f. External Services:
• Since the project integrates multiple AI models, include a component (or external APIs node) showing connections to external services like OpenAI, Google Gemini, etc.
g. Platform-Specific Modules:
• Although the business logic resides in the lib folder, native code for each platform (Android, iOS, etc.) shows integration layers. These modules handle platform-specific initialization, configuration, and resource management.
Final Touches
• That every component (including smaller widgets or utilities if they play a significant role) is clearly labeled.