How anubhavgithub07/dravya-ayurvedic-blockchain-platform works
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: batch.controller.ts Domain controllers · supply-chain.service.ts Supply-chain workflow · page.tsx Role dashboards · public-verification.service.ts Public verification
Components 20
Web client
- Next.js app · Role-specific operational and public verification experiences.
client/src/app/page.tsx - Role dashboards
client/src/app/producer/dashboard/page.tsx - Public verifier
client/src/app/verify/page.tsx - Client API layer
client/src/services/api/axios.ts - Client auth state
client/src/store/authStore.ts
Application API
- Express API · Principal API for operational supply-chain workflows.
server/src/index.ts - Auth and RBAC · JWT, authorization, validation, and rate limiting protect business endpoints.
server/src/middleware/auth.middleware.ts - Domain controllers · Authentication, batch, inspection, lab, distribution, and administration APIs.
server/src/controllers/batch.controller.ts - Supply-chain workflow · Coordinates batch lifecycle operations.
server/src/services/supply-chain.service.ts - Audit and notifications
server/src/services/audit.service.ts - Prisma data model · Shared operational schema for platform domains.
server/prisma/schema.prisma - PostgreSQL
Traceability
- Public verification · Bridges QR-labelled batches to application and ledger lookups.
server/src/services/public-verification.service.ts - Fabric connection
server/src/services/fabric-connection.service.ts - Traceability chaincode · Immutable batch traceability records.
blockchain/chaincode/src/traceability.ts
AI engine
- Python AI API · Separately deployable prediction, batch-AI, and assistant API.
AI-Engine/src/api/app.py - Prediction routes
AI-Engine/src/api/routes/prediction.py - Model inference · Loads artifacts and taxonomy mappings for image identification.
AI-Engine/src/inference/predictor.py - Model lifecycle · Approved evaluated models are promoted for inference.
AI-Engine/src/evaluation/model_promotion.py
Other components
- iOS client · Authentication and configurable API access client.
mobile-iOS/DravyaMobile/Core/Networking/APIClient.swift
Connections 22
- 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