# aalzriqat/auto architecture

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

- Interactive diagram: https://gitdiagram.com/aalzriqat/auto
- Repository: https://github.com/aalzriqat/auto

## Overview

#### Purpose and Runtime Topology
AutoFlow is a multi-tenant dealership operating system: inventory, CRM/leads, sales and financing, accounting, workforce operations, and a cross-dealer marketplace. It runs as a pnpm monorepo with a Next.js web client, Expo/React Native mobile client, Convex backend, and Cloudflare edge worker. Primary web entry points are `app/layout.tsx`, `app/page.tsx`, and organization-scoped dashboard routes under `app/(dashboard)/[orgId]/`.

#### Web Application Boundaries
Next.js App Router separates public marketing/marketplace/dealer-hosted sites from authenticated organization workspaces and a platform-admin control plane. The org ID is a route-level tenancy boundary, with shared dashboard layout/navigation around domain pages. Relevant paths: `app/(dashboard)/[orgId]/layout.tsx`, `app/(dashboard)/[orgId]/sales/page.tsx`, `app/admin/layout.tsx`. Public dealer sites are dynamically rendered by slug/theme at `app/dealer-site/[[...slug]]/page.tsx`.

#### Backend Authority and Tenancy
Convex is the shared reactive database and server-function layer consumed by web and mobile through generated APIs. Its schema is centralized in `convex/schema.ts`; domain mutations/queries must enforce authenticated org scope and permissions rather than trust UI state. Tenancy and role authorization form the core security boundary in `convex/utils/tenancy.ts`, with membership/role data managed by `convex/memberships.ts` and `convex/roles.ts`. Clerk authenticates users; Clerk-to-Convex synchronization uses configured backend auth/webhook infrastructure.

#### Dealership Operational Domains
Vehicles, customers/leads, applications, quotes/sales, deposits, and financing form the operational transaction chain. Sales workflow UI is staged and captures customer, vehicle, finance, review, and completion actions in `components/sales/wizard/SalesWizard.tsx`, `components/sales/wizard/steps/Step1QuoteSetup.tsx`, and `components/sales/wizard/steps/Step3Review.tsx`. Backend lifecycle ownership resides in `convex/vehicles.ts`, `convex/leads.ts`, and `convex/sales.ts`; approval gates and audit-aware transitions are handled by `convex/approvals.ts`.

#### Financial System and Accounting Boundary
The accounting subsystem translates business events into double-entry ledger postings, reports, reconciliations, and period controls. Posting rules/engine are isolated under `convex/accounting/postingRules.ts` and `convex/accounting/postingEngine.ts`; sale and workflow hooks feed this boundary via `convex/accounting/workflowHooks.ts`. The accounting workspace is exposed from `app/(dashboard)/[orgId]/accounting/page.tsx` and assembled in `components/accounting/AccountingClient.tsx`. This is the main consistency-critical boundary: operational completion, deposits, financing, commissions, and expenses should produce controlled, reversible/accountable financial events.

#### Marketplace, Communications, and External Integrations
The marketplace connects public buyers and dealer inventory/request workflows, with matching, listings, requests, responses, messaging, and push notifications implemented in Convex modules such as `convex/marketplaceListings.ts`, `convex/marketplaceRequests.ts`, and `convex/marketplaceMatching.ts`. Public marketplace routes live at `app/marketplace/cars/page.tsx`; dealer users work from org-scoped marketplace routes. Social/WhatsApp integrations and dealer-side integration work extend beyond the core app through `convex/whatsapp.ts`, `convex/socialInbox.ts`, and `dealer-worker/src/index.ts`.

#### Mobile and Platform Operations
The Expo companion app mirrors buyer marketplace and dealer workspace functions through file-based routes and feature screens. Entry/provider composition begins at `apps/mobile/app/_layout.tsx`; dealer tabs live at `apps/mobile/app/(app)/org/[orgId]/(tabs)/_layout.tsx`; Convex connectivity is configured in `apps/mobile/src/convexApi.ts`. Mobile includes native push, biometric locking, and EAS OTA/native update gates. Production infrastructure is Vercel (web), Convex (backend), Cloudflare Workers (edge), Expo/EAS (mobile), and Sentry (observability), with deployment workflows under `.github/workflows/`.

