# anubhavgithub07/dravya-ayurvedic-blockchain-platform architecture

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

- Interactive diagram: https://gitdiagram.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform
- Repository: https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform

## Overview

#### Purpose and entry points
Dravya is an Ayurvedic-herb supply-chain platform for role-based batch management, quality/inspection workflows, public verification, blockchain traceability, and AI-assisted identification. Primary runtime entry points are the Express API at `server/src/index.ts`, the Next.js application at `client/src/app/page.tsx`, and the Python AI API at `AI-Engine/src/api/app.py`.

#### Web client and role experiences
The `client/` application is a Next.js 16/React 19 TypeScript frontend. App Router pages segment experiences for producers, labs, distributors, authorities, administrators, and public verifiers; layouts enforce role-specific navigation. API calls are centralized behind service modules, with client auth and UI state stores.
Paths: `client/src/app/producer/dashboard/page.tsx`, `client/src/app/verify/page.tsx`, `client/src/services/api/axios.ts`, `client/src/store/authStore.ts`.

#### Core backend and persistence boundary
The Express/TypeScript server is the principal application API. Routes dispatch to controllers, which use Prisma as the persistence boundary to PostgreSQL; the schema and seed establish the shared operational data model. Backend domains cover authentication, users, herbs, batches, inspections, labs, distribution, verification, administration, and public APIs.
Paths: `server/src/index.ts`, `server/prisma/schema.prisma`, `server/src/controllers/batch.controller.ts`, `server/src/routes/public.routes.ts`.

#### Security and workflow control
JWT authentication, RBAC, request rate limiting, and validation sit between external clients and business endpoints. Supply-chain services coordinate lifecycle operations; audit and notification services provide cross-cutting records and user-facing updates. This is the main control boundary for who may create, inspect, transfer, verify, or administer batches.
Paths: `server/src/middleware/auth.middleware.ts`, `server/src/middleware/rbac.middleware.ts`, `server/src/services/supply-chain.service.ts`, `server/src/services/audit.service.ts`.

#### Traceability and blockchain integration
The server’s blockchain services connect application workflows to Hyperledger Fabric-oriented chaincode for immutable traceability. The chaincode exposes the ledger domain, while backend controllers/services mediate requests from the web client. QR generation and public-verification services bridge physical batch labels to batch/ledger lookup.
Paths: `blockchain/chaincode/src/traceability.ts`, `blockchain/chaincode/src/index.ts`, `server/src/services/fabric-connection.service.ts`, `server/src/services/public-verification.service.ts`.

#### AI engine and model lifecycle
`AI-Engine/` is a separately deployable Python service for image prediction, batch-related AI APIs, and an assistant/chat capability. Its model boundary loads versioned PyTorch artifacts and taxonomy/class mappings; inference is exposed through FastAPI-style routes. Offline pipelines transform raw datasets into canonical reviewed data, train models, evaluate quality gates, and promote approved versions.
Paths: `AI-Engine/src/api/routes/prediction.py`, `AI-Engine/src/inference/predictor.py`, `AI-Engine/src/models/version_manager.py`, `AI-Engine/src/evaluation/model_promotion.py`.

#### Deployment surfaces and additional client
Material runtimes are Node.js/Express, Next.js, PostgreSQL/Prisma, Python AI workloads with model files, and Docker/Compose or Render definitions for the AI service. Hyperledger Fabric chaincode is packaged separately. An iOS SwiftUI client currently concentrates on authentication and configurable API networking, rather than the full web workflow surface.
Paths: `AI-Engine/Dockerfile`, `AI-Engine/docker-compose.yml`, `AI-Engine/render.yaml`, `mobile-iOS/DravyaMobile/Core/Networking/APIClient.swift`.

