# tech18arun-stack/agri_flow architecture

> Architecture diagram of the GitHub repository tech18arun-stack/agri_flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tech18arun-stack/agri_flow
- Repository: https://github.com/tech18arun-stack/agri_flow

## Overview

#### 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: [`lib/main.dart`](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/main.dart) (App composition), [`lib/services/appwrite_service.dart`](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_service.dart) (Appwrite access), [`lib/services/appwrite_config.dart`](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_config.dart) (Appwrite backend), [`lib/providers/product_provider.dart`](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/product_provider.dart) (Catalog state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flutter["Flutter app"]
  node_platforms{{"Platform launchers<br/>Flutter targets"}}
  node_main["App composition<br/>Flutter entry<br/>[main.dart]"]
  node_presentation_core["Presentation core<br/>theme and responsive UI<br/>[app_theme.dart]"]
  node_auth_provider["Auth state<br/>Provider<br/>[auth_provider.dart]"]
end

subgraph group_roles["Role experiences"]
  node_role_onboarding["Role onboarding<br/>auth screen"]
  node_farmer_shell["Farmer experience<br/>role shell<br/>[farmer_screen.dart]"]
  node_merchant_shell["Merchant experience<br/>role shell"]
  node_customer_shell["Customer experience<br/>role shell"]
  node_admin_ui["Admin control surface<br/>web admin UI<br/>[web_admin.dart]"]
end

subgraph group_marketplace["Marketplace domain"]
  node_market_models["Marketplace models<br/>shared models<br/>[models.dart]"]
  node_catalog_provider["Catalog state<br/>Product Provider"]
  node_cart_provider["Persistent cart<br/>Provider"]
  node_order_provider["Order state<br/>Provider"]
  node_inventory_provider["Inventory state<br/>Provider"]
  node_checkout["Checkout<br/>customer flow"]
end

subgraph group_pricing["Smart Mandi pricing"]
  node_price_engine["Price engine<br/>domain logic<br/>[price_engine.dart]"]
  node_price_provider["Price intelligence state<br/>Provider"]
  node_farmer_price_input["Farmer price suggestion<br/>farmer feature"]
  node_public_prices["Public price views<br/>price screens"]
end

subgraph group_backend["Backend and operations"]
  node_auth_service["Authentication service<br/>[auth_service.dart]"]
  node_appwrite_service["Appwrite access<br/>service abstraction"]
  node_appwrite[("Appwrite backend<br/>auth, database, storage")]
  node_aggregation_function["Price aggregation<br/>Appwrite function"]
  node_integrations["Device integrations<br/>location, map, notifications"]
  node_bootstrap_data["Catalog templates<br/>static bootstrap data"]
  node_operations["Appwrite operations<br/>Python provisioning<br/>[setup_appwrite.py]"]
end

node_platforms -->|"launches"| node_main
node_main -->|"uses"| node_presentation_core
node_main -->|"routes through"| node_auth_provider
node_auth_provider -->|"delegates auth"| node_auth_service
node_auth_service -->|"authenticates with"| node_appwrite
node_auth_provider -->|"drives"| node_role_onboarding
node_main -->|"routes farmer"| node_farmer_shell
node_main -->|"routes merchant"| node_merchant_shell
node_main -->|"routes customer"| node_customer_shell
node_main -->|"routes web admin"| node_admin_ui
node_catalog_provider -->|"manages"| node_market_models
node_cart_provider -->|"persists cart"| node_market_models
node_order_provider -->|"manages orders"| node_market_models
node_inventory_provider -->|"manages inventory"| node_market_models
node_customer_shell -->|"browses"| node_catalog_provider
node_customer_shell -->|"uses"| node_cart_provider
node_checkout -->|"checks out"| node_cart_provider
node_checkout -->|"creates order"| node_order_provider
node_merchant_shell -->|"manages"| node_inventory_provider
node_farmer_shell -->|"manages products"| node_inventory_provider
node_catalog_provider -->|"loads and saves"| node_appwrite_service
node_order_provider -->|"loads and saves"| node_appwrite_service
node_inventory_provider -->|"loads and saves"| node_appwrite_service
node_appwrite_service -->|"accesses"| node_appwrite
node_farmer_price_input -->|"submits price inputs"| node_price_engine
node_price_engine -->|"writes price logs"| node_appwrite
node_appwrite -->|"triggers"| node_aggregation_function
node_aggregation_function -->|"persists aggregates and trends"| node_appwrite
node_price_provider -->|"reads intelligence"| node_appwrite_service
node_farmer_shell -->|"uses recommendations"| node_price_provider
node_public_prices -->|"displays trends"| node_price_provider
node_admin_ui -->|"governs platform data"| node_appwrite_service
node_operations -.->|"provisions and migrates"| node_appwrite
node_bootstrap_data -.->|"seeds templates"| node_catalog_provider

