How homsai-smart-home/homsai-app works
Main Components
• Presentation (UI) Layer:
• Flutter pages and widgets, which reside under the lib/ui directory.
• Screens such as login, dashboard, add plant, add sensor, scan, and more.
• Auto_route usage for navigation and route generation (e.g., lib/app.router.dart, lib/app.router.gr.dart).
• Business Logic Layer:
• Centers around the BLoC pattern implementation. This layer is found in lib/business and parts of lib/ui (where BLoC classes are defined for each page).
• Covers domain-specific features such as home assistant integration, AI service processing, sensor and light management, and authentication.
• Use of dependency injection via get_it to wire up services.
• Data Access (Persistence and Communication) Layer:
• Represents local storage (using sqflite, Floor, and related DAOs under lib/datastore/local) and remote data interactions.
• Contains remote API interactions using HTTP and WebSocket. Look in lib/datastore/remote for REST and websocket-related repositories.
• Includes data transfer objects (DTOs) for both remote (HTTP/Websocket) and local database communication, based on the organized DTO folders.
• Contains models for home assistant, sensor entities, and other domain-specific data.
• External Services and Libraries:
• External integrations like flutter_web_auth, connectivity_plus, network_info_plus, url_launcher, and third-party packages for animations, charts, and localization.
• Platform-specific Modules:
• Native Android and iOS modules (directories “android” and “ios”) that handle platform-specific configuration, deployment, and integration with native services like splash screens.
Relationships and Interactions
• The Business Logic layer communicates with the Data Access tier by calling repository methods to fetch, persist, or update data. Both local (database) and remote (REST/WebSocket) services should be depicted.
• The dependency injection (using get_it) centrally manages the instantiation and wiring between the UI, business, and data layers—this can be shown as an “Infrastructure/DI” component that connects these layers.
Architectural Patterns and Key Design Principles
• Use the BLoC pattern as a primary mechanism for state management; clearly indicate that UI components send events which are processed by BLoCs that then react and update the UI.
• Separation of concerns between the presentation, business logic, and data layers.
• Mention the use of dependency injection (get_it) to decouple components.
• Local caching or persistence via SQFLite-related components (using Floor as an ORM-like abstraction).
• Routing and navigation pattern managed by auto_route as a separate navigation module.
Relevant Technologies and Frameworks
• Flutter as the base framework.
• BLoC, flutter_bloc, and bloc_concurrency for state management.
• Dependency Injection via get_it.
• Persistence: sqflite, Floor.
• Networking: http and WebSocket components.
• Localization: intl, flutter_localizations, and auto-generated l10n files.
• External utilities for animations (rive), charts (fl_chart), and SVG rendering.
Specific Elements
• Clear labels for each component (e.g., “UI Layer – Dashboard Page”, “Business Logic – Home Assistant Service”, “Data Access – REST Repository”, “Local Database – Floor ORM”).
• Annotations to indicate dependency injection handling and routing logic (auto_route).
• Within each layer, further decompose into sub-components (e.g., list out the relevant pages/widgets, BLoC components, and repository modules).
• External interactions (e.g., API endpoints, WebSocket connections, local database) as separate modules that connect into the Data Access layer.