# thjnn/farm2home architecture

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

- Interactive diagram: https://gitdiagram.com/thjnn/farm2home
- Repository: https://github.com/thjnn/farm2home

## Overview

FARM2HOME AI is a Laravel application coordinating produce demand with small-farm harvests, rather than simply an online vegetable shop. Customers place orders and subscriptions; farmers report available supply; operators use forecasts to review and confirm harvest plans, then receive crops, create traceable batches, and handle feedback. Admin tools also cover loyalty, waste and packaging returns, and pilot KPIs. Edges follow the README’s documented workflow and sampled controller/service calls; several broader capabilities are documented but their implementations were not sampled.

Main entry points: [`app/Http/Controllers/Farmer/FarmerPortalController.php`](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Farmer/FarmerPortalController.php) (Farmer portal), [`app/Services/HarvestPlanService.php`](https://github.com/thjnn/farm2home/blob/main/app/Services/HarvestPlanService.php) (Harvest allocation), [`app/Services/OrderService.php`](https://github.com/thjnn/farm2home/blob/main/app/Services/OrderService.php) (Order processing), [`app/Services/ForecastService.php`](https://github.com/thjnn/farm2home/blob/main/app/Services/ForecastService.php) (Demand forecasting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ordering["Customer ordering"]
  node_public_ordering["Public ordering"]
  node_order_service["Order processing<br/>[OrderService.php]"]
  node_subscriptions["Recurring baskets"]
  node_orders["Orders<br/>[Order.php]"]
  node_chatbot["Shopping chatbot<br/>[ChatbotService.php]"]
end

subgraph group_supply["Supply planning"]
  node_farmer_portal["Farmer portal"]
  node_supply_reports["Supply reporting"]
  node_forecast["Demand forecasting"]
  node_forecast_math["Forecast methods"]
  node_harvest_controller["Harvest planning"]
  node_harvest_service["Harvest allocation"]
  node_harvest_plans["Harvest plans<br/>[HarvestPlan.php]"]
end

subgraph group_traceability["Fulfillment and traceability"]
  node_batch_service["Batch and QR<br/>[BatchService.php]"]
  node_feedback["Batch feedback"]
end

subgraph group_operations["Operations"]
  node_loyalty["Loyalty points<br/>[LoyaltyService.php]"]
  node_kpi["Pilot KPIs<br/>[KpiService.php]"]
  node_waste["Waste and returns"]
end

subgraph group_platform["Application access"]
  node_app_entry["PWA entry"]
  node_database[("Application records<br/>[Order.php]")]
end

node_customer(("Customer"))
node_operator(("Operator"))
node_farmer_actor(("Farmer"))
node_gemini{{"Gemini API"}}

node_customer -->|"places order"| node_public_ordering
node_public_ordering -->|"submits order"| node_order_service
node_order_service -->|"creates order"| node_orders
node_customer -->|"sets recurrence"| node_subscriptions
node_farmer_actor -->|"reports supply"| node_farmer_portal
node_farmer_portal -->|"saves report"| node_supply_reports
node_farmer_portal -->|"views outlook"| node_forecast
node_forecast -->|"calculates forecasts"| node_forecast_math
node_operator -->|"reviews plan"| node_harvest_controller
node_harvest_controller -->|"delegates planning"| node_harvest_service
node_harvest_service -->|"uses forecast"| node_forecast
node_harvest_service -->|"updates plan"| node_harvest_plans
node_farmer_portal -->|"confirms harvest"| node_harvest_service
node_operator -->|"creates QR batches"| node_batch_service
node_customer -->|"rates batch"| node_feedback
node_customer -->|"redeems points"| node_loyalty
node_operator -->|"views metrics"| node_kpi
node_operator -->|"records waste"| node_waste
node_customer -->|"asks questions"| node_chatbot
node_chatbot -.->|"queries optionally"| node_gemini
node_customer -->|"opens app"| node_app_entry
node_app_entry -->|"redirects farmer"| node_farmer_portal
node_order_service -->|"persists orders"| node_database

click node_public_ordering "https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Public/OrderController.php"
click node_order_service "https://github.com/thjnn/farm2home/blob/main/app/Services/OrderService.php"
click node_subscriptions "https://github.com/thjnn/farm2home/blob/main/app/Services/SubscriptionService.php"
click node_orders "https://github.com/thjnn/farm2home/blob/main/app/Models/Order.php"
click node_farmer_portal "https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Farmer/FarmerPortalController.php"
click node_supply_reports "https://github.com/thjnn/farm2home/blob/main/app/Services/SupplyReportService.php"
click node_forecast "https://github.com/thjnn/farm2home/blob/main/app/Services/ForecastService.php"
click node_forecast_math "https://github.com/thjnn/farm2home/blob/main/app/Support/ForecastCalculator.php"
click node_harvest_controller "https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Admin/HarvestPlanController.php"
click node_harvest_service "https://github.com/thjnn/farm2home/blob/main/app/Services/HarvestPlanService.php"
click node_harvest_plans "https://github.com/thjnn/farm2home/blob/main/app/Models/HarvestPlan.php"
click node_batch_service "https://github.com/thjnn/farm2home/blob/main/app/Services/BatchService.php"
click node_feedback "https://github.com/thjnn/farm2home/blob/main/app/Services/FeedbackService.php"
click node_loyalty "https://github.com/thjnn/farm2home/blob/main/app/Services/LoyaltyService.php"
click node_kpi "https://github.com/thjnn/farm2home/blob/main/app/Services/KpiService.php"
click node_waste "https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Admin/WasteController.php"
click node_chatbot "https://github.com/thjnn/farm2home/blob/main/app/Services/ChatbotService.php"
click node_app_entry "https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/AppEntryController.php"
click node_database "https://github.com/thjnn/farm2home/blob/main/app/Models/Order.php"

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_public_ordering,node_order_service,node_subscriptions,node_orders,node_chatbot toneBlue
class node_farmer_portal,node_supply_reports,node_forecast,node_forecast_math,node_harvest_controller,node_harvest_service,node_harvest_plans toneAmber
class node_batch_service,node_feedback,node_gemini toneMint
class node_loyalty,node_kpi,node_waste toneRose
class node_app_entry,node_database,node_customer,node_operator,node_farmer_actor toneIndigo
```

## Components

### Customer ordering

- [Public ordering](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Public/OrderController.php): `app/Http/Controllers/Public/OrderController.php`
- [Order processing](https://github.com/thjnn/farm2home/blob/main/app/Services/OrderService.php): `app/Services/OrderService.php`
- [Recurring baskets](https://github.com/thjnn/farm2home/blob/main/app/Services/SubscriptionService.php): `app/Services/SubscriptionService.php`
- [Orders](https://github.com/thjnn/farm2home/blob/main/app/Models/Order.php): `app/Models/Order.php`
- [Shopping chatbot](https://github.com/thjnn/farm2home/blob/main/app/Services/ChatbotService.php): `app/Services/ChatbotService.php`

### Supply planning

- [Farmer portal](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Farmer/FarmerPortalController.php): `app/Http/Controllers/Farmer/FarmerPortalController.php`
- [Supply reporting](https://github.com/thjnn/farm2home/blob/main/app/Services/SupplyReportService.php): `app/Services/SupplyReportService.php`
- [Demand forecasting](https://github.com/thjnn/farm2home/blob/main/app/Services/ForecastService.php): `app/Services/ForecastService.php`
- [Forecast methods](https://github.com/thjnn/farm2home/blob/main/app/Support/ForecastCalculator.php): `app/Support/ForecastCalculator.php`
- [Harvest planning](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Admin/HarvestPlanController.php): `app/Http/Controllers/Admin/HarvestPlanController.php`
- [Harvest allocation](https://github.com/thjnn/farm2home/blob/main/app/Services/HarvestPlanService.php): `app/Services/HarvestPlanService.php`
- [Harvest plans](https://github.com/thjnn/farm2home/blob/main/app/Models/HarvestPlan.php): `app/Models/HarvestPlan.php`

### Fulfillment and traceability

- [Batch and QR](https://github.com/thjnn/farm2home/blob/main/app/Services/BatchService.php): `app/Services/BatchService.php`
- [Batch feedback](https://github.com/thjnn/farm2home/blob/main/app/Services/FeedbackService.php): `app/Services/FeedbackService.php`

### Operations

- [Loyalty points](https://github.com/thjnn/farm2home/blob/main/app/Services/LoyaltyService.php): `app/Services/LoyaltyService.php`
- [Pilot KPIs](https://github.com/thjnn/farm2home/blob/main/app/Services/KpiService.php): `app/Services/KpiService.php`
- [Waste and returns](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/Admin/WasteController.php): `app/Http/Controllers/Admin/WasteController.php`

### Application access

- [PWA entry](https://github.com/thjnn/farm2home/blob/main/app/Http/Controllers/AppEntryController.php): `app/Http/Controllers/AppEntryController.php`
- [Application records](https://github.com/thjnn/farm2home/blob/main/app/Models/Order.php): `app/Models/Order.php`

### Other components

- **Customer**
- **Operator**
- **Farmer**
- **Gemini API**

## Connections

- Customer → Public ordering: places order (evidence: `README.md`)
- Public ordering → Order processing: submits order (evidence: `app/Http/Controllers/Public/OrderController.php`)
- Order processing → Orders: creates order (evidence: `app/Services/OrderService.php`)
- Customer → Recurring baskets: sets recurrence (evidence: `README.md`)
- Farmer → Farmer portal: reports supply (evidence: `README.md`)
- Farmer portal → Supply reporting: saves report (evidence: `app/Http/Controllers/Farmer/FarmerPortalController.php`)
- Farmer portal → Demand forecasting: views outlook (evidence: `app/Http/Controllers/Farmer/FarmerPortalController.php`)
- Demand forecasting → Forecast methods: calculates forecasts (evidence: `app/Services/ForecastService.php`)
- Operator → Harvest planning: reviews plan (evidence: `README.md`)
- Harvest planning → Harvest allocation: delegates planning (evidence: `app/Http/Controllers/Admin/HarvestPlanController.php`)
- Harvest allocation → Demand forecasting: uses forecast (evidence: `app/Services/HarvestPlanService.php`)
- Harvest allocation → Harvest plans: updates plan (evidence: `app/Services/HarvestPlanService.php`)
- Farmer portal → Harvest allocation: confirms harvest (evidence: `app/Http/Controllers/Farmer/FarmerPortalController.php`)
- Operator → Batch and QR: creates QR batches (evidence: `README.md`)
- Customer → Batch feedback: rates batch (evidence: `README.md`)
- Customer → Loyalty points: redeems points (evidence: `README.md`)
- Operator → Pilot KPIs: views metrics (evidence: `README.md`)
- Operator → Waste and returns: records waste (evidence: `README.md`)
- Customer → Shopping chatbot: asks questions (evidence: `README.md`)
- Shopping chatbot → Gemini API: queries optionally (evidence: `README.md`)
- Customer → PWA entry: opens app (evidence: `app/Http/Controllers/AppEntryController.php`)
- PWA entry → Farmer portal: redirects farmer (evidence: `app/Http/Controllers/AppEntryController.php`)
- Order processing → Application records: persists orders (evidence: `app/Services/OrderService.php`)
