# huzaifatg/loadflow architecture

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

- Interactive diagram: https://gitdiagram.com/huzaifatg/loadflow
- Repository: https://github.com/huzaifatg/loadflow

## Overview

LoadFlow is a multi-tenant logistics SaaS. Users manage deliveries, drivers, trucks, and load plans through the dashboard; recommendation and load-planning services support resource assignment. A second major workflow ingests CSVs through parsing, adaptation, validation, mapping, preview, and transactional commit. Authentication resolves a user’s company, while API routes serve domain operations and Prisma persists data. The graph retains README-documented schedule and settings capabilities; relationships for unsampled modules are limited to documented or indexed wiring.

Main entry points: [`lib/import/pipeline/engine.ts`](https://github.com/huzaifatg/loadflow/blob/main/lib/import/pipeline/engine.ts) (Import pipeline), [`lib/prisma.ts`](https://github.com/huzaifatg/loadflow/blob/main/lib/prisma.ts) (Prisma database), [`lib/auth.ts`](https://github.com/huzaifatg/loadflow/blob/main/lib/auth.ts) (Auth context), [`app/api/deliveries/route.ts`](https://github.com/huzaifatg/loadflow/blob/main/app/api/deliveries/route.ts) (Delivery management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_landing["Landing page<br/>[LandingPage.tsx]"]
  node_dashboard["Dashboard workspace<br/>[page.tsx]"]
  node_authpages["Login and signup<br/>[page.tsx]"]
end

subgraph group_identity["Identity and tenancy"]
  node_auth["Auth context<br/>[auth.ts]"]
  node_supabase["Supabase session<br/>[server.ts]"]
  node_security["Tenant safeguards<br/>[tenant.ts]"]
end

subgraph group_operations["Logistics operations"]
  node_deliveries["Delivery management<br/>[route.ts]"]
  node_deliveryitems["Item weights<br/>[delivery-items.ts]"]
  node_fleet["Drivers and trucks<br/>[page.tsx]"]
  node_loads["Load planning<br/>[page.tsx]"]
  node_validation["Plan validation"]
  node_recommendations["Recommendations"]
  node_schedule["Schedule view<br/>[page.tsx]"]
  node_settings["Company settings<br/>[page.tsx]"]
end

subgraph group_ingestion["CSV ingestion"]
  node_csvapi["CSV import API<br/>[route.ts]"]
  node_pipeline["Import pipeline<br/>[engine.ts]"]
  node_contract["Import contract<br/>[types.ts]"]
  node_csvstages["Parse and adapt<br/>[parser.ts]"]
  node_validateimport["Import validation<br/>[engine.ts]"]
  node_mapping["Field mapping<br/>[engine.ts]"]
  node_preview["Import preview<br/>[engine.ts]"]
  node_commit["Import commit<br/>[engine.ts]"]
  node_commitstorage["Commit persistence<br/>[persistence.ts]"]
end

subgraph group_platform["Persistence"]
  node_prisma[("Prisma database<br/>[prisma.ts]")]
end

node_visitor(("User"))

node_visitor -->|"visits"| node_landing
node_visitor -.->|"signs in"| node_authpages
node_visitor -.->|"manages logistics"| node_dashboard
node_landing -.->|"starts workflow"| node_dashboard
node_authpages -.->|"authenticates via"| node_auth
node_dashboard -->|"resolves company"| node_auth
node_auth -->|"checks session"| node_supabase
node_auth -->|"resolves membership"| node_prisma
node_deliveries -->|"authenticates"| node_auth
node_deliveries -->|"checks tenant access"| node_security
node_deliveries -->|"computes weights"| node_deliveryitems
node_deliveries -->|"reads and writes"| node_prisma
node_fleet -.->|"manages records"| node_prisma
node_loads -.->|"requests assignments"| node_recommendations
node_recommendations -->|"converts weights"| node_deliveryitems
node_recommendations -->|"loads candidates"| node_prisma
node_loads -->|"validates plans"| node_validation
node_schedule -.->|"shows schedule data"| node_prisma
node_settings -.->|"updates company"| node_prisma
node_visitor -.->|"submits CSV"| node_csvapi
node_csvapi -->|"authenticates"| node_auth
node_csvapi -->|"checks tenant access"| node_security
node_csvapi -->|"invokes import"| node_pipeline
node_pipeline -->|"parses and adapts"| node_csvstages
node_pipeline -->|"validates"| node_validateimport
node_pipeline -->|"maps fields"| node_mapping
node_pipeline -->|"previews changes"| node_preview
node_pipeline -->|"commits approved rows"| node_commit
node_commit -->|"persists rows"| node_commitstorage
node_commitstorage -.->|"writes transaction"| node_prisma
node_pipeline -->|"uses document contract"| node_contract
node_preview -->|"consumes and enriches"| node_contract
node_commit -->|"guards document state"| node_contract

click node_landing "https://github.com/huzaifatg/loadflow/blob/main/components/landing/LandingPage.tsx"
click node_dashboard "https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/dashboard/page.tsx"
click node_authpages "https://github.com/huzaifatg/loadflow/blob/main/app/(auth)/login/page.tsx"
click node_auth "https://github.com/huzaifatg/loadflow/blob/main/lib/auth.ts"
click node_supabase "https://github.com/huzaifatg/loadflow/blob/main/lib/supabase/server.ts"
click node_security "https://github.com/huzaifatg/loadflow/blob/main/lib/security/tenant.ts"
click node_deliveries "https://github.com/huzaifatg/loadflow/blob/main/app/api/deliveries/route.ts"
click node_deliveryitems "https://github.com/huzaifatg/loadflow/blob/main/lib/delivery-items.ts"
click node_fleet "https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/drivers/page.tsx"
click node_loads "https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/loads/page.tsx"
click node_validation "https://github.com/huzaifatg/loadflow/blob/main/lib/services/load-plan-validation.ts"
click node_recommendations "https://github.com/huzaifatg/loadflow/blob/main/lib/services/recommendation-engine.ts"
click node_schedule "https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/schedule/page.tsx"
click node_settings "https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/settings/page.tsx"
click node_csvapi "https://github.com/huzaifatg/loadflow/blob/main/app/api/import/csv/route.ts"
click node_pipeline "https://github.com/huzaifatg/loadflow/blob/main/lib/import/pipeline/engine.ts"
click node_contract "https://github.com/huzaifatg/loadflow/blob/main/lib/import/contract/types.ts"
click node_csvstages "https://github.com/huzaifatg/loadflow/blob/main/lib/import/csv/parser.ts"
click node_validateimport "https://github.com/huzaifatg/loadflow/blob/main/lib/import/validation/engine.ts"
click node_mapping "https://github.com/huzaifatg/loadflow/blob/main/lib/import/mapping/engine.ts"
click node_preview "https://github.com/huzaifatg/loadflow/blob/main/lib/import/preview/engine.ts"
click node_commit "https://github.com/huzaifatg/loadflow/blob/main/lib/import/commit/engine.ts"
click node_commitstorage "https://github.com/huzaifatg/loadflow/blob/main/lib/import/commit/persistence.ts"
click node_prisma "https://github.com/huzaifatg/loadflow/blob/main/lib/prisma.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_landing,node_dashboard,node_authpages,node_visitor toneBlue
class node_auth,node_supabase,node_security toneAmber
class node_deliveries,node_deliveryitems,node_fleet,node_loads,node_validation,node_recommendations,node_schedule,node_settings toneMint
class node_csvapi,node_pipeline,node_contract,node_csvstages,node_validateimport,node_mapping,node_preview,node_commit,node_commitstorage toneRose
class node_prisma toneIndigo
```

## Components

### Web experience

- [Landing page](https://github.com/huzaifatg/loadflow/blob/main/components/landing/LandingPage.tsx): `components/landing/LandingPage.tsx`
- [Dashboard workspace](https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/dashboard/page.tsx): `app/(dashboard)/dashboard/page.tsx`
- [Login and signup](https://github.com/huzaifatg/loadflow/blob/main/app/(auth)/login/page.tsx): `app/(auth)/login/page.tsx`

### Identity and tenancy

- [Auth context](https://github.com/huzaifatg/loadflow/blob/main/lib/auth.ts): `lib/auth.ts`
- [Supabase session](https://github.com/huzaifatg/loadflow/blob/main/lib/supabase/server.ts): `lib/supabase/server.ts`
- [Tenant safeguards](https://github.com/huzaifatg/loadflow/blob/main/lib/security/tenant.ts): `lib/security/tenant.ts`

### Logistics operations

- [Delivery management](https://github.com/huzaifatg/loadflow/blob/main/app/api/deliveries/route.ts): `app/api/deliveries/route.ts`
- [Item weights](https://github.com/huzaifatg/loadflow/blob/main/lib/delivery-items.ts): `lib/delivery-items.ts`
- [Drivers and trucks](https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/drivers/page.tsx): `app/(dashboard)/drivers/page.tsx`
- [Load planning](https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/loads/page.tsx): `app/(dashboard)/loads/page.tsx`
- [Plan validation](https://github.com/huzaifatg/loadflow/blob/main/lib/services/load-plan-validation.ts): `lib/services/load-plan-validation.ts`
- [Recommendations](https://github.com/huzaifatg/loadflow/blob/main/lib/services/recommendation-engine.ts): `lib/services/recommendation-engine.ts`
- [Schedule view](https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/schedule/page.tsx): `app/(dashboard)/schedule/page.tsx`
- [Company settings](https://github.com/huzaifatg/loadflow/blob/main/app/(dashboard)/settings/page.tsx): `app/(dashboard)/settings/page.tsx`

### CSV ingestion

- [CSV import API](https://github.com/huzaifatg/loadflow/blob/main/app/api/import/csv/route.ts): `app/api/import/csv/route.ts`
- [Import pipeline](https://github.com/huzaifatg/loadflow/blob/main/lib/import/pipeline/engine.ts): `lib/import/pipeline/engine.ts`
- [Import contract](https://github.com/huzaifatg/loadflow/blob/main/lib/import/contract/types.ts): `lib/import/contract/types.ts`
- [Parse and adapt](https://github.com/huzaifatg/loadflow/blob/main/lib/import/csv/parser.ts): `lib/import/csv/parser.ts`
- [Import validation](https://github.com/huzaifatg/loadflow/blob/main/lib/import/validation/engine.ts): `lib/import/validation/engine.ts`
- [Field mapping](https://github.com/huzaifatg/loadflow/blob/main/lib/import/mapping/engine.ts): `lib/import/mapping/engine.ts`
- [Import preview](https://github.com/huzaifatg/loadflow/blob/main/lib/import/preview/engine.ts): `lib/import/preview/engine.ts`
- [Import commit](https://github.com/huzaifatg/loadflow/blob/main/lib/import/commit/engine.ts): `lib/import/commit/engine.ts`
- [Commit persistence](https://github.com/huzaifatg/loadflow/blob/main/lib/import/commit/persistence.ts): `lib/import/commit/persistence.ts`

### Persistence

- [Prisma database](https://github.com/huzaifatg/loadflow/blob/main/lib/prisma.ts): `lib/prisma.ts`

### Other components

- **User**

## Connections

- User → Landing page: visits
- User → Login and signup: signs in (evidence: `README.md`)
- User → Dashboard workspace: manages logistics (evidence: `README.md`)
- Landing page → Dashboard workspace: starts workflow (evidence: `README.md`)
- Login and signup → Auth context: authenticates via (evidence: `README.md`)
- Dashboard workspace → Auth context: resolves company (evidence: `app/(dashboard)/dashboard/page.tsx`)
- Auth context → Supabase session: checks session (evidence: `lib/auth.ts`)
- Auth context → Prisma database: resolves membership (evidence: `lib/auth.ts`)
- Delivery management → Auth context: authenticates (evidence: `app/api/deliveries/route.ts`)
- Delivery management → Tenant safeguards: checks tenant access (evidence: `app/api/deliveries/route.ts`)
- Delivery management → Item weights: computes weights (evidence: `app/api/deliveries/route.ts`)
- Delivery management → Prisma database: reads and writes (evidence: `app/api/deliveries/route.ts`)
- Drivers and trucks → Prisma database: manages records (evidence: `README.md`)
- Load planning → Recommendations: requests assignments (evidence: `README.md`)
- Recommendations → Item weights: converts weights (evidence: `lib/services/recommendation-engine.ts`)
- Recommendations → Prisma database: loads candidates (evidence: `app/api/recommendations/route.ts`)
- Load planning → Plan validation: validates plans
- Schedule view → Prisma database: shows schedule data (evidence: `README.md`)
- Company settings → Prisma database: updates company (evidence: `README.md`)
- User → CSV import API: submits CSV (evidence: `README.md`)
- CSV import API → Auth context: authenticates (evidence: `app/api/import/csv/route.ts`)
- CSV import API → Tenant safeguards: checks tenant access (evidence: `app/api/import/csv/route.ts`)
- CSV import API → Import pipeline: invokes import (evidence: `app/api/import/csv/route.ts`)
- Import pipeline → Parse and adapt: parses and adapts (evidence: `lib/import/pipeline/engine.ts`)
- Import pipeline → Import validation: validates (evidence: `lib/import/pipeline/engine.ts`)
- Import pipeline → Field mapping: maps fields (evidence: `lib/import/pipeline/engine.ts`)
- Import pipeline → Import preview: previews changes (evidence: `lib/import/pipeline/engine.ts`)
- Import pipeline → Import commit: commits approved rows (evidence: `lib/import/pipeline/engine.ts`)
- Import commit → Commit persistence: persists rows (evidence: `lib/import/commit/engine.ts`)
- Commit persistence → Prisma database: writes transaction
- Import pipeline → Import contract: uses document contract (evidence: `lib/import/pipeline/engine.ts`)
- Import preview → Import contract: consumes and enriches (evidence: `lib/import/preview/engine.ts`)
- Import commit → Import contract: guards document state (evidence: `lib/import/commit/engine.ts`)
