# rahul-irs/farm_direct architecture

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

- Interactive diagram: https://gitdiagram.com/rahul-irs/farm_direct
- Repository: https://github.com/rahul-irs/farm_direct

## Overview

FarmDirect AI is a role-based agricultural marketplace and supply-chain operations platform. The main buyer journey is marketplace browsing and cart checkout, followed by server-side stock validation, multi-supplier order allocation, development payment records, farmer fulfillment, logistics delivery and tracking, and buyer notifications. The graph also preserves authentication, partner/FPO operations, AI forecasts, reviews, and administration. Relationships are based on the README, shown excerpts, and SOURCE INDEX references; unsampled route implementations are represented at their exact listed paths without inferring their internal call chains.

Main entry points: [`frontend/src/services/api.js`](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/services/api.js) (HTTP API client), [`frontend/src/App.jsx`](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/App.jsx) (Role-based routing), [`backend/app/routes/orders.py`](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/orders.py) (Cart and orders), [`backend/app/models/order.py`](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/order.py) (Order allocations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend experience"]
  node_react_app["Role-based routing<br/>[App.jsx]"]
  node_buyer_pages["Buyer marketplace"]
  node_buyer_checkout["Cart and orders UI<br/>[CartPage.jsx]"]
  node_farmer_pages["Farmer operations UI"]
  node_partner_pages["Partner operations UI"]
  node_logistics_pages["Logistics UI"]
  node_api_client["HTTP API client<br/>[api.js]"]
end

subgraph group_commerce["Commerce workflow"]
  node_auth_routes["Authentication<br/>[auth.py]"]
  node_catalog_routes["Product catalogue<br/>[products.py]"]
  node_order_routes["Cart and orders<br/>[orders.py]"]
  node_payment_routes["Payment records<br/>[payments.py]"]
  node_review_routes["Purchase reviews<br/>[reviews.py]"]
end

subgraph group_operations["Supply chain operations"]
  node_partner_routes["FPO and bulk buying<br/>[partners.py]"]
  node_logistics_routes["Delivery and tracking<br/>[logistics.py]"]
  node_notifications_routes["Notifications<br/>[notifications.py]"]
  node_ai_routes["AI forecasts<br/>[ai.py]"]
end

subgraph group_platform["Platform services"]
  node_user_model["User accounts<br/>[user.py]"]
  node_product_model["Product inventory<br/>[product.py]"]
  node_order_model["Order allocations<br/>[order.py]"]
  node_logistics_model["Delivery records<br/>[logistics.py]"]
  node_partner_model["Partner records<br/>[partners.py]"]
  node_review_model["Review records<br/>[review.py]"]
  node_database[("PostgreSQL database")]
  node_flask_app["Flask API setup<br/>[__init__.py]"]
end

node_buyers(("Buyers"))
node_farmers(("Farmers"))
node_logistics_partner(("Logistics partners"))

node_buyers -->|"use application"| node_react_app
node_farmers -->|"use application"| node_react_app
node_logistics_partner -->|"use application"| node_react_app
node_react_app -->|"routes to"| node_buyer_pages
node_react_app -->|"routes to"| node_farmer_pages
node_react_app -->|"routes to"| node_partner_pages
node_react_app -->|"routes to"| node_logistics_pages
node_buyer_pages -.->|"requests data"| node_api_client
node_buyer_checkout -.->|"checks out"| node_api_client
node_farmer_pages -->|"requests data"| node_api_client
node_partner_pages -->|"requests data"| node_api_client
node_logistics_pages -->|"requests data"| node_api_client
node_api_client -->|"calls API"| node_auth_routes
node_api_client -->|"calls API"| node_catalog_routes
node_api_client -->|"calls API"| node_order_routes
node_api_client -->|"calls API"| node_payment_routes
node_api_client -->|"calls API"| node_logistics_routes
node_api_client -->|"calls API"| node_notifications_routes
node_api_client -->|"calls API"| node_ai_routes
node_api_client -->|"calls API"| node_partner_routes
node_flask_app -->|"registers routes"| node_auth_routes
node_flask_app -->|"registers routes"| node_order_routes
node_flask_app -->|"registers routes"| node_catalog_routes
node_flask_app -->|"registers routes"| node_partner_routes
node_flask_app -->|"registers routes"| node_logistics_routes
node_order_routes -->|"reads and writes"| node_order_model
node_order_routes -->|"validates stock"| node_product_model
node_order_routes -->|"coordinates delivery"| node_logistics_model
node_order_routes -->|"uses partner data"| node_partner_model
node_logistics_routes -->|"updates delivery"| node_logistics_model
node_logistics_routes -->|"updates order"| node_order_model
node_logistics_routes -.->|"creates notifications"| node_notifications_routes
node_review_routes -->|"creates reviews"| node_review_model
node_review_routes -->|"checks purchase"| node_order_model
node_auth_routes -->|"manages accounts"| node_user_model
node_partner_routes -->|"manages partners"| node_partner_model
node_partner_routes -->|"uses inventory"| node_product_model
node_partner_routes -->|"uses orders"| node_order_model
node_catalog_routes -.->|"manages catalogue"| node_product_model
node_payment_routes -.->|"records payment"| node_order_model
node_notifications_routes -.->|"persists records"| node_database
node_ai_routes -.->|"reads history"| node_database
node_user_model -->|"persists accounts"| node_database
node_product_model -->|"persists inventory"| node_database
node_order_model -->|"persists orders"| node_database
node_logistics_model -->|"persists tracking"| node_database
node_partner_model -->|"persists memberships"| node_database
node_review_model -.->|"persists reviews"| node_database

click node_react_app "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/App.jsx"
click node_buyer_pages "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/consumer/MarketplacePage.jsx"
click node_buyer_checkout "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/consumer/CartPage.jsx"
click node_farmer_pages "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/farmer/FarmerProductsPage.jsx"
click node_partner_pages "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/partners/PartnerDashboardPage.jsx"
click node_logistics_pages "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/logistics/LogisticsDashboardPage.jsx"
click node_api_client "https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/services/api.js"
click node_auth_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/auth.py"
click node_catalog_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/products.py"
click node_order_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/orders.py"
click node_payment_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/payments.py"
click node_review_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/reviews.py"
click node_partner_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/partners.py"
click node_logistics_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/logistics.py"
click node_notifications_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/notifications.py"
click node_ai_routes "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/ai.py"
click node_user_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/user.py"
click node_product_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/product.py"
click node_order_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/order.py"
click node_logistics_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/logistics.py"
click node_partner_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/partners.py"
click node_review_model "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/review.py"
click node_flask_app "https://github.com/rahul-irs/farm_direct/blob/main/backend/app/__init__.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_react_app,node_buyer_pages,node_buyer_checkout,node_farmer_pages,node_partner_pages,node_logistics_pages,node_api_client toneBlue
class node_auth_routes,node_catalog_routes,node_order_routes,node_payment_routes,node_review_routes toneAmber
class node_partner_routes,node_logistics_routes,node_notifications_routes,node_ai_routes toneMint
class node_user_model,node_product_model,node_order_model,node_logistics_model,node_partner_model,node_review_model,node_database,node_flask_app toneRose
class node_buyers,node_farmers,node_logistics_partner toneIndigo
```

## Components

### Frontend experience

- [Role-based routing](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Buyer marketplace](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/consumer/MarketplacePage.jsx): `frontend/src/pages/consumer/MarketplacePage.jsx`
- [Cart and orders UI](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/consumer/CartPage.jsx): `frontend/src/pages/consumer/CartPage.jsx`
- [Farmer operations UI](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/farmer/FarmerProductsPage.jsx): `frontend/src/pages/farmer/FarmerProductsPage.jsx`
- [Partner operations UI](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/partners/PartnerDashboardPage.jsx): `frontend/src/pages/partners/PartnerDashboardPage.jsx`
- [Logistics UI](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/pages/logistics/LogisticsDashboardPage.jsx): `frontend/src/pages/logistics/LogisticsDashboardPage.jsx`
- [HTTP API client](https://github.com/rahul-irs/farm_direct/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Commerce workflow

- [Authentication](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/auth.py): `backend/app/routes/auth.py`
- [Product catalogue](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/products.py): `backend/app/routes/products.py`
- [Cart and orders](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/orders.py): `backend/app/routes/orders.py`
- [Payment records](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/payments.py): `backend/app/routes/payments.py`
- [Purchase reviews](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/reviews.py): `backend/app/routes/reviews.py`

### Supply chain operations

- [FPO and bulk buying](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/partners.py): `backend/app/routes/partners.py`
- [Delivery and tracking](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/logistics.py): `backend/app/routes/logistics.py`
- [Notifications](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/notifications.py): `backend/app/routes/notifications.py`
- [AI forecasts](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/routes/ai.py): `backend/app/routes/ai.py`

### Platform services

- [User accounts](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/user.py): `backend/app/models/user.py`
- [Product inventory](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/product.py): `backend/app/models/product.py`
- [Order allocations](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/order.py): `backend/app/models/order.py`
- [Delivery records](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/logistics.py): `backend/app/models/logistics.py`
- [Partner records](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/partners.py): `backend/app/models/partners.py`
- [Review records](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/models/review.py): `backend/app/models/review.py`
- **PostgreSQL database**
- [Flask API setup](https://github.com/rahul-irs/farm_direct/blob/main/backend/app/__init__.py): `backend/app/__init__.py`

### Other components

- **Buyers**
- **Farmers**
- **Logistics partners**

## Connections

- Buyers → Role-based routing: use application (evidence: `README.md`)
- Farmers → Role-based routing: use application (evidence: `README.md`)
- Logistics partners → Role-based routing: use application (evidence: `README.md`)
- Role-based routing → Buyer marketplace: routes to (evidence: `frontend/src/App.jsx`)
- Role-based routing → Farmer operations UI: routes to (evidence: `frontend/src/App.jsx`)
- Role-based routing → Partner operations UI: routes to (evidence: `frontend/src/App.jsx`)
- Role-based routing → Logistics UI: routes to (evidence: `frontend/src/App.jsx`)
- Buyer marketplace → HTTP API client: requests data
- Cart and orders UI → HTTP API client: checks out
- Farmer operations UI → HTTP API client: requests data (evidence: `frontend/src/pages/farmer/FarmerProductsPage.jsx`)
- Partner operations UI → HTTP API client: requests data (evidence: `frontend/src/pages/partners/PartnerDashboardPage.jsx`)
- Logistics UI → HTTP API client: requests data (evidence: `frontend/src/pages/logistics/LogisticsDashboardPage.jsx`)
- HTTP API client → Authentication: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → Product catalogue: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → Cart and orders: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → Payment records: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → Delivery and tracking: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → Notifications: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → AI forecasts: calls API (evidence: `frontend/src/services/api.js`)
- HTTP API client → FPO and bulk buying: calls API (evidence: `frontend/src/services/api.js`)
- Flask API setup → Authentication: registers routes (evidence: `backend/app/__init__.py`)
- Flask API setup → Cart and orders: registers routes (evidence: `backend/app/__init__.py`)
- Flask API setup → Product catalogue: registers routes (evidence: `backend/app/__init__.py`)
- Flask API setup → FPO and bulk buying: registers routes (evidence: `backend/app/__init__.py`)
- Flask API setup → Delivery and tracking: registers routes (evidence: `backend/app/__init__.py`)
- Cart and orders → Order allocations: reads and writes (evidence: `backend/app/routes/orders.py`)
- Cart and orders → Product inventory: validates stock (evidence: `backend/app/routes/orders.py`)
- Cart and orders → Delivery records: coordinates delivery (evidence: `backend/app/routes/orders.py`)
- Cart and orders → Partner records: uses partner data (evidence: `backend/app/routes/orders.py`)
- Delivery and tracking → Delivery records: updates delivery (evidence: `backend/app/routes/logistics.py`)
- Delivery and tracking → Order allocations: updates order (evidence: `backend/app/routes/logistics.py`)
- Delivery and tracking → Notifications: creates notifications
- Purchase reviews → Review records: creates reviews (evidence: `backend/app/routes/reviews.py`)
- Purchase reviews → Order allocations: checks purchase (evidence: `backend/app/routes/reviews.py`)
- Authentication → User accounts: manages accounts (evidence: `backend/app/routes/auth.py`)
- FPO and bulk buying → Partner records: manages partners (evidence: `backend/app/routes/partners.py`)
- FPO and bulk buying → Product inventory: uses inventory (evidence: `backend/app/routes/partners.py`)
- FPO and bulk buying → Order allocations: uses orders (evidence: `backend/app/routes/partners.py`)
- Product catalogue → Product inventory: manages catalogue
- Payment records → Order allocations: records payment
- Notifications → PostgreSQL database: persists records
- AI forecasts → PostgreSQL database: reads history
- User accounts → PostgreSQL database: persists accounts (evidence: `README.md`)
- Product inventory → PostgreSQL database: persists inventory (evidence: `README.md`)
- Order allocations → PostgreSQL database: persists orders (evidence: `README.md`)
- Delivery records → PostgreSQL database: persists tracking (evidence: `README.md`)
- Partner records → PostgreSQL database: persists memberships (evidence: `README.md`)
- Review records → PostgreSQL database: persists reviews