click node_main "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/main.dart"
click node_presentation_core "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/core/theme/app_theme.dart"
click node_auth_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/auth_provider.dart"
click node_auth_service "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/auth_service.dart"
click node_role_onboarding "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/auth/role_onboarding_screen.dart"
click node_farmer_shell "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/farmer/farmer_screen.dart"
click node_merchant_shell "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/merchant/merchant_screen.dart"
click node_customer_shell "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/customer/customer_screen.dart"
click node_admin_ui "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/web_admin.dart"
click node_market_models "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/data/models.dart"
click node_catalog_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/product_provider.dart"
click node_cart_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/cart_persistence_provider.dart"
click node_order_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/order_provider.dart"
click node_inventory_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/inventory_provider.dart"
click node_checkout "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/customer/features/checkout_screen.dart"
click node_price_engine "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/data/price_engine.dart"
click node_price_provider "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/price_engine_provider.dart"
click node_farmer_price_input "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/farmer/features/farmer_add_product_tab.dart"
click node_public_prices "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/flower_price/flower_price_public_screen.dart"
click node_appwrite_service "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_service.dart"
click node_appwrite "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_config.dart"
click node_aggregation_function "https://github.com/tech18arun-stack/agri_flow/blob/main/appwrite_functions/update_aggregated_prices.js"
click node_integrations "https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/location_service.dart"
click node_bootstrap_data "https://github.com/tech18arun-stack/agri_flow/blob/main/assets/data/product_templates.json"
click node_operations "https://github.com/tech18arun-stack/agri_flow/blob/main/scripts/setup_appwrite.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_platforms,node_main,node_presentation_core,node_auth_provider toneBlue
class node_role_onboarding,node_farmer_shell,node_merchant_shell,node_customer_shell,node_admin_ui toneAmber
class node_market_models,node_catalog_provider,node_cart_provider,node_order_provider,node_inventory_provider,node_checkout toneMint
class node_price_engine,node_price_provider,node_farmer_price_input,node_public_prices toneRose
class node_auth_service,node_appwrite_service,node_appwrite,node_aggregation_function,node_integrations,node_bootstrap_data,node_operations toneIndigo
```

## Components

### Flutter app

Shared responsive client across supported platforms.

- **Platform launchers**: Flutter targets · Android, iOS, web, Linux, macOS, and Windows launch the shared app.
- [App composition](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/main.dart): Flutter entry · Initializes the app, role routing, and web-admin versus mobile UI. · `lib/main.dart`
- [Presentation core](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/core/theme/app_theme.dart): theme and responsive UI · Shared theme, strings, and responsive conventions. · `lib/core/theme/app_theme.dart`
- [Auth state](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/auth_provider.dart): Provider · Client control layer for identity and role state. · `lib/providers/auth_provider.dart`

### Role experiences

- [Role onboarding](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/auth/role_onboarding_screen.dart): auth screen · `lib/ui/screens/auth/role_onboarding_screen.dart`
- [Farmer experience](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/farmer/farmer_screen.dart): role shell · `lib/ui/screens/farmer/farmer_screen.dart`
- [Merchant experience](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/merchant/merchant_screen.dart): role shell · `lib/ui/screens/merchant/merchant_screen.dart`
- [Customer experience](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/customer/customer_screen.dart): role shell · `lib/ui/screens/customer/customer_screen.dart`
- [Admin control surface](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/web_admin.dart): web admin UI · Privileged oversight for users, catalog, moderation, orders, analytics, prices, and notifications. · `lib/ui/web_admin.dart`

### Marketplace domain

- [Marketplace models](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/data/models.dart): shared models · Products, inventory, carts, orders, harvests, and transactions. · `lib/data/models.dart`
- [Catalog state](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/product_provider.dart): Product Provider · `lib/providers/product_provider.dart`
- [Persistent cart](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/cart_persistence_provider.dart): Provider · `lib/providers/cart_persistence_provider.dart`
- [Order state](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/order_provider.dart): Provider · `lib/providers/order_provider.dart`
- [Inventory state](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/inventory_provider.dart): Provider · `lib/providers/inventory_provider.dart`
- [Checkout](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/customer/features/checkout_screen.dart): customer flow · `lib/ui/screens/customer/features/checkout_screen.dart`

### Smart Mandi pricing

- [Price engine](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/data/price_engine.dart): domain logic · Builds price-log inputs and price intelligence over marketplace data. · `lib/data/price_engine.dart`
- [Price intelligence state](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/providers/price_engine_provider.dart): Provider · Exposes comparisons, trends, and recommendations. · `lib/providers/price_engine_provider.dart`
- [Farmer price suggestion](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/farmer/features/farmer_add_product_tab.dart): farmer feature · `lib/ui/screens/farmer/features/farmer_add_product_tab.dart`
- [Public price views](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/ui/screens/flower_price/flower_price_public_screen.dart): price screens · Farmer and customer price consumption boundary. · `lib/ui/screens/flower_price/flower_price_public_screen.dart`

### Backend and operations

- [Authentication service](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/auth_service.dart): service · `lib/services/auth_service.dart`
- [Appwrite access](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_service.dart): service abstraction · Backend access for database, storage, and remote operations. · `lib/services/appwrite_service.dart`
- [Appwrite backend](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/appwrite_config.dart): auth, database, storage · Primary remote boundary with permission enforcement. · `lib/services/appwrite_config.dart`
- [Price aggregation](https://github.com/tech18arun-stack/agri_flow/blob/main/appwrite_functions/update_aggregated_prices.js): Appwrite function · Aggregates price logs into persisted prices and trends. · `appwrite_functions/update_aggregated_prices.js`
- [Device integrations](https://github.com/tech18arun-stack/agri_flow/blob/main/lib/services/location_service.dart): location, map, notifications · `lib/services/location_service.dart`
- [Catalog templates](https://github.com/tech18arun-stack/agri_flow/blob/main/assets/data/product_templates.json): static bootstrap data · Initial catalog and product-template data. · `assets/data/product_templates.json`
- [Appwrite operations](https://github.com/tech18arun-stack/agri_flow/blob/main/scripts/setup_appwrite.py): Python provisioning · Setup, migrations, seeding, permissions, and verification. · `scripts/setup_appwrite.py`

## Connections

- 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
