# eddy165/ayurchain architecture

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

- Interactive diagram: https://gitdiagram.com/eddy165/ayurchain
- Repository: https://github.com/eddy165/ayurchain

## Overview

AyurChain provides farm-to-consumer herb-batch traceability: supply-chain participants create and advance batches, labs submit reports, and consumers verify provenance through a QR scan. The README describes a hybrid design: MongoDB serves operational records, IPFS holds documents and metadata, and Polygon anchors verifiable proofs and transfers. The graph combines documented capabilities with relationships visible in sampled source; some route implementations and web/mobile screens were not sampled, so those connections are documented rather than inferred from imports.

Main entry points: [`backend/src/index.ts`](https://github.com/eddy165/ayurchain/blob/main/backend/src/index.ts) (Express API), [`backend/src/controllers/batchController.ts`](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/batchController.ts) (Batch workflow), [`backend/src/services/blockchainService.ts`](https://github.com/eddy165/ayurchain/blob/main/backend/src/services/blockchainService.ts) (Blockchain bridge), [`backend/src/controllers/labController.ts`](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/labController.ts) (Lab reports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client apps"]
  node_web["Web application<br/>[App.tsx]"]
  node_mobile["QR mobile app"]
  node_webapi["Web API client<br/>[api.ts]"]
  node_webstate["Web auth state<br/>[authSlice.ts]"]
  node_webtypes["Batch and user types<br/>[batch.types.ts]"]
end

subgraph group_api["API and workflows"]
  node_server["Express API<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.ts]"]
  node_authcontroller["Authentication workflow<br/>[authController.ts]"]
  node_batchroutes["Batch routes<br/>[batches.ts]"]
  node_batchcontroller["Batch workflow<br/>[batchController.ts]"]
  node_labroutes["Lab routes<br/>[labs.ts]"]
  node_labcontroller["Lab reports<br/>[labController.ts]"]
  node_consumerroute["Consumer route<br/>[consumer.ts]"]
  node_consumercontroller["Consumer traceability"]
  node_qrroutes["QR routes<br/>[qr.ts]"]
  node_qrcontroller["QR handling<br/>[qrController.ts]"]
  node_middleware["Auth and request guards<br/>[auth.ts]"]
end

subgraph group_records["Operational records"]
  node_batchmodel[("Batch records<br/>[Batch.ts]")]
  node_usermodel[("User records<br/>[User.ts]")]
  node_labmodel[("Lab reports<br/>[LabReport.ts]")]
  node_mongodb[("MongoDB")]
end

subgraph group_trust["Verification services"]
  node_ipfs["Document storage<br/>[ipfsService.ts]"]
  node_qrservice["QR generation<br/>[qrService.ts]"]
  node_blockchainservice["Blockchain bridge"]
end

subgraph group_chain["On-chain contracts"]
  node_contracts["Traceability contracts"]
end

node_farmer(("Supply-chain users"))
node_consumer(("Consumer"))
node_pinata[("IPFS Pinata")]
node_polygon[("Polygon network")]

node_farmer -.->|"manages batches"| node_web
node_consumer -.->|"scans QR"| node_mobile
node_consumer -.->|"verifies provenance"| node_web
node_web -.->|"requests API"| node_webapi
node_webapi -.->|"calls REST API"| node_server
node_webapi -->|"uses auth state"| node_webstate
node_webstate -->|"uses user types"| node_webtypes
node_mobile -.->|"requests traceability"| node_server
node_server -->|"routes requests"| node_authroutes
node_server -->|"routes requests"| node_batchroutes
node_server -->|"routes requests"| node_labroutes
node_server -->|"routes requests"| node_consumerroute
node_server -->|"routes requests"| node_qrroutes
node_authroutes -->|"dispatches handlers"| node_authcontroller
node_consumerroute -->|"dispatches handlers"| node_consumercontroller
node_qrroutes -->|"dispatches handlers"| node_qrcontroller
node_middleware -->|"guards requests"| node_qrroutes
node_authcontroller -->|"reads and writes"| node_usermodel
node_batchcontroller -->|"reads and writes"| node_batchmodel
node_batchcontroller -->|"reads user data"| node_usermodel
node_batchcontroller -->|"uploads metadata"| node_ipfs
node_batchcontroller -->|"anchors batch"| node_blockchainservice
node_batchcontroller -->|"creates QR"| node_qrservice
node_labcontroller -->|"reads and updates"| node_batchmodel
node_labcontroller -->|"stores report"| node_labmodel
node_labcontroller -->|"uploads report"| node_ipfs
node_labcontroller -->|"records stage"| node_blockchainservice
node_consumercontroller -->|"reads batch"| node_batchmodel
node_consumercontroller -->|"verifies history"| node_blockchainservice
node_batchmodel -.->|"persists records"| node_mongodb
node_usermodel -.->|"persists records"| node_mongodb
node_labmodel -.->|"persists reports"| node_mongodb
node_ipfs -.->|"stores documents"| node_pinata
node_blockchainservice -.->|"submits transactions"| node_polygon
node_contracts -.->|"executes on"| node_polygon
node_blockchainservice -->|"calls contract methods"| node_contracts

click node_web "https://github.com/eddy165/ayurchain/blob/main/web/src/App.tsx"
click node_mobile "https://github.com/eddy165/ayurchain/blob/main/mobile/src/screens/QRScannerScreen.tsx"
click node_webapi "https://github.com/eddy165/ayurchain/blob/main/web/src/services/api.ts"
click node_webstate "https://github.com/eddy165/ayurchain/blob/main/web/src/store/authSlice.ts"
click node_webtypes "https://github.com/eddy165/ayurchain/blob/main/web/src/types/batch.types.ts"
click node_server "https://github.com/eddy165/ayurchain/blob/main/backend/src/index.ts"
click node_authroutes "https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/auth.ts"
click node_authcontroller "https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/authController.ts"
click node_batchroutes "https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/batches.ts"
click node_batchcontroller "https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/batchController.ts"
click node_labroutes "https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/labs.ts"
click node_labcontroller "https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/labController.ts"
click node_consumerroute "https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/consumer.ts"
click node_consumercontroller "https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/consumerController.ts"
click node_qrroutes "https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/qr.ts"
click node_qrcontroller "https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/qrController.ts"
click node_middleware "https://github.com/eddy165/ayurchain/blob/main/backend/src/middleware/auth.ts"
click node_batchmodel "https://github.com/eddy165/ayurchain/blob/main/backend/src/models/Batch.ts"
click node_usermodel "https://github.com/eddy165/ayurchain/blob/main/backend/src/models/User.ts"
click node_labmodel "https://github.com/eddy165/ayurchain/blob/main/backend/src/models/LabReport.ts"
click node_ipfs "https://github.com/eddy165/ayurchain/blob/main/backend/src/services/ipfsService.ts"
click node_qrservice "https://github.com/eddy165/ayurchain/blob/main/backend/src/services/qrService.ts"
click node_blockchainservice "https://github.com/eddy165/ayurchain/blob/main/backend/src/services/blockchainService.ts"
click node_contracts "https://github.com/eddy165/ayurchain/tree/main/contracts"

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_web,node_mobile,node_webapi,node_webstate,node_webtypes,node_farmer toneBlue
class node_server,node_authroutes,node_authcontroller,node_batchroutes,node_batchcontroller,node_labroutes,node_labcontroller,node_consumerroute,node_consumercontroller,node_qrroutes,node_qrcontroller,node_middleware,node_pinata,node_polygon toneAmber
class node_batchmodel,node_usermodel,node_labmodel,node_mongodb toneMint
class node_ipfs,node_qrservice,node_blockchainservice toneRose
class node_contracts,node_consumer toneIndigo
```

## Components

### Client apps

- [Web application](https://github.com/eddy165/ayurchain/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [QR mobile app](https://github.com/eddy165/ayurchain/blob/main/mobile/src/screens/QRScannerScreen.tsx): `mobile/src/screens/QRScannerScreen.tsx`
- [Web API client](https://github.com/eddy165/ayurchain/blob/main/web/src/services/api.ts): `web/src/services/api.ts`
- [Web auth state](https://github.com/eddy165/ayurchain/blob/main/web/src/store/authSlice.ts): `web/src/store/authSlice.ts`
- [Batch and user types](https://github.com/eddy165/ayurchain/blob/main/web/src/types/batch.types.ts): `web/src/types/batch.types.ts`

### API and workflows

- [Express API](https://github.com/eddy165/ayurchain/blob/main/backend/src/index.ts): `backend/src/index.ts`
- [Authentication routes](https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [Authentication workflow](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/authController.ts): `backend/src/controllers/authController.ts`
- [Batch routes](https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/batches.ts): `backend/src/routes/batches.ts`
- [Batch workflow](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/batchController.ts): `backend/src/controllers/batchController.ts`
- [Lab routes](https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/labs.ts): `backend/src/routes/labs.ts`
- [Lab reports](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/labController.ts): `backend/src/controllers/labController.ts`
- [Consumer route](https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/consumer.ts): `backend/src/routes/consumer.ts`
- [Consumer traceability](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/consumerController.ts): `backend/src/controllers/consumerController.ts`
- [QR routes](https://github.com/eddy165/ayurchain/blob/main/backend/src/routes/qr.ts): `backend/src/routes/qr.ts`
- [QR handling](https://github.com/eddy165/ayurchain/blob/main/backend/src/controllers/qrController.ts): `backend/src/controllers/qrController.ts`
- [Auth and request guards](https://github.com/eddy165/ayurchain/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`

### Operational records

- [Batch records](https://github.com/eddy165/ayurchain/blob/main/backend/src/models/Batch.ts): `backend/src/models/Batch.ts`
- [User records](https://github.com/eddy165/ayurchain/blob/main/backend/src/models/User.ts): `backend/src/models/User.ts`
- [Lab reports](https://github.com/eddy165/ayurchain/blob/main/backend/src/models/LabReport.ts): `backend/src/models/LabReport.ts`
- **MongoDB**

### Verification services

- [Document storage](https://github.com/eddy165/ayurchain/blob/main/backend/src/services/ipfsService.ts): `backend/src/services/ipfsService.ts`
- [QR generation](https://github.com/eddy165/ayurchain/blob/main/backend/src/services/qrService.ts): `backend/src/services/qrService.ts`
- [Blockchain bridge](https://github.com/eddy165/ayurchain/blob/main/backend/src/services/blockchainService.ts): `backend/src/services/blockchainService.ts`

### On-chain contracts

- [Traceability contracts](https://github.com/eddy165/ayurchain/tree/main/contracts): `contracts`

### Other components

- **Supply-chain users**
- **Consumer**
- **IPFS Pinata**
- **Polygon network**

## Connections

- Supply-chain users → Web application: manages batches (evidence: `README.md`)
- Consumer → QR mobile app: scans QR (evidence: `README.md`)
- Consumer → Web application: verifies provenance (evidence: `README.md`)
- Web application → Web API client: requests API (evidence: `README.md`)
- Web API client → Express API: calls REST API (evidence: `README.md`)
- Web API client → Web auth state: uses auth state (evidence: `web/src/services/api.ts`)
- Web auth state → Batch and user types: uses user types
- QR mobile app → Express API: requests traceability (evidence: `README.md`)
- Express API → Authentication routes: routes requests (evidence: `backend/src/index.ts`)
- Express API → Batch routes: routes requests (evidence: `backend/src/index.ts`)
- Express API → Lab routes: routes requests (evidence: `backend/src/index.ts`)
- Express API → Consumer route: routes requests (evidence: `backend/src/index.ts`)
- Express API → QR routes: routes requests (evidence: `backend/src/index.ts`)
- Authentication routes → Authentication workflow: dispatches handlers (evidence: `backend/src/routes/auth.ts`)
- Consumer route → Consumer traceability: dispatches handlers (evidence: `backend/src/routes/consumer.ts`)
- QR routes → QR handling: dispatches handlers (evidence: `backend/src/routes/qr.ts`)
- Auth and request guards → QR routes: guards requests (evidence: `backend/src/routes/qr.ts`)
- Authentication workflow → User records: reads and writes (evidence: `backend/src/controllers/authController.ts`)
- Batch workflow → Batch records: reads and writes (evidence: `backend/src/controllers/batchController.ts`)
- Batch workflow → User records: reads user data (evidence: `backend/src/controllers/batchController.ts`)
- Batch workflow → Document storage: uploads metadata (evidence: `backend/src/controllers/batchController.ts`)
- Batch workflow → Blockchain bridge: anchors batch (evidence: `backend/src/controllers/batchController.ts`)
- Batch workflow → QR generation: creates QR (evidence: `backend/src/controllers/batchController.ts`)
- Lab reports → Batch records: reads and updates (evidence: `backend/src/controllers/labController.ts`)
- Lab reports → Lab reports: stores report (evidence: `backend/src/controllers/labController.ts`)
- Lab reports → Document storage: uploads report (evidence: `backend/src/controllers/labController.ts`)
- Lab reports → Blockchain bridge: records stage (evidence: `backend/src/controllers/labController.ts`)
- Consumer traceability → Batch records: reads batch (evidence: `backend/src/controllers/consumerController.ts`)
- Consumer traceability → Blockchain bridge: verifies history (evidence: `backend/src/controllers/consumerController.ts`)
- Batch records → MongoDB: persists records (evidence: `README.md`)
- User records → MongoDB: persists records (evidence: `README.md`)
- Lab reports → MongoDB: persists reports (evidence: `README.md`)
- Document storage → IPFS Pinata: stores documents (evidence: `README.md`)
- Blockchain bridge → Polygon network: submits transactions (evidence: `README.md`)
- Traceability contracts → Polygon network: executes on (evidence: `README.md`)
- Blockchain bridge → Traceability contracts: calls contract methods (evidence: `backend/src/services/blockchainService.ts`)
