# mayur-anand-cys/residueguard architecture

> Architecture diagram of the GitHub repository mayur-anand-cys/residueguard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mayur-anand-cys/residueguard
- Repository: https://github.com/mayur-anand-cys/residueguard

## Overview

ResidueGuard is an agri-tech compliance prototype whose main workflow is entering spray and market details, calculating harvest safety, and presenting the result to FPO staff or buyers. Its dashboard also exposes policy checks and audit verification; the README describes additional environmental and anti-fraud capabilities that are represented within the dashboard rather than as separately verified services. The excerpts confirm the dashboard’s kinetics and audit dependencies and the app’s routing, auth, and preview bridge. Several feature details and backend relationships are documented but their implementations were not sampled.

Main entry points: [`src/components/residue-guard.tsx`](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx) (Compliance dashboard), [`src/routes/__root.tsx`](https://github.com/mayur-anand-cys/residueguard/blob/main/src/routes/__root.tsx) (App shell), [`src/router.tsx`](https://github.com/mayur-anand-cys/residueguard/blob/main/src/router.tsx) (App router), [`src/lib/auth/provider.tsx`](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/auth/provider.tsx) (Auth provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["Compliance product"]
  node_dashboard["Compliance dashboard<br/>[residue-guard.tsx]"]
  node_chemical_data[("Chemical reference data<br/>[mockData.js]")]
  node_kinetics["MSI kinetics<br/>[kinetics.ts]"]
  node_policy["Market policy checks<br/>[residue-guard.tsx]"]
  node_environment["Environmental modifiers<br/>[residue-guard.tsx]"]
  node_antifraud["Anti-fraud checks<br/>[residue-guard.tsx]"]
end

subgraph group_integrity["Audit integrity"]
  node_audit_ui["Buyer audit view<br/>[residue-guard.tsx]"]
  node_audit_chain["Hash-chain verification<br/>[chain.ts]"]
  node_audit_store[("Audit event store<br/>[store.ts]")]
end

subgraph group_platform["App platform"]
  node_router["App router<br/>[router.tsx]"]
  node_routes["Route tree<br/>[routeTree.gen.ts]"]
  node_root["App shell<br/>[__root.tsx]"]
  node_auth_provider["Auth provider<br/>[provider.tsx]"]
  node_auth_server["Auth service<br/>[server.ts]"]
  node_database[("App database<br/>[db.ts]")]
  node_preview_bridge["Preview host bridge"]
end

subgraph group_localization["Localization"]
  node_language["Language provider"]
  node_translations["Translation messages<br/>[translations.ts]"]
end

node_farmer(("FPO user"))
node_buyer(("Buyer auditor"))
node_embedder["Grok preview host"]

node_farmer -->|"opens app"| node_router
node_buyer -->|"opens app"| node_router
node_router -->|"loads routes"| node_routes
node_root -->|"renders"| node_auth_provider
node_root -->|"renders"| node_language
node_language -.->|"uses messages"| node_translations
node_dashboard -->|"reads data"| node_chemical_data
node_dashboard -->|"calculates MSI"| node_kinetics
node_dashboard -->|"presents checks"| node_policy
node_dashboard -->|"applies modifiers"| node_environment
node_dashboard -->|"presents alerts"| node_antifraud
node_dashboard -->|"uses verification"| node_audit_chain
node_dashboard -->|"uses audit events"| node_audit_store
node_audit_ui -->|"verifies chain"| node_audit_chain
node_audit_ui -->|"reads history"| node_audit_store
node_auth_provider -.->|"configures auth"| node_auth_server
node_auth_server -->|"persists sessions"| node_database
node_root -->|"renders bridge"| node_preview_bridge
node_preview_bridge -->|"posts messages"| node_embedder

click node_router "https://github.com/mayur-anand-cys/residueguard/blob/main/src/router.tsx"
click node_routes "https://github.com/mayur-anand-cys/residueguard/blob/main/src/routeTree.gen.ts"
click node_root "https://github.com/mayur-anand-cys/residueguard/blob/main/src/routes/__root.tsx"
click node_dashboard "https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx"
click node_chemical_data "https://github.com/mayur-anand-cys/residueguard/blob/main/src/mockData.js"
click node_kinetics "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/kinetics.ts"
click node_policy "https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx"
click node_environment "https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx"
click node_antifraud "https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx"
click node_audit_ui "https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx"
click node_audit_chain "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/audit/chain.ts"
click node_audit_store "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/audit/store.ts"
click node_auth_provider "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/auth/provider.tsx"
click node_auth_server "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/auth/server.ts"
click node_database "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/db.ts"
click node_language "https://github.com/mayur-anand-cys/residueguard/blob/main/src/i18n/LanguageProvider.tsx"
click node_translations "https://github.com/mayur-anand-cys/residueguard/blob/main/src/i18n/translations.ts"
click node_preview_bridge "https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/preview-host-bridge.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_dashboard,node_chemical_data,node_kinetics,node_policy,node_environment,node_antifraud,node_farmer,node_embedder toneBlue
class node_audit_ui,node_audit_chain,node_audit_store toneAmber
class node_router,node_routes,node_root,node_auth_provider,node_auth_server,node_database,node_preview_bridge toneMint
class node_language,node_translations toneRose
class node_buyer toneIndigo
```

## Components

### Compliance product

- [Compliance dashboard](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx): `src/components/residue-guard.tsx`
- [Chemical reference data](https://github.com/mayur-anand-cys/residueguard/blob/main/src/mockData.js): `src/mockData.js`
- [MSI kinetics](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/kinetics.ts): `src/lib/kinetics.ts`
- [Market policy checks](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx): `src/components/residue-guard.tsx`
- [Environmental modifiers](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx): `src/components/residue-guard.tsx`
- [Anti-fraud checks](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx): `src/components/residue-guard.tsx`

### Audit integrity

- [Buyer audit view](https://github.com/mayur-anand-cys/residueguard/blob/main/src/components/residue-guard.tsx): `src/components/residue-guard.tsx`
- [Hash-chain verification](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/audit/chain.ts): `src/lib/audit/chain.ts`
- [Audit event store](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/audit/store.ts): `src/lib/audit/store.ts`

### App platform

- [App router](https://github.com/mayur-anand-cys/residueguard/blob/main/src/router.tsx): `src/router.tsx`
- [Route tree](https://github.com/mayur-anand-cys/residueguard/blob/main/src/routeTree.gen.ts): `src/routeTree.gen.ts`
- [App shell](https://github.com/mayur-anand-cys/residueguard/blob/main/src/routes/__root.tsx): `src/routes/__root.tsx`
- [Auth provider](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/auth/provider.tsx): `src/lib/auth/provider.tsx`
- [Auth service](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/auth/server.ts): `src/lib/auth/server.ts`
- [App database](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [Preview host bridge](https://github.com/mayur-anand-cys/residueguard/blob/main/src/lib/preview-host-bridge.ts): `src/lib/preview-host-bridge.ts`

### Localization

- [Language provider](https://github.com/mayur-anand-cys/residueguard/blob/main/src/i18n/LanguageProvider.tsx): `src/i18n/LanguageProvider.tsx`
- [Translation messages](https://github.com/mayur-anand-cys/residueguard/blob/main/src/i18n/translations.ts): `src/i18n/translations.ts`

### Other components

- **FPO user**
- **Buyer auditor**
- **Grok preview host**

## Connections

- FPO user → App router: opens app (evidence: `README.md`)
- Buyer auditor → App router: opens app (evidence: `README.md`)
- App router → Route tree: loads routes (evidence: `src/router.tsx`)
- App shell → Auth provider: renders (evidence: `src/routes/__root.tsx`)
- App shell → Language provider: renders (evidence: `src/routes/__root.tsx`)
- Language provider → Translation messages: uses messages
- Compliance dashboard → Chemical reference data: reads data (evidence: `src/components/residue-guard.tsx`)
- Compliance dashboard → MSI kinetics: calculates MSI (evidence: `src/components/residue-guard.tsx`)
- Compliance dashboard → Market policy checks: presents checks (evidence: `README.md`)
- Compliance dashboard → Environmental modifiers: applies modifiers (evidence: `README.md`)
- Compliance dashboard → Anti-fraud checks: presents alerts (evidence: `README.md`)
- Compliance dashboard → Hash-chain verification: uses verification (evidence: `src/components/residue-guard.tsx`)
- Compliance dashboard → Audit event store: uses audit events (evidence: `src/components/residue-guard.tsx`)
- Buyer audit view → Hash-chain verification: verifies chain (evidence: `README.md`)
- Buyer audit view → Audit event store: reads history (evidence: `src/components/residue-guard.tsx`)
- Auth provider → Auth service: configures auth
- Auth service → App database: persists sessions (evidence: `src/lib/auth/server.ts`)
- App shell → Preview host bridge: renders bridge (evidence: `src/routes/__root.tsx`)
- Preview host bridge → Grok preview host: posts messages (evidence: `src/lib/preview-host-bridge.ts`)
