# ansukr07/wooltrace architecture

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

- Interactive diagram: https://gitdiagram.com/ansukr07/wooltrace
- Repository: https://github.com/ansukr07/wooltrace

## Overview

#### Purpose and Entry Points
This is a Vite/React wool supply-chain platform spanning farmers, inspectors, processors, warehouses, sellers, transport, teachers, and public users. The frontend bootstraps at `src/main.jsx`, composes routing/UI in `src/App.jsx`, and is deployable as serverless functions via `vercel.json`. Backend HTTP entry points are the route-like files under `api/`, notably `api/login.js`, `api/batches.js`, `api/processing.js`, and `api/market.js`.

#### Client Application Shell and Access Control
Role-specific layouts organize authenticated workspaces: `src/layouts/FarmerLayout.jsx`, `src/layouts/ProcessingLayout.jsx`, `src/layouts/WarehouseLayout.jsx`, and `src/layouts/SellerLayout.jsx`. `src/components/ProtectedRoute.jsx` forms the client-side route-access boundary. Shared authentication and cross-page application state live in `src/context/AuthContext.jsx`, `src/context/GlobalStateContext.jsx`, and `src/context/WoolKartContext.jsx`.

#### Batch Traceability and Quality Lifecycle
The central domain entity is the wool batch, persisted through `api/_models/WoolBatch.js`. Farmers create/manage and track stock through `src/pages/farmer/MyWool.jsx`, `src/pages/farmer/BatchDetail.jsx`, and `src/pages/farmer/TrackWool.jsx`; public users can inspect a batch without entering a role workspace at `src/pages/public/PublicTrackBatch.jsx`. The backend’s batch boundary is `api/batches.js`. Traceability is rendered through `src/components/TraceabilityTimeline.jsx`.

Quality inspection requests, resulting certificates, and public certificate verification are represented by `api/_models/InspectionRequest.js`, `api/_models/QualityCertificate.js`, and `api/qa.js`. Inspector workflows are centered in `src/pages/inspector/InspectionDetail.jsx` and `src/pages/inspector/Certificates.jsx`; public verification is `src/pages/public/VerifyCertificate.jsx`. Frontend calls are isolated behind `src/services/qa/qaService.js`.

#### Processing and Warehouse Handoffs
Processing requests and records model conversion of batches at `api/_models/ProcessingRequest.js` and `api/_models/ProcessingRecord.js`. The serverless processing API, `api/processing.js`, coordinates persistence plus the external CEDA-related integration encapsulated by `api/_utils/processingCedaService.js` and `api/_utils/ceda.js`. Processors operate through `src/pages/processing/ProcessingDashboard.jsx` and `src/pages/processing/ProcessingBatchDetail.jsx`, using `src/services/processing/processingService.js`.

Warehouse work is a subsequent custody boundary: intake, inventory, release, and requests are separated into `src/pages/warehouse/WarehouseCheckIn.jsx`, `src/pages/warehouse/WarehouseInventory.jsx`, and `src/pages/warehouse/WarehouseReleases.jsx`. Transport currently has a dedicated dashboard at `src/pages/transport/TransportDashboard.jsx`.

#### Market, Bidding, and Orders
Two commerce-oriented flows exist. Wool listing/bidding is modeled by `api/_models/BiddingListing.js` and `api/_models/Bid.js`, exposed from `api/bidding.js`, and consumed by seller views such as `src/pages/seller/Marketplace.jsx`, `src/pages/seller/Bids.jsx`, and `src/pages/seller/BidDetail.jsx`.

Orders are persisted by `api/_models/Order.js` and served through `api/market.js`. Seller order/inventory flows are in `src/pages/seller/Inventory.jsx` and `src/pages/seller/Orders.jsx`. A farmer-facing WoolKart storefront has its own cart state and flow in `src/context/WoolKartContext.jsx`, `src/pages/farmer/woolkart/WoolKartRoot.jsx`, and `src/pages/farmer/woolkart/Checkout.jsx`.

