# chodisettiakshitha-code/agrochain-main architecture

> Architecture diagram of the GitHub repository chodisettiakshitha-code/agrochain-main, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chodisettiakshitha-code/agrochain-main
- Repository: https://github.com/chodisettiakshitha-code/agrochain-main

## Overview

AgroChain combines a farmer-to-consumer Algorand marketplace with a separate x402-paid agricultural-services API. The main marketplace flow is users connecting a wallet, browsing or listing produce, and purchasing through the frontend’s chain hook and the marketplace contract; the backend provides paid advisory, forecasting, quality-verification, and produce-purchase endpoints. The sampled frontend and contract code supports the wallet, state, and contract relationships shown. Backend-to-facilitator payment handling is documented in the server excerpt; unsampled frontend service wiring is left unspecified.

Main entry points: [`frontend/src/App.tsx`](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/App.tsx) (Application shell), [`frontend/src/hooks/useAgroChain.ts`](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/hooks/useAgroChain.ts) (Marketplace state hook), [`backend/index.ts`](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/backend/index.ts) (x402 API server), [`frontend/src/pages/Marketplace.tsx`](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/Marketplace.tsx) (Marketplace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Marketplace frontend"]
  node_app["Application shell<br/>[App.tsx]"]
  node_market["Marketplace<br/>[Marketplace.tsx]"]
  node_farmer["Farmer dashboard"]
  node_orders["Order history<br/>[MyOrders.tsx]"]
  node_servicesui["Agri services UI<br/>[AgriServices.tsx]"]
  node_wallet["Wallet connection<br/>[WalletButton.tsx]"]
  node_state["Marketplace state hook<br/>[useAgroChain.ts]"]
  node_chainservice["Chain access service<br/>[agrochain.ts]"]
end

subgraph group_chain["Algorand marketplace"]
  node_client["Contract client"]
  node_contract["Marketplace contract<br/>[contract.py]"]
end

subgraph group_api["Paid agricultural services"]
  node_server["x402 API server<br/>[index.ts]"]
  node_handlers["Agriculture handlers<br/>[agrochain.ts]"]
end

node_user(("Farmer or consumer"))
node_algorand(("Algorand network"))
node_facilitator(("x402 facilitator"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_market
node_app -->|"renders"| node_farmer
node_app -->|"renders"| node_orders
node_app -->|"renders"| node_servicesui
node_app -->|"uses"| node_state
node_app -->|"opens"| node_wallet
node_market -->|"requests purchases"| node_state
node_farmer -->|"requests listings"| node_state
node_orders -->|"displays orders"| node_state
node_state -->|"uses signer"| node_wallet
node_state -->|"reads and records"| node_chainservice
node_state -->|"calls contract"| node_client
node_client -->|"submits transactions"| node_algorand
node_algorand -->|"executes"| node_contract
node_servicesui -.->|"requests paid services"| node_server
node_server -->|"verifies payments"| node_facilitator
node_server -->|"dispatches routes"| node_handlers

click node_app "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/App.tsx"
click node_market "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/Marketplace.tsx"
click node_farmer "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/FarmerDashboard.tsx"
click node_orders "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/MyOrders.tsx"
click node_servicesui "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/AgriServices.tsx"
click node_wallet "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/components/WalletButton.tsx"
click node_state "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/hooks/useAgroChain.ts"
click node_chainservice "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/services/agrochain.ts"
click node_client "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/contracts/AgroChainMarketplace.ts"
click node_contract "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/contracts/smart_contracts/agrochain_marketplace/contract.py"
click node_server "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/backend/index.ts"
click node_handlers "https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/backend/handlers/agrochain.ts"

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_app,node_market,node_farmer,node_orders,node_servicesui,node_wallet,node_state,node_chainservice toneBlue
class node_client,node_contract toneAmber
class node_server,node_handlers toneMint
class node_user,node_algorand,node_facilitator toneIndigo
```

## Components

### Marketplace frontend

- [Application shell](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Marketplace](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/Marketplace.tsx): `frontend/src/pages/Marketplace.tsx`
- [Farmer dashboard](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/FarmerDashboard.tsx): `frontend/src/pages/FarmerDashboard.tsx`
- [Order history](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/MyOrders.tsx): `frontend/src/pages/MyOrders.tsx`
- [Agri services UI](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/pages/AgriServices.tsx): `frontend/src/pages/AgriServices.tsx`
- [Wallet connection](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/components/WalletButton.tsx): `frontend/src/components/WalletButton.tsx`
- [Marketplace state hook](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/hooks/useAgroChain.ts): `frontend/src/hooks/useAgroChain.ts`
- [Chain access service](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/services/agrochain.ts): `frontend/src/services/agrochain.ts`

### Algorand marketplace

- [Contract client](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/frontend/src/contracts/AgroChainMarketplace.ts): `frontend/src/contracts/AgroChainMarketplace.ts`
- [Marketplace contract](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/contracts/smart_contracts/agrochain_marketplace/contract.py): `contracts/smart_contracts/agrochain_marketplace/contract.py`

### Paid agricultural services

- [x402 API server](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/backend/index.ts): `backend/index.ts`
- [Agriculture handlers](https://github.com/chodisettiakshitha-code/agrochain-main/blob/main/backend/handlers/agrochain.ts): `backend/handlers/agrochain.ts`

### Other components

- **Farmer or consumer**
- **Algorand network**
- **x402 facilitator**

## Connections

- Farmer or consumer → Application shell: uses
- Application shell → Marketplace: renders
- Application shell → Farmer dashboard: renders
- Application shell → Order history: renders
- Application shell → Agri services UI: renders
- Application shell → Marketplace state hook: uses
- Application shell → Wallet connection: opens
- Marketplace → Marketplace state hook: requests purchases
- Farmer dashboard → Marketplace state hook: requests listings
- Order history → Marketplace state hook: displays orders
- Marketplace state hook → Wallet connection: uses signer
- Marketplace state hook → Chain access service: reads and records
- Marketplace state hook → Contract client: calls contract
- Contract client → Algorand network: submits transactions
- Algorand network → Marketplace contract: executes
- Agri services UI → x402 API server: requests paid services
- x402 API server → x402 facilitator: verifies payments
- x402 API server → Agriculture handlers: dispatches routes
