How mrhgj/fluttergithub works
Main Components
• Mobile Client (Flutter App): Represent the overall Flutter app that spans both Android (android directory) and iOS (ios directory) native projects.
• UI Layer: Under “lib/routes”, “lib/widgets”, and “lib/res” are the various UI screens (login, home, search, repo detail, personal detail, etc.), custom widgets, and styling resources.
• State Management Layer: “lib/states” and “lib/common/event” are used for shared application state (using provider and event_bus) to manage theme, user profile, and locale settings.
• Business Logic / Networking: “lib/common/net” encapsulates API requests (using dio) with files like NetApi.dart and api.dart. This layer handles interactions with the external GitHub API.
• Data / Model Layer: “lib/models” and accompanying generated files (with .g.dart) hold the data representations for repositories, users, commits, events, etc.
• Local Persistence: “lib/db” for SQLite database management via “sqflite” to store history or cache data.
• Internationalization: “lib/l10n” and “l10n-arb” provide localization resources.
• Third Party Integrations: Various libraries such as cached_network_image, flutter_markdown, and webview_flutter form key external integrations.
Relationships and Interactions
• The UI Layer (screens & widgets) interacts with the State Management Layer to reflect changes in theme, locale, and user data.
• UI interacts with the Business Logic layer to fetch data from the GitHub API. Data is passed to/from the Model Layer.
• The Network layer uses API endpoints (requiring GitHub OAuth credentials provided in the “ignore.dart” file) to request data.
• Data fetched from the API can be persisted locally in the Database Layer.
• Event communication (via event_bus) connects disparate parts (like notifying UI updates upon state changes).
• The Internationalization and Theme components tie into the global configurations maintained in the State and Common layers.
Architectural Patterns and Design Principles
• MVVM/MVC-like segregations: While not a strict framework, the separation between UI (Routes and Widgets), business logic (States and Common Logic), and data (Models and Database) is a key pattern.
• Layered Architecture: Clear division from presentation (UI) down through domain logic to data and network.
• Dependency Injection / State Management: Use of provider for managing shared states.
• Reusability and Modularity: “lib/common”, “lib/widgets”, and “lib/routes” suggest a modular design with separation of concerns.