How khuongkayyyyy/green_fairm works
Project type and purpose
• This is a full-stack, cross-platform farm management application.
• Frontend is a Flutter app (mobile, web, desktop).
• Backend is implemented as Firebase services (Authentication, Firestore, Cloud Functions) plus external integrations (MQTT sensor network, Weather API, custom ML).
• It provides real-time environmental monitoring, satellite imagery, AI-driven recommendations, and water-usage forecasting.
File structure
• Top-level “android/”, “ios/”, “web/”, “linux/”, “macos/”, “windows/” directories → Flutter platform targets.
• “lib/” → Flutter app code, organized by Clean Architecture:
• core/ (constants, services, utilities)
• data/ (models, repositories)
• presentation/ (BLoC state management, views)
• main.dart
• “functions/” → Node.js Cloud Functions (backend logic, REST endpoints, triggers).
• “assets/” and “public/” → static images, hosting assets.
• Firebase config files: firebase.json, storage.rules, remoteconfig.template.json, apphosting.yaml.
• Third-party configs: mqtt.dart integration under presentation/view/mqtt.dart.
Extract architecture hints from README
• Tech stack: Flutter frontend; NestJS (implied) or Node.js functions; Firebase Authentication; MongoDB (if used by backend); external Weather API; MQTT broker.
• Features listing confirms real-time data flow (MQTT → app), REST/API calls (Weather API), ML/AI inference (Gemini/ML model).
a. Frontend (Flutter app)
• Presentation layer (Widgets + BLoC)
• Data layer (Repositories)
• Core services (FirestoreService, LocalStorageService, NotiService)
b. Backend services
• Firebase Authentication
• Firebase Firestore (NoSQL database)
• Firebase Cloud Functions (Node.js / NestJS)
• (Optional) MongoDB if external to Firestore
c. External systems
• MQTT Broker (sensor network)
• Weather API provider
• ML/AI service (Gemini assistant or custom TensorFlow model)
• Satellite imagery service
d. Deployment & hosting
• Firebase Hosting (web assets)
• Platform-specific app stores (Android/iOS stores, desktop installers)
Relationships and interactions
• Flutter → Firebase Auth: sign-in/up, token-based calls.
• Flutter → Firestore: CRUD operations for user, field, sensor, water history.
• Flutter → Cloud Functions: HTTP triggers for machine-learning inference, notifications, satellite imagery requests.
• MQTT Broker ↔ Cloud Functions (or Flutter directly): sensor publishes telemetry → Functions subscribe or app subscribes.
• Cloud Functions → External Weather API: HTTP REST calls for forecast data.
• Cloud Functions → ML Model: invoke prediction endpoint or embedded logic.
• Flutter ← Remote Config: feature flags, app settings.
Architectural patterns & principles
• Clean Architecture in Flutter: separation of UI (presentation), domain/data, infrastructure.
• BLoC for state management → event-state mapping.
• Publish/Subscribe for real-time MQTT data.
• Serverless microservices using Cloud Functions.
• Layered approach: UI ↔ BLoC ↔ Repository ↔ Service ↔ Backend.
• Deployments (mobile devices, Firebase region, third-party API).
• Cross-platform nature: mobile, web, desktop targets all point to the same backend.
• You capture Clean Architecture layers inside the Flutter container.