#### Market Data and Learning Services
Market pricing/data is abstracted behind provider interfaces in `src/services/market/MarketDataProvider.js`, with demo and Agmarknet implementations in `src/services/market/DemoDataProvider.js` and `src/services/market/AgmarknetProvider.js`; API interaction is centralized by `src/services/market/marketService.js`.

Learning content is persisted as `api/_models/LearningResource.js` and exposed via `api/learning-resources.js`. Farmer academy and teacher resource-library experiences are `src/pages/farmer/Academy.jsx` and `src/pages/teacher/ResourceLibrary.jsx`.

#### Runtime and Persistence Boundaries
The browser runtime is React on Vite (`vite.config.js`), while `api/*.js` are likely Vercel serverless endpoints. Backend models and route handlers share database setup through `api/_utils/db.js`; users and roles are represented by `api/_models/User.js`, with registration/login handled in `api/register.js` and `api/login.js`. No payment, mapping, or database vendor is identifiable from the supplied tree.

Main entry points: [`api/_utils/db.js`](https://github.com/ansukr07/wooltrace/blob/main/api/_utils/db.js) (Database connection), [`api/_models/WoolBatch.js`](https://github.com/ansukr07/wooltrace/blob/main/api/_models/WoolBatch.js) (Wool batches), [`api/processing.js`](https://github.com/ansukr07/wooltrace/blob/main/api/processing.js) (Processing API), [`src/App.jsx`](https://github.com/ansukr07/wooltrace/blob/main/src/App.jsx) (App routing shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["React browser app"]
  node_vite(("Vite bootstrap<br/>client entry<br/>[main.jsx]"))
  node_app["App routing shell<br/>React router<br/>[App.jsx]"]
  node_auth_state["Auth and app state<br/>React contexts<br/>[AuthContext.jsx]"]
  node_protected_routes["Protected routes<br/>access boundary<br/>[ProtectedRoute.jsx]"]
  node_role_workspaces["Role workspaces<br/>role layouts<br/>[FarmerLayout.jsx]"]
  node_batch_ui["Batch tracking UI<br/>farmer and public pages<br/>[MyWool.jsx]"]
  node_traceability["Traceability timeline<br/>shared component"]
  node_qa_ui["Inspection and certificates UI<br/>inspector and public pages"]
  node_processing_ui["Processing workspace<br/>processor pages"]
  node_warehouse_transport_ui["Warehouse and transport UI<br/>custody workspace"]
  node_commerce_ui["Marketplace and WoolKart UI<br/>seller and farmer pages<br/>[Marketplace.jsx]"]
  node_learning_ui["Academy and resource library<br/>learning pages<br/>[Academy.jsx]"]
end

subgraph group_api["Serverless API"]
  node_auth_api["Authentication API<br/>serverless routes<br/>[login.js]"]
  node_batch_api["Batch API<br/>serverless route<br/>[batches.js]"]
  node_qa_api["Quality API<br/>serverless route<br/>[qa.js]"]
  node_processing_api["Processing API<br/>serverless route<br/>[processing.js]"]
  node_commerce_api["Bidding and market APIs<br/>serverless routes<br/>[bidding.js]"]
  node_learning_api["Learning resources API<br/>serverless route"]
end

subgraph group_data["Domain persistence"]
  node_users[("Users and roles<br/>User model<br/>[User.js]")]
  node_batches[("Wool batches<br/>WoolBatch model<br/>[WoolBatch.js]")]
  node_quality_records[("Inspection and certificates<br/>quality models")]
  node_processing_records[("Processing records<br/>processing models")]
  node_commerce_records[("Listings, bids, and orders<br/>commerce models<br/>[BiddingListing.js]")]
  node_learning_resources[("Learning resources<br/>LearningResource model")]
  node_database[("Database connection<br/>shared DB utility<br/>[db.js]")]
end

subgraph group_external["External integration"]
  node_ceda{{"CEDA integration<br/>external processing service"}}
  node_market_data{{"Market data providers<br/>provider layer"}}
end

node_vite -->|"mounts"| node_app
node_app -->|"uses"| node_auth_state
node_app -->|"routes through"| node_protected_routes
node_protected_routes -->|"authorizes"| node_role_workspaces
node_role_workspaces -->|"hosts"| node_batch_ui
node_batch_ui -->|"renders"| node_traceability
node_batch_ui -->|"manages batches"| node_batch_api
node_qa_ui -->|"inspection workflow"| node_qa_api
node_processing_ui -->|"submits processing"| node_processing_api
node_warehouse_transport_ui -->|"updates custody"| node_batch_api
node_commerce_ui -->|"trades and orders"| node_commerce_api
node_commerce_ui -->|"reads pricing"| node_market_data
node_learning_ui -->|"uses resources"| node_learning_api
node_auth_state -->|"authenticates"| node_auth_api
node_auth_api -->|"reads and writes"| node_users
node_batch_api -->|"persists"| node_batches
node_qa_api -->|"traces batch"| node_batches
node_qa_api -->|"persists"| node_quality_records
node_processing_api -->|"updates lifecycle"| node_batches
node_processing_api -->|"persists"| node_processing_records
node_processing_api -->|"integrates"| node_ceda
node_commerce_api -->|"lists inventory"| node_batches
node_commerce_api -->|"persists"| node_commerce_records
node_learning_api -->|"persists"| node_learning_resources
node_users -->|"connects via"| node_database
node_batches -->|"connects via"| node_database
node_quality_records -->|"connects via"| node_database
node_processing_records -->|"connects via"| node_database
node_commerce_records -->|"connects via"| node_database
node_learning_resources -->|"connects via"| node_database

click node_vite "https://github.com/ansukr07/wooltrace/blob/main/src/main.jsx"
click node_app "https://github.com/ansukr07/wooltrace/blob/main/src/App.jsx"
click node_auth_state "https://github.com/ansukr07/wooltrace/blob/main/src/context/AuthContext.jsx"
click node_protected_routes "https://github.com/ansukr07/wooltrace/blob/main/src/components/ProtectedRoute.jsx"
click node_role_workspaces "https://github.com/ansukr07/wooltrace/blob/main/src/layouts/FarmerLayout.jsx"
click node_batch_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/farmer/MyWool.jsx"
click node_traceability "https://github.com/ansukr07/wooltrace/blob/main/src/components/TraceabilityTimeline.jsx"
click node_qa_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/inspector/InspectionDetail.jsx"
click node_processing_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/processing/ProcessingDashboard.jsx"
click node_warehouse_transport_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/warehouse/WarehouseCheckIn.jsx"
click node_commerce_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/seller/Marketplace.jsx"
click node_learning_ui "https://github.com/ansukr07/wooltrace/blob/main/src/pages/farmer/Academy.jsx"
click node_auth_api "https://github.com/ansukr07/wooltrace/blob/main/api/login.js"
click node_batch_api "https://github.com/ansukr07/wooltrace/blob/main/api/batches.js"
click node_qa_api "https://github.com/ansukr07/wooltrace/blob/main/api/qa.js"
click node_processing_api "https://github.com/ansukr07/wooltrace/blob/main/api/processing.js"
click node_commerce_api "https://github.com/ansukr07/wooltrace/blob/main/api/bidding.js"
click node_learning_api "https://github.com/ansukr07/wooltrace/blob/main/api/learning-resources.js"
click node_users "https://github.com/ansukr07/wooltrace/blob/main/api/_models/User.js"
click node_batches "https://github.com/ansukr07/wooltrace/blob/main/api/_models/WoolBatch.js"
click node_quality_records "https://github.com/ansukr07/wooltrace/blob/main/api/_models/InspectionRequest.js"
click node_processing_records "https://github.com/ansukr07/wooltrace/blob/main/api/_models/ProcessingRequest.js"
click node_commerce_records "https://github.com/ansukr07/wooltrace/blob/main/api/_models/BiddingListing.js"
click node_learning_resources "https://github.com/ansukr07/wooltrace/blob/main/api/_models/LearningResource.js"
click node_database "https://github.com/ansukr07/wooltrace/blob/main/api/_utils/db.js"
click node_ceda "https://github.com/ansukr07/wooltrace/blob/main/api/_utils/processingCedaService.js"
click node_market_data "https://github.com/ansukr07/wooltrace/blob/main/src/services/market/MarketDataProvider.js"

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_vite,node_app,node_auth_state,node_protected_routes,node_role_workspaces,node_batch_ui,node_traceability,node_qa_ui,node_processing_ui,node_warehouse_transport_ui,node_commerce_ui,node_learning_ui toneBlue
class node_auth_api,node_batch_api,node_qa_api,node_processing_api,node_commerce_api,node_learning_api toneAmber
class node_users,node_batches,node_quality_records,node_processing_records,node_commerce_records,node_learning_resources,node_database toneMint
class node_ceda,node_market_data toneRose
```

## Components

### React browser app

Vite client for role workspaces and public access.

- [Vite bootstrap](https://github.com/ansukr07/wooltrace/blob/main/src/main.jsx): client entry · `src/main.jsx`
- [App routing shell](https://github.com/ansukr07/wooltrace/blob/main/src/App.jsx): React router · `src/App.jsx`
- [Auth and app state](https://github.com/ansukr07/wooltrace/blob/main/src/context/AuthContext.jsx): React contexts · Authentication, shared state, and WoolKart cart state. · `src/context/AuthContext.jsx`
- [Protected routes](https://github.com/ansukr07/wooltrace/blob/main/src/components/ProtectedRoute.jsx): access boundary · `src/components/ProtectedRoute.jsx`
- [Role workspaces](https://github.com/ansukr07/wooltrace/blob/main/src/layouts/FarmerLayout.jsx): role layouts · Farmer, processor, warehouse, and seller application shells. · `src/layouts/FarmerLayout.jsx`
- [Batch tracking UI](https://github.com/ansukr07/wooltrace/blob/main/src/pages/farmer/MyWool.jsx): farmer and public pages · Batch management, tracking, and public traceability views. · `src/pages/farmer/MyWool.jsx`
- [Traceability timeline](https://github.com/ansukr07/wooltrace/blob/main/src/components/TraceabilityTimeline.jsx): shared component · `src/components/TraceabilityTimeline.jsx`
- [Inspection and certificates UI](https://github.com/ansukr07/wooltrace/blob/main/src/pages/inspector/InspectionDetail.jsx): inspector and public pages · Inspection workflows, certificates, and public verification. · `src/pages/inspector/InspectionDetail.jsx`
- [Processing workspace](https://github.com/ansukr07/wooltrace/blob/main/src/pages/processing/ProcessingDashboard.jsx): processor pages · `src/pages/processing/ProcessingDashboard.jsx`
- [Warehouse and transport UI](https://github.com/ansukr07/wooltrace/blob/main/src/pages/warehouse/WarehouseCheckIn.jsx): custody workspace · Check-in, inventory, release, and transport operations. · `src/pages/warehouse/WarehouseCheckIn.jsx`
- [Marketplace and WoolKart UI](https://github.com/ansukr07/wooltrace/blob/main/src/pages/seller/Marketplace.jsx): seller and farmer pages · Listings, bids, orders, inventory, cart, and checkout. · `src/pages/seller/Marketplace.jsx`
- [Academy and resource library](https://github.com/ansukr07/wooltrace/blob/main/src/pages/farmer/Academy.jsx): learning pages · `src/pages/farmer/Academy.jsx`

### Serverless API

Vercel route handlers and backend orchestration.

- [Authentication API](https://github.com/ansukr07/wooltrace/blob/main/api/login.js): serverless routes · Registration and login endpoints. · `api/login.js`
- [Batch API](https://github.com/ansukr07/wooltrace/blob/main/api/batches.js): serverless route · `api/batches.js`
- [Quality API](https://github.com/ansukr07/wooltrace/blob/main/api/qa.js): serverless route · Handles inspection requests, certificates, and verification. · `api/qa.js`
- [Processing API](https://github.com/ansukr07/wooltrace/blob/main/api/processing.js): serverless route · Coordinates processing records and CEDA integration. · `api/processing.js`
- [Bidding and market APIs](https://github.com/ansukr07/wooltrace/blob/main/api/bidding.js): serverless routes · Listing, bid, order, and inventory endpoints. · `api/bidding.js`
- [Learning resources API](https://github.com/ansukr07/wooltrace/blob/main/api/learning-resources.js): serverless route · `api/learning-resources.js`

### Domain persistence

Shared database models.

- [Users and roles](https://github.com/ansukr07/wooltrace/blob/main/api/_models/User.js): User model · `api/_models/User.js`
- [Wool batches](https://github.com/ansukr07/wooltrace/blob/main/api/_models/WoolBatch.js): WoolBatch model · Central traceability entity. · `api/_models/WoolBatch.js`
- [Inspection and certificates](https://github.com/ansukr07/wooltrace/blob/main/api/_models/InspectionRequest.js): quality models · Inspection requests and quality certificates. · `api/_models/InspectionRequest.js`
- [Processing records](https://github.com/ansukr07/wooltrace/blob/main/api/_models/ProcessingRequest.js): processing models · Processing requests and conversion records. · `api/_models/ProcessingRequest.js`
- [Listings, bids, and orders](https://github.com/ansukr07/wooltrace/blob/main/api/_models/BiddingListing.js): commerce models · Marketplace bidding and order persistence. · `api/_models/BiddingListing.js`
- [Learning resources](https://github.com/ansukr07/wooltrace/blob/main/api/_models/LearningResource.js): LearningResource model · `api/_models/LearningResource.js`
- [Database connection](https://github.com/ansukr07/wooltrace/blob/main/api/_utils/db.js): shared DB utility · Shared model and route database setup. · `api/_utils/db.js`

### External integration

- [CEDA integration](https://github.com/ansukr07/wooltrace/blob/main/api/_utils/processingCedaService.js): external processing service · `api/_utils/processingCedaService.js`
- [Market data providers](https://github.com/ansukr07/wooltrace/blob/main/src/services/market/MarketDataProvider.js): provider layer · Demo and Agmarknet market-data implementations. · `src/services/market/MarketDataProvider.js`

## Connections

- Vite bootstrap → App routing shell: mounts
- App routing shell → Auth and app state: uses
- App routing shell → Protected routes: routes through
- Protected routes → Role workspaces: authorizes
- Role workspaces → Batch tracking UI: hosts
- Batch tracking UI → Traceability timeline: renders
- Batch tracking UI → Batch API: manages batches
- Inspection and certificates UI → Quality API: inspection workflow
- Processing workspace → Processing API: submits processing
- Warehouse and transport UI → Batch API: updates custody
- Marketplace and WoolKart UI → Bidding and market APIs: trades and orders
- Marketplace and WoolKart UI → Market data providers: reads pricing
- Academy and resource library → Learning resources API: uses resources
- Auth and app state → Authentication API: authenticates
- Authentication API → Users and roles: reads and writes
- Batch API → Wool batches: persists
- Quality API → Wool batches: traces batch
- Quality API → Inspection and certificates: persists
- Processing API → Wool batches: updates lifecycle
- Processing API → Processing records: persists
- Processing API → CEDA integration: integrates
- Bidding and market APIs → Wool batches: lists inventory
- Bidding and market APIs → Listings, bids, and orders: persists
- Learning resources API → Learning resources: persists
- Users and roles → Database connection: connects via
- Wool batches → Database connection: connects via
- Inspection and certificates → Database connection: connects via
- Processing records → Database connection: connects via
- Listings, bids, and orders → Database connection: connects via
- Learning resources → Database connection: connects via
