How tech18arun-stack/agri_flow works
Purpose and Runtime
Farm Flow is a responsive, bilingual Flutter marketplace for Tamil Nadu agriculture. It supports farmer, merchant, customer, and administrator workflows, including a market-price intelligence feature. The shared Flutter application runs on Android, iOS, web, Linux, macOS, and Windows; platform launchers live under android/, ios/, web/, linux/, macos/, and windows/.
Application Entry and Composition
lib/main.dart is the application entry point and responsive composition boundary. It initializes the Flutter app, routes users into role-appropriate experiences, and selects web-admin versus mobile-oriented UI behavior. Core presentation conventions are centralized in:
• lib/core/theme/app_theme.dart
• lib/core/constants/strings.dart
• lib/core/utils/responsive.dart
The UI is organized primarily by user role rather than by a generic feature module hierarchy.
Identity, Role Routing, and Session State
Authentication and role onboarding establish the user’s destination and allowed workflow. Provider state is the client-side control layer between screens and remote services:
• lib/providers/auth_provider.dart
• lib/services/auth_service.dart
• lib/ui/screens/auth/role_onboarding_screen.dart
After sign-in, role shells separate farmer, merchant, customer, and administrator navigation:
• lib/ui/screens/farmer/farmer_screen.dart
• lib/ui/screens/merchant/merchant_screen.dart
• lib/ui/screens/customer/customer_screen.dart
Marketplace Catalog and Transaction Flows
Products, inventory, carts, wishlists, orders, harvests, and transactions are represented through providers backed by shared data models and Appwrite services. The central flow is: sellers create/manage products and inventory; customers browse/search, add items to a persistent cart, check out, and view orders; merchants support wholesale buying and selling.
• lib/data/models.dart
• lib/providers/product_provider.dart
• lib/providers/cart_persistence_provider.dart
• lib/providers/order_provider.dart
• lib/providers/inventory_provider.dart
• lib/ui/screens/customer/features/checkout_screen.dart
• lib/ui/screens/merchant/features/inventory_management_screen.dart
Smart Mandi Price Pipeline
The price engine is a separate domain layer over marketplace product data. Farmer price/product actions produce price-log inputs; an Appwrite function calculates persisted aggregate and trend records; providers expose comparisons, trends, and recommendations to each role’s UI.
• lib/data/price_engine.dart
• lib/providers/price_engine_provider.dart
• lib/providers/flower_price_provider.dart
• appwrite_functions/update_aggregated_prices.js
The intended remote-data flow is price_logs → aggregation function → aggregated prices/trends → Flutter providers/screens. Farmer-facing price suggestion and public/customer price views are key consumption boundaries:
• lib/ui/screens/farmer/features/farmer_add_product_tab.dart
• lib/ui/screens/flower_price/flower_price_public_screen.dart
• lib/ui/screens/customer/features/flower_prices_public_screen.dart
Backend, External Services, and Operational Boundary
Appwrite is the primary backend boundary for authentication, database/storage access, and server-side price aggregation. Flutter code should depend on service abstractions rather than embedding backend details in screens:
• lib/services/appwrite_config.dart
• lib/services/appwrite_service.dart
• lib/services/config_service.dart
Location, mapping, and notifications are external/device-service integrations:
• lib/services/location_service.dart
• lib/services/map_service.dart
• lib/services/notification_service.dart
Backend provisioning, schema evolution, seed data, permissions, and verification are managed outside the app runtime through Python scripts:
• scripts/setup_appwrite.py
• scripts/migrations/run_migrations.py
• scripts/seed_appwrite.py
Administration and Governance
Administration is a distinct control surface for platform oversight: users, catalog, moderation, orders, analytics, price updates, and push notifications. It shares providers/services with the app but represents privileged workflows and likely requires backend permission enforcement.
• lib/ui/web_admin.dart
• lib/ui/screens/admin/admin_dashboard.dart
• lib/ui/screens/admin/admin_moderation.dart
• lib/ui/screens/admin/admin_price_updaters_screen.dart
Static bootstrap/configuration data supports initial catalog and product-template behavior:
• assets/data/config.json
• assets/data/product_templates.json
• lib/services/product_template_service.dart
Main entry points: main.dart App composition · appwrite_service.dart Appwrite access · appwrite_config.dart Appwrite backend · product_provider.dart Catalog state
Components 26
Flutter app
Shared responsive client across supported platforms.
- Platform launchers · Android, iOS, web, Linux, macOS, and Windows launch the shared app.
- App composition · Initializes the app, role routing, and web-admin versus mobile UI.
lib/main.dart - Presentation core · Shared theme, strings, and responsive conventions.
lib/core/theme/app_theme.dart - Auth state · Client control layer for identity and role state.
lib/providers/auth_provider.dart
Role experiences
- Role onboarding
lib/ui/screens/auth/role_onboarding_screen.dart - Farmer experience
lib/ui/screens/farmer/farmer_screen.dart - Merchant experience
lib/ui/screens/merchant/merchant_screen.dart - Customer experience
lib/ui/screens/customer/customer_screen.dart - Admin control surface · Privileged oversight for users, catalog, moderation, orders, analytics, prices, and notifications.
lib/ui/web_admin.dart
Marketplace domain
- Marketplace models · Products, inventory, carts, orders, harvests, and transactions.
lib/data/models.dart - Catalog state
lib/providers/product_provider.dart - Persistent cart
lib/providers/cart_persistence_provider.dart - Order state
lib/providers/order_provider.dart - Inventory state
lib/providers/inventory_provider.dart - Checkout
lib/ui/screens/customer/features/checkout_screen.dart
Smart Mandi pricing
- Price engine · Builds price-log inputs and price intelligence over marketplace data.
lib/data/price_engine.dart - Price intelligence state · Exposes comparisons, trends, and recommendations.
lib/providers/price_engine_provider.dart - Farmer price suggestion
lib/ui/screens/farmer/features/farmer_add_product_tab.dart - Public price views · Farmer and customer price consumption boundary.
lib/ui/screens/flower_price/flower_price_public_screen.dart
Backend and operations
- Authentication service
lib/services/auth_service.dart - Appwrite access · Backend access for database, storage, and remote operations.
lib/services/appwrite_service.dart - Appwrite backend · Primary remote boundary with permission enforcement.
lib/services/appwrite_config.dart - Price aggregation · Aggregates price logs into persisted prices and trends.
appwrite_functions/update_aggregated_prices.js - Device integrations
lib/services/location_service.dart - Catalog templates · Initial catalog and product-template data.
assets/data/product_templates.json - Appwrite operations · Setup, migrations, seeding, permissions, and verification.
scripts/setup_appwrite.py
Connections 34
- Platform launchers → App composition: launches
- App composition → Presentation core: uses
- App composition → Auth state: routes through
- Auth state → Authentication service: delegates auth
- Authentication service → Appwrite backend: authenticates with
- Auth state → Role onboarding: drives
- App composition → Farmer experience: routes farmer
- App composition → Merchant experience: routes merchant
- App composition → Customer experience: routes customer
- App composition → Admin control surface: routes web admin
- Catalog state → Marketplace models: manages
- Persistent cart → Marketplace models: persists cart
- Order state → Marketplace models: manages orders
- Inventory state → Marketplace models: manages inventory
- Customer experience → Catalog state: browses
- Customer experience → Persistent cart: uses
- Checkout → Persistent cart: checks out
- Checkout → Order state: creates order
- Merchant experience → Inventory state: manages
- Farmer experience → Inventory state: manages products
- Catalog state → Appwrite access: loads and saves
- Order state → Appwrite access: loads and saves
- Inventory state → Appwrite access: loads and saves
- Appwrite access → Appwrite backend: accesses
- Farmer price suggestion → Price engine: submits price inputs
- Price engine → Appwrite backend: writes price logs
- Appwrite backend → Price aggregation: triggers
- Price aggregation → Appwrite backend: persists aggregates and trends
- Price intelligence state → Appwrite access: reads intelligence
- Farmer experience → Price intelligence state: uses recommendations
- Public price views → Price intelligence state: displays trends
- Admin control surface → Appwrite access: governs platform data
- Appwrite operations → Appwrite backend: provisions and migrates
- Catalog templates → Catalog state: seeds templates