# git791/chain-guard-ai architecture

> Architecture diagram of the GitHub repository git791/chain-guard-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/git791/chain-guard-ai
- Repository: https://github.com/git791/chain-guard-ai

## Overview

ChainGuard AI is a logistics command center for shipment visibility, disruption awareness, AI-generated operational suggestions, and sustainability reporting. Managers sign in, inspect live shipment status and routes, create shipments, and review analytics; Firestore snapshots feed the tracking views, while a delay-triggered function records event-feed alerts. The README also describes automated rerouting, but sampled code shows Gemini suggestions rather than an implemented route-approval or persistence flow. Wiring from the dashboard’s insight widget to the Gemini endpoint was not sampled, so that connection is omitted.

Main entry points: [`app/page.js`](https://github.com/git791/chain-guard-ai/blob/main/app/page.js) (Command Dashboard), [`lib/AuthContext.js`](https://github.com/git791/chain-guard-ai/blob/main/lib/AuthContext.js) (Auth Context), [`hooks/useShipments.js`](https://github.com/git791/chain-guard-ai/blob/main/hooks/useShipments.js) (Shipment Feed), [`app/routes/page.js`](https://github.com/git791/chain-guard-ai/blob/main/app/routes/page.js) (Live Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Access and Profile"]
  node_login["Sign In<br/>[page.js]"]
  node_auth["Auth Context<br/>[AuthContext.js]"]
  node_settings["Profile Settings<br/>[page.js]"]
end

subgraph group_tracking["Shipment Operations"]
  node_dashboard["Command Dashboard<br/>[page.js]"]
  node_shipment_hook["Shipment Feed<br/>[useShipments.js]"]
  node_shipment_list["Shipment List<br/>[ShipmentList.jsx]"]
  node_create_shipment["Create Shipment"]
end

subgraph group_intelligence["Risk and Insights"]
  node_delay_function["Delay Detector<br/>[index.js]"]
  node_event_feed[("Event Feed")]
  node_disruptions["Disruption Alerts<br/>[DisruptionList.jsx]"]
  node_insights["AI Insights View<br/>[AIInsights.jsx]"]
  node_gemini_route["Gemini API Route<br/>[route.js]"]
end

subgraph group_reporting["Mapping and Analytics"]
  node_routes_page["Live Routes<br/>[page.js]"]
  node_map["Route Map<br/>[Map.jsx]"]
  node_analytics_page["Sustainability Analytics<br/>[page.js]"]
  node_chart["Trend Chart<br/>[Chart.jsx]"]
end

node_manager(("Logistics Manager"))
node_firebase_auth[("Firebase Auth")]
node_firestore[("Firestore")]
node_gemini{{"Gemini"}}
node_google_maps{{"Google Maps API"}}

node_manager -->|"submits credentials"| node_login
node_login -->|"calls login"| node_auth
node_auth -->|"authenticates"| node_firebase_auth
node_manager -->|"views operations"| node_dashboard
node_dashboard -->|"checks session"| node_auth
node_manager -->|"edits profile"| node_settings
node_settings -->|"updates profile"| node_auth
node_dashboard -->|"loads shipments"| node_shipment_hook
node_shipment_hook -->|"subscribes to shipments"| node_firestore
node_dashboard -->|"renders shipments"| node_shipment_list
node_manager -->|"enters shipment"| node_create_shipment
node_create_shipment -->|"adds shipment"| node_firestore
node_firestore -->|"dispatches update"| node_delay_function
node_delay_function -->|"writes delay event"| node_event_feed
node_dashboard -->|"renders alerts"| node_disruptions
node_dashboard -->|"renders insights"| node_insights
node_gemini_route -->|"requests generation"| node_gemini
node_manager -->|"views live routes"| node_routes_page
node_routes_page -->|"loads shipments"| node_shipment_hook
node_routes_page -->|"passes shipments"| node_map
node_dashboard -->|"passes shipments"| node_map
node_map -.->|"renders map"| node_google_maps
node_manager -->|"views sustainability"| node_analytics_page
node_analytics_page -->|"loads shipments"| node_shipment_hook
node_analytics_page -->|"renders trend"| node_chart

click node_login "https://github.com/git791/chain-guard-ai/blob/main/app/login/page.js"
click node_auth "https://github.com/git791/chain-guard-ai/blob/main/lib/AuthContext.js"
click node_settings "https://github.com/git791/chain-guard-ai/blob/main/app/settings/page.js"
click node_dashboard "https://github.com/git791/chain-guard-ai/blob/main/app/page.js"
click node_shipment_hook "https://github.com/git791/chain-guard-ai/blob/main/hooks/useShipments.js"
click node_shipment_list "https://github.com/git791/chain-guard-ai/blob/main/components/ShipmentList.jsx"
click node_create_shipment "https://github.com/git791/chain-guard-ai/blob/main/components/CreateShipmentModal.jsx"
click node_delay_function "https://github.com/git791/chain-guard-ai/blob/main/functions/index.js"
click node_disruptions "https://github.com/git791/chain-guard-ai/blob/main/components/DisruptionList.jsx"
click node_insights "https://github.com/git791/chain-guard-ai/blob/main/components/AIInsights.jsx"
click node_gemini_route "https://github.com/git791/chain-guard-ai/blob/main/app/api/gemini/route.js"
click node_routes_page "https://github.com/git791/chain-guard-ai/blob/main/app/routes/page.js"
click node_map "https://github.com/git791/chain-guard-ai/blob/main/components/Map.jsx"
click node_analytics_page "https://github.com/git791/chain-guard-ai/blob/main/app/analytics/page.js"
click node_chart "https://github.com/git791/chain-guard-ai/blob/main/components/Chart.jsx"

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_login,node_auth,node_settings toneBlue
class node_dashboard,node_shipment_hook,node_shipment_list,node_create_shipment,node_firebase_auth,node_firestore toneAmber
class node_delay_function,node_event_feed,node_disruptions,node_insights,node_gemini_route,node_google_maps toneMint
class node_routes_page,node_map,node_analytics_page,node_chart toneRose
class node_manager,node_gemini toneIndigo
```

## Components

### Access and Profile

- [Sign In](https://github.com/git791/chain-guard-ai/blob/main/app/login/page.js): `app/login/page.js`
- [Auth Context](https://github.com/git791/chain-guard-ai/blob/main/lib/AuthContext.js): `lib/AuthContext.js`
- [Profile Settings](https://github.com/git791/chain-guard-ai/blob/main/app/settings/page.js): `app/settings/page.js`

### Shipment Operations

- [Command Dashboard](https://github.com/git791/chain-guard-ai/blob/main/app/page.js): `app/page.js`
- [Shipment Feed](https://github.com/git791/chain-guard-ai/blob/main/hooks/useShipments.js): `hooks/useShipments.js`
- [Shipment List](https://github.com/git791/chain-guard-ai/blob/main/components/ShipmentList.jsx): `components/ShipmentList.jsx`
- [Create Shipment](https://github.com/git791/chain-guard-ai/blob/main/components/CreateShipmentModal.jsx): `components/CreateShipmentModal.jsx`

### Risk and Insights

- [Delay Detector](https://github.com/git791/chain-guard-ai/blob/main/functions/index.js): `functions/index.js`
- **Event Feed**
- [Disruption Alerts](https://github.com/git791/chain-guard-ai/blob/main/components/DisruptionList.jsx): `components/DisruptionList.jsx`
- [AI Insights View](https://github.com/git791/chain-guard-ai/blob/main/components/AIInsights.jsx): `components/AIInsights.jsx`
- [Gemini API Route](https://github.com/git791/chain-guard-ai/blob/main/app/api/gemini/route.js): `app/api/gemini/route.js`

### Mapping and Analytics

- [Live Routes](https://github.com/git791/chain-guard-ai/blob/main/app/routes/page.js): `app/routes/page.js`
- [Route Map](https://github.com/git791/chain-guard-ai/blob/main/components/Map.jsx): `components/Map.jsx`
- [Sustainability Analytics](https://github.com/git791/chain-guard-ai/blob/main/app/analytics/page.js): `app/analytics/page.js`
- [Trend Chart](https://github.com/git791/chain-guard-ai/blob/main/components/Chart.jsx): `components/Chart.jsx`

### Other components

- **Logistics Manager**
- **Firebase Auth**
- **Firestore**
- **Gemini**
- **Google Maps API**

## Connections

- Logistics Manager → Sign In: submits credentials
- Sign In → Auth Context: calls login
- Auth Context → Firebase Auth: authenticates
- Logistics Manager → Command Dashboard: views operations
- Command Dashboard → Auth Context: checks session
- Logistics Manager → Profile Settings: edits profile
- Profile Settings → Auth Context: updates profile
- Command Dashboard → Shipment Feed: loads shipments
- Shipment Feed → Firestore: subscribes to shipments
- Command Dashboard → Shipment List: renders shipments
- Logistics Manager → Create Shipment: enters shipment
- Create Shipment → Firestore: adds shipment
- Firestore → Delay Detector: dispatches update
- Delay Detector → Event Feed: writes delay event
- Command Dashboard → Disruption Alerts: renders alerts
- Command Dashboard → AI Insights View: renders insights
- Gemini API Route → Gemini: requests generation
- Logistics Manager → Live Routes: views live routes
- Live Routes → Shipment Feed: loads shipments
- Live Routes → Route Map: passes shipments
- Command Dashboard → Route Map: passes shipments
- Route Map → Google Maps API: renders map
- Logistics Manager → Sustainability Analytics: views sustainability
- Sustainability Analytics → Shipment Feed: loads shipments
- Sustainability Analytics → Trend Chart: renders trend