Main entry points: [`server/src/controllers/batch.controller.ts`](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/controllers/batch.controller.ts) (Domain controllers), [`server/src/services/supply-chain.service.ts`](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/supply-chain.service.ts) (Supply-chain workflow), [`client/src/app/producer/dashboard/page.tsx`](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/producer/dashboard/page.tsx) (Role dashboards), [`server/src/services/public-verification.service.ts`](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/public-verification.service.ts) (Public verification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web client"]
  node_next["Next.js app<br/>web runtime<br/>[page.tsx]"]
  node_role_pages["Role dashboards<br/>App Router pages<br/>[page.tsx]"]
  node_verify_page["Public verifier<br/>App Router page<br/>[page.tsx]"]
  node_client_api["Client API layer<br/>Axios services<br/>[axios.ts]"]
  node_auth_store["Client auth state<br/>UI store<br/>[authStore.ts]"]
end

subgraph group_server["Application API"]
  node_express["Express API<br/>Node.js runtime<br/>[index.ts]"]
  node_security["Auth and RBAC<br/>middleware boundary<br/>[auth.middleware.ts]"]
  node_controllers["Domain controllers<br/>route handlers"]
  node_workflow["Supply-chain workflow<br/>domain service"]
  node_audit["Audit and notifications<br/>cross-cutting service<br/>[audit.service.ts]"]
  node_prisma["Prisma data model<br/>persistence boundary<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL<br/>operational database")]
end

subgraph group_trace["Traceability"]
  node_public_service["Public verification<br/>verification service"]
  node_fabric["Fabric connection<br/>blockchain adapter"]
  node_chaincode{{"Traceability chaincode<br/>Fabric ledger domain<br/>[traceability.ts]"}}
end

subgraph group_ai["AI engine"]
  node_ai_api["Python AI API<br/>FastAPI runtime<br/>[app.py]"]
  node_prediction["Prediction routes<br/>AI API routes<br/>[prediction.py]"]
  node_predictor["Model inference<br/>PyTorch predictor<br/>[predictor.py]"]
  node_model_lifecycle["Model lifecycle<br/>versioning and promotion<br/>[model_promotion.py]"]
end

node_mobile["iOS client<br/>SwiftUI networking<br/>[APIClient.swift]"]

node_next -->|"renders"| node_role_pages
node_next -->|"renders"| node_verify_page
node_role_pages -->|"uses session"| node_auth_store
node_role_pages -->|"calls"| node_client_api
node_verify_page -->|"verifies"| node_client_api
node_client_api -->|"HTTPS API"| node_express
node_mobile -->|"API access"| node_express
node_express -->|"applies"| node_security
node_security -->|"authorizes"| node_controllers
node_controllers -->|"executes lifecycle"| node_workflow
node_controllers -->|"public lookup"| node_public_service
node_workflow -->|"persists"| node_prisma
node_workflow -->|"records events"| node_audit
node_workflow -->|"writes traceability"| node_fabric
node_public_service -->|"batch lookup"| node_prisma
node_public_service -->|"ledger lookup"| node_fabric
node_prisma -->|"reads and writes"| node_postgres
node_fabric -->|"submits queries and transactions"| node_chaincode
node_controllers -->|"AI requests"| node_ai_api
node_ai_api -->|"routes"| node_prediction
node_prediction -->|"runs inference"| node_predictor
node_predictor -->|"loads promoted version"| node_model_lifecycle