Main entry points: [`convex/sales.ts`](https://github.com/aalzriqat/auto/blob/main/convex/sales.ts) (Operational lifecycle), [`app/page.tsx`](https://github.com/aalzriqat/auto/blob/main/app/page.tsx) (Public web surfaces), [`convex/utils/tenancy.ts`](https://github.com/aalzriqat/auto/blob/main/convex/utils/tenancy.ts) (Tenancy and authorization), [`apps/mobile/app/_layout.tsx`](https://github.com/aalzriqat/auto/blob/main/apps/mobile/app/_layout.tsx) (Expo mobile app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web surfaces"]
  node_web_public["Public web surfaces<br/>Next.js routes<br/>[page.tsx]"]
  node_dealer_site["Dealer-hosted sites<br/>dynamic route<br/>[page.tsx]"]
  node_org_dashboard["Org workspace<br/>tenant route shell<br/>[layout.tsx]"]
  node_sales_wizard["Sales workflow<br/>staged UI<br/>[SalesWizard.tsx]"]
  node_accounting_workspace["Accounting workspace<br/>dashboard UI"]
  node_admin["Platform admin<br/>admin route shell<br/>[layout.tsx]"]
end

subgraph group_backend["Convex core"]
  node_convex_schema[("Shared data model<br/>Convex schema<br/>[schema.ts]")]
  node_tenancy_auth{{"Tenancy and authorization<br/>security boundary<br/>[tenancy.ts]"}}
  node_membership_roles["Memberships and roles<br/>identity domain<br/>[memberships.ts]"]
  node_operations["Operational lifecycle<br/>Convex domain functions<br/>[sales.ts]"]
  node_approvals["Approvals and audit gates<br/>Convex domain functions<br/>[approvals.ts]"]
  node_accounting_engine["Double-entry accounting<br/>posting engine<br/>[postingEngine.ts]"]
  node_marketplace["Marketplace workflows<br/>Convex domain functions"]
  node_communications["Social and WhatsApp<br/>integration functions<br/>[whatsapp.ts]"]
end

subgraph group_clients["Mobile and edge"]
  node_mobile_app["Expo mobile app<br/>mobile route shell<br/>[_layout.tsx]"]
  node_mobile_tenant_tabs["Mobile dealer workspace<br/>tenant tabs<br/>[_layout.tsx]"]
  node_edge_worker["Dealer edge worker<br/>Cloudflare Worker<br/>[index.ts]"]
end

subgraph group_platform["Platform services"]
  node_clerk(("Clerk identity<br/>authentication service"))
  node_deployment["Production delivery<br/>deployment workflows"]
  node_observability["Sentry<br/>observability service"]
end

node_web_public -->|"serves dealer sites"| node_dealer_site
node_org_dashboard -->|"hosts"| node_sales_wizard
node_org_dashboard -->|"hosts"| node_accounting_workspace
node_web_public -->|"browses and requests"| node_marketplace
node_org_dashboard -->|"uses generated APIs"| node_operations
node_sales_wizard -->|"creates and completes sales"| node_operations
node_accounting_workspace -->|"queries financial records"| node_accounting_engine
node_operations -->|"requests gated transitions"| node_approvals
node_approvals -->|"authorizes financial events"| node_accounting_engine
node_operations -->|"feeds workflow hooks"| node_accounting_engine
node_accounting_engine -->|"posts ledger data"| node_convex_schema
node_operations -->|"persists lifecycle data"| node_convex_schema
node_marketplace -->|"persists listings and requests"| node_convex_schema
node_tenancy_auth -->|"scopes access"| node_operations
node_tenancy_auth -->|"scopes dealer actions"| node_marketplace
node_membership_roles -->|"supplies permissions"| node_tenancy_auth
node_clerk -->|"provides identity"| node_tenancy_auth
node_mobile_app -->|"hosts"| node_mobile_tenant_tabs
node_mobile_tenant_tabs -->|"uses Convex APIs"| node_operations
node_mobile_app -->|"uses Convex APIs"| node_marketplace
node_communications -->|"supports messaging"| node_marketplace
node_edge_worker -->|"extends integrations"| node_communications
node_deployment -.->|"deploys to Vercel"| node_web_public
node_deployment -.->|"releases through Expo/EAS"| node_mobile_app
node_deployment -.->|"deploys to Cloudflare"| node_edge_worker
node_observability -.->|"monitors"| node_web_public
node_observability -.->|"monitors"| node_mobile_app

click node_web_public "https://github.com/aalzriqat/auto/blob/main/app/page.tsx"
click node_dealer_site "https://github.com/aalzriqat/auto/blob/main/app/dealer-site/%5B%5B...slug%5D%5D/page.tsx"
click node_org_dashboard "https://github.com/aalzriqat/auto/blob/main/app/(dashboard)/%5BorgId%5D/layout.tsx"
click node_sales_wizard "https://github.com/aalzriqat/auto/blob/main/components/sales/wizard/SalesWizard.tsx"
click node_accounting_workspace "https://github.com/aalzriqat/auto/blob/main/components/accounting/AccountingClient.tsx"
click node_admin "https://github.com/aalzriqat/auto/blob/main/app/admin/layout.tsx"
click node_convex_schema "https://github.com/aalzriqat/auto/blob/main/convex/schema.ts"
click node_tenancy_auth "https://github.com/aalzriqat/auto/blob/main/convex/utils/tenancy.ts"
click node_membership_roles "https://github.com/aalzriqat/auto/blob/main/convex/memberships.ts"
click node_operations "https://github.com/aalzriqat/auto/blob/main/convex/sales.ts"
click node_approvals "https://github.com/aalzriqat/auto/blob/main/convex/approvals.ts"
click node_accounting_engine "https://github.com/aalzriqat/auto/blob/main/convex/accounting/postingEngine.ts"
click node_communications "https://github.com/aalzriqat/auto/blob/main/convex/whatsapp.ts"
click node_mobile_app "https://github.com/aalzriqat/auto/blob/main/apps/mobile/app/_layout.tsx"
click node_mobile_tenant_tabs "https://github.com/aalzriqat/auto/blob/main/apps/mobile/app/(app)/org/%5BorgId%5D/(tabs)/_layout.tsx"
click node_edge_worker "https://github.com/aalzriqat/auto/blob/main/dealer-worker/src/index.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_web_public,node_dealer_site,node_org_dashboard,node_sales_wizard,node_accounting_workspace,node_admin toneBlue
class node_convex_schema,node_tenancy_auth,node_membership_roles,node_operations,node_approvals,node_accounting_engine,node_marketplace,node_communications toneAmber
class node_mobile_app,node_mobile_tenant_tabs,node_edge_worker toneMint
class node_clerk,node_deployment,node_observability toneRose
```

## Components

### Web surfaces

- [Public web surfaces](https://github.com/aalzriqat/auto/blob/main/app/page.tsx): Next.js routes · Marketing, marketplace, and dealer-hosted pages. · `app/page.tsx`
- [Dealer-hosted sites](https://github.com/aalzriqat/auto/blob/main/app/dealer-site/%5B%5B...slug%5D%5D/page.tsx): dynamic route · Renders dealer sites by slug and theme. · `app/dealer-site/[[...slug]]/page.tsx`
- [Org workspace](https://github.com/aalzriqat/auto/blob/main/app/(dashboard)/%5BorgId%5D/layout.tsx): tenant route shell · Route-level organization tenancy boundary. · `app/(dashboard)/[orgId]/layout.tsx`
- [Sales workflow](https://github.com/aalzriqat/auto/blob/main/components/sales/wizard/SalesWizard.tsx): staged UI · Captures quote, customer, vehicle, finance, review, and completion. · `components/sales/wizard/SalesWizard.tsx`
- [Accounting workspace](https://github.com/aalzriqat/auto/blob/main/components/accounting/AccountingClient.tsx): dashboard UI · `components/accounting/AccountingClient.tsx`
- [Platform admin](https://github.com/aalzriqat/auto/blob/main/app/admin/layout.tsx): admin route shell · `app/admin/layout.tsx`

### Convex core

- [Shared data model](https://github.com/aalzriqat/auto/blob/main/convex/schema.ts): Convex schema · Central reactive database schema. · `convex/schema.ts`
- [Tenancy and authorization](https://github.com/aalzriqat/auto/blob/main/convex/utils/tenancy.ts): security boundary · Enforces authenticated organization scope and permissions. · `convex/utils/tenancy.ts`
- [Memberships and roles](https://github.com/aalzriqat/auto/blob/main/convex/memberships.ts): identity domain · `convex/memberships.ts`
- [Operational lifecycle](https://github.com/aalzriqat/auto/blob/main/convex/sales.ts): Convex domain functions · Vehicles, leads, and sales own transaction lifecycle state. · `convex/sales.ts`
- [Approvals and audit gates](https://github.com/aalzriqat/auto/blob/main/convex/approvals.ts): Convex domain functions · Controls approval-aware state transitions. · `convex/approvals.ts`
- [Double-entry accounting](https://github.com/aalzriqat/auto/blob/main/convex/accounting/postingEngine.ts): posting engine · Turns controlled business events into ledger postings. · `convex/accounting/postingEngine.ts`
- **Marketplace workflows**: Convex domain functions · Listings, buyer requests, dealer responses, and matching.
- [Social and WhatsApp](https://github.com/aalzriqat/auto/blob/main/convex/whatsapp.ts): integration functions · `convex/whatsapp.ts`

### Mobile and edge

- [Expo mobile app](https://github.com/aalzriqat/auto/blob/main/apps/mobile/app/_layout.tsx): mobile route shell · Buyer marketplace and dealer workspace companion. · `apps/mobile/app/_layout.tsx`
- [Mobile dealer workspace](https://github.com/aalzriqat/auto/blob/main/apps/mobile/app/(app)/org/%5BorgId%5D/(tabs)/_layout.tsx): tenant tabs · `apps/mobile/app/(app)/org/[orgId]/(tabs)/_layout.tsx`
- [Dealer edge worker](https://github.com/aalzriqat/auto/blob/main/dealer-worker/src/index.ts): Cloudflare Worker · Extends dealer-side integration processing. · `dealer-worker/src/index.ts`

### Platform services

- **Clerk identity**: authentication service · Synchronizes authenticated users to Convex.
- **Production delivery**: deployment workflows · Deploys web, backend, edge, and mobile releases.
- **Sentry**: observability service

## Connections

- Public web surfaces → Dealer-hosted sites: serves dealer sites
- Org workspace → Sales workflow: hosts
- Org workspace → Accounting workspace: hosts
- Public web surfaces → Marketplace workflows: browses and requests
- Org workspace → Operational lifecycle: uses generated APIs
- Sales workflow → Operational lifecycle: creates and completes sales
- Accounting workspace → Double-entry accounting: queries financial records
- Operational lifecycle → Approvals and audit gates: requests gated transitions
- Approvals and audit gates → Double-entry accounting: authorizes financial events
- Operational lifecycle → Double-entry accounting: feeds workflow hooks
- Double-entry accounting → Shared data model: posts ledger data
- Operational lifecycle → Shared data model: persists lifecycle data
- Marketplace workflows → Shared data model: persists listings and requests
- Tenancy and authorization → Operational lifecycle: scopes access
- Tenancy and authorization → Marketplace workflows: scopes dealer actions
- Memberships and roles → Tenancy and authorization: supplies permissions
- Clerk identity → Tenancy and authorization: provides identity
- Expo mobile app → Mobile dealer workspace: hosts
- Mobile dealer workspace → Operational lifecycle: uses Convex APIs
- Expo mobile app → Marketplace workflows: uses Convex APIs
- Social and WhatsApp → Marketplace workflows: supports messaging
- Dealer edge worker → Social and WhatsApp: extends integrations
- Production delivery → Public web surfaces: deploys to Vercel
- Production delivery → Expo mobile app: releases through Expo/EAS
- Production delivery → Dealer edge worker: deploys to Cloudflare
- Sentry → Public web surfaces: monitors
- Sentry → Expo mobile app: monitors
