How aalzriqat/auto works
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: sales.ts Operational lifecycle · page.tsx Public web surfaces · tenancy.ts Tenancy and authorization · _layout.tsx Expo mobile app
Components 20
Web surfaces
- Public web surfaces · Marketing, marketplace, and dealer-hosted pages.
app/page.tsx - Dealer-hosted sites · Renders dealer sites by slug and theme.
app/dealer-site/[[...slug]]/page.tsx - Org workspace · Route-level organization tenancy boundary.
app/(dashboard)/[orgId]/layout.tsx - Sales workflow · Captures quote, customer, vehicle, finance, review, and completion.
components/sales/wizard/SalesWizard.tsx - Accounting workspace
components/accounting/AccountingClient.tsx - Platform admin
app/admin/layout.tsx
Convex core
- Shared data model · Central reactive database schema.
convex/schema.ts - Tenancy and authorization · Enforces authenticated organization scope and permissions.
convex/utils/tenancy.ts - Memberships and roles
convex/memberships.ts - Operational lifecycle · Vehicles, leads, and sales own transaction lifecycle state.
convex/sales.ts - Approvals and audit gates · Controls approval-aware state transitions.
convex/approvals.ts - Double-entry accounting · Turns controlled business events into ledger postings.
convex/accounting/postingEngine.ts - Marketplace workflows · Listings, buyer requests, dealer responses, and matching.
- Social and WhatsApp
convex/whatsapp.ts
Mobile and edge
- Expo mobile app · Buyer marketplace and dealer workspace companion.
apps/mobile/app/_layout.tsx - Mobile dealer workspace
apps/mobile/app/(app)/org/[orgId]/(tabs)/_layout.tsx - Dealer edge worker · Extends dealer-side integration processing.
dealer-worker/src/index.ts
Platform services
- Clerk identity · Synchronizes authenticated users to Convex.
- Production delivery · Deploys web, backend, edge, and mobile releases.
- Sentry
Connections 27
- 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