click node_next "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/page.tsx"
click node_role_pages "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/producer/dashboard/page.tsx"
click node_verify_page "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/verify/page.tsx"
click node_client_api "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/services/api/axios.ts"
click node_auth_store "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/store/authStore.ts"
click node_express "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/index.ts"
click node_security "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/middleware/auth.middleware.ts"
click node_controllers "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/controllers/batch.controller.ts"
click node_workflow "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/supply-chain.service.ts"
click node_audit "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/audit.service.ts"
click node_prisma "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/prisma/schema.prisma"
click node_public_service "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/public-verification.service.ts"
click node_fabric "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/fabric-connection.service.ts"
click node_chaincode "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/blockchain/chaincode/src/traceability.ts"
click node_ai_api "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/api/app.py"
click node_prediction "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/api/routes/prediction.py"
click node_predictor "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/inference/predictor.py"
click node_model_lifecycle "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/evaluation/model_promotion.py"
click node_mobile "https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/mobile-iOS/DravyaMobile/Core/Networking/APIClient.swift"

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_next,node_role_pages,node_verify_page,node_client_api,node_auth_store toneBlue
class node_express,node_security,node_controllers,node_workflow,node_audit,node_prisma,node_postgres toneAmber
class node_public_service,node_fabric,node_chaincode toneMint
class node_ai_api,node_prediction,node_predictor,node_model_lifecycle toneRose
class node_mobile toneNeutral
```

## Components

### Web client

- [Next.js app](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/page.tsx): web runtime · Role-specific operational and public verification experiences. · `client/src/app/page.tsx`
- [Role dashboards](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/producer/dashboard/page.tsx): App Router pages · `client/src/app/producer/dashboard/page.tsx`
- [Public verifier](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/app/verify/page.tsx): App Router page · `client/src/app/verify/page.tsx`
- [Client API layer](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/services/api/axios.ts): Axios services · `client/src/services/api/axios.ts`
- [Client auth state](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/client/src/store/authStore.ts): UI store · `client/src/store/authStore.ts`

### Application API

- [Express API](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/index.ts): Node.js runtime · Principal API for operational supply-chain workflows. · `server/src/index.ts`
- [Auth and RBAC](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/middleware/auth.middleware.ts): middleware boundary · JWT, authorization, validation, and rate limiting protect business endpoints. · `server/src/middleware/auth.middleware.ts`
- [Domain controllers](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/controllers/batch.controller.ts): route handlers · Authentication, batch, inspection, lab, distribution, and administration APIs. · `server/src/controllers/batch.controller.ts`
- [Supply-chain workflow](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/supply-chain.service.ts): domain service · Coordinates batch lifecycle operations. · `server/src/services/supply-chain.service.ts`
- [Audit and notifications](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/audit.service.ts): cross-cutting service · `server/src/services/audit.service.ts`
- [Prisma data model](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/prisma/schema.prisma): persistence boundary · Shared operational schema for platform domains. · `server/prisma/schema.prisma`
- **PostgreSQL**: operational database

### Traceability

- [Public verification](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/public-verification.service.ts): verification service · Bridges QR-labelled batches to application and ledger lookups. · `server/src/services/public-verification.service.ts`
- [Fabric connection](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/server/src/services/fabric-connection.service.ts): blockchain adapter · `server/src/services/fabric-connection.service.ts`
- [Traceability chaincode](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/blockchain/chaincode/src/traceability.ts): Fabric ledger domain · Immutable batch traceability records. · `blockchain/chaincode/src/traceability.ts`

### AI engine

- [Python AI API](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/api/app.py): FastAPI runtime · Separately deployable prediction, batch-AI, and assistant API. · `AI-Engine/src/api/app.py`
- [Prediction routes](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/api/routes/prediction.py): AI API routes · `AI-Engine/src/api/routes/prediction.py`
- [Model inference](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/inference/predictor.py): PyTorch predictor · Loads artifacts and taxonomy mappings for image identification. · `AI-Engine/src/inference/predictor.py`
- [Model lifecycle](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/AI-Engine/src/evaluation/model_promotion.py): versioning and promotion · Approved evaluated models are promoted for inference. · `AI-Engine/src/evaluation/model_promotion.py`

### Other components

- [iOS client](https://github.com/anubhavgithub07/dravya-ayurvedic-blockchain-platform/blob/main/mobile-iOS/DravyaMobile/Core/Networking/APIClient.swift): SwiftUI networking · Authentication and configurable API access client. · `mobile-iOS/DravyaMobile/Core/Networking/APIClient.swift`

## Connections

- Next.js app → Role dashboards: renders
- Next.js app → Public verifier: renders
- Role dashboards → Client auth state: uses session
- Role dashboards → Client API layer: calls
- Public verifier → Client API layer: verifies
- Client API layer → Express API: HTTPS API
- iOS client → Express API: API access
- Express API → Auth and RBAC: applies
- Auth and RBAC → Domain controllers: authorizes
- Domain controllers → Supply-chain workflow: executes lifecycle
- Domain controllers → Public verification: public lookup
- Supply-chain workflow → Prisma data model: persists
- Supply-chain workflow → Audit and notifications: records events
- Supply-chain workflow → Fabric connection: writes traceability
- Public verification → Prisma data model: batch lookup
- Public verification → Fabric connection: ledger lookup
- Prisma data model → PostgreSQL: reads and writes
- Fabric connection → Traceability chaincode: submits queries and transactions
- Domain controllers → Python AI API: AI requests
- Python AI API → Prediction routes: routes
- Prediction routes → Model inference: runs inference
- Model inference → Model lifecycle: loads promoted version
