How juvialski/invoiceapp works
Purpose and Entry Points
ENGORYX is a multi-tenant AEC operations platform spanning project cost control, invoices, cash settlement, payroll, engineering records, and field workflows. The browser client starts at src/main.tsx, composes providers/shell in src/app/AppProviders.tsx and src/app/AppShell.tsx, and resolves product areas through src/app/routes/AppRouter.tsx. server.ts hosts server-side AI/assistant capabilities.
Application Shell, Routing, and Modes
Route components separate major workspaces—dashboard, projects, invoices, expenses, payroll, cash/banking, reports, settings, and platform company administration. Navigation is modeled independently, allowing consistent route/menu/tour behavior. A demo runtime is a parallel, seeded experience rather than the production persistence path.
• src/app/routes/AppRouter.tsx
• src/navigation/navigationModel.ts
• src/demo/DemoRoot.tsx
Company Tenancy, Access, and Persistence Boundary
The frontend accesses Supabase through a shared client and domain persistence modules. Company context/access state gates UI behavior, while PostgreSQL migrations establish company tenancy, RBAC/RLS, storage policy, and RPC contracts. Database policy—not client checks alone—is the authority for isolation and privileged actions.
• src/lib/supabase.ts
• src/context/CompanyAccessContext.tsx
• supabase/migrations/20260824093000_company_tenancy_rls_and_admin_rpcs.sql
Operational Financial Domains
Invoices, project costs, expenses, payroll, and banking are separate source domains connected through controlled allocations and settlement evidence. Cash/banking imports and reconciles transactions; settlement can evidence invoice, payroll, and eligible expense payment without creating or rewriting project cost/payroll history. Domain libraries encapsulate calculations, workflows, and persistence behind UI workspaces.
• src/lib/cashBanking.ts
• src/lib/financialSettlement.ts
• src/lib/payrollWorkflow.ts
Project and Engineering Record Lifecycle
Project workspaces aggregate budgets, invoice allocations, labor, direct expenses, reports, documents, coordination, and site logs. Engineering documents support revision lineage, annotations, and storage controls; RFIs/submittals and daily logs are project-scoped lifecycle records with controller/access layers separating screen behavior from persistence rules.
• src/components/projects/ProjectWorkspace.tsx
• src/features/engineering/useEngineeringDocumentsController.ts
• src/features/engineering/useDailySiteLogsController.ts
Workspace Synchronization and Realtime Control Flow
Typical flow is route/UI → domain library/controller → Supabase tables/RPCs; cached workspace loading and synchronization manage refresh, sequencing, conflict handling, and realtime updates. The database includes realtime-oriented migrations for workspace, payroll, and banking changes, making server state the shared source of truth.
• src/lib/workspaceSync.ts
• src/lib/workspaceLoadCache.ts
• supabase/migrations/20260823180000_workspace_sync_realtime.sql
Guarded AI Assistant
The client assistant panel sends contextual requests and attachments to server handlers. Server code resolves company-scoped AI credentials, runs Gemini-compatible model/tool loops, validates and authorizes tools, and returns prepared actions. UI policy and confirmation gates require explicit human confirmation before writes; encrypted per-company credentials and optional global fallback are controlled by environment variables.
• src/assistant/AssistantProvider.tsx
• src/server/assistant/assistantHandler.ts
• src/server/ai/companyAiRuntime.ts
Runtime and Infrastructure
The stack is TypeScript/React with Vite for the client, Node-based server execution, and Supabase (PostgreSQL, RLS, RPCs, storage, realtime) as backend infrastructure. Gemini is the external AI integration. Engineering drawing functionality is represented in the UI layer and documented as PDF.js/Konva-based; database migrations are versioned under supabase/migrations.
• vite.config.ts
• server.ts
• supabase/config.toml
Main entry points: workspaceSync.ts Workspace sync · AppRouter.tsx Product router · ProjectWorkspace.tsx Project workspace · financialSettlement.ts Financial workflows
Components 23
Browser application
- Client entry
src/main.tsx - App providers
src/app/AppProviders.tsx - Application shell
src/app/AppShell.tsx - Product router · Selects dashboard, projects, financial, reporting, settings, and administration workspaces.
src/app/routes/AppRouter.tsx - Navigation model · Keeps menus and guided-tour behavior independent from routes.
src/navigation/navigationModel.ts - Demo runtime · Runs a seeded experience outside production persistence.
src/demo/DemoRoot.tsx - Company access context
src/context/CompanyAccessContext.tsx
Operational domains
- Project workspace · Aggregates budgets, allocations, labor, expenses, reports, documents, coordination, and site logs.
src/components/projects/ProjectWorkspace.tsx - Engineering documents · Manages revision lineage, annotations, and controlled storage access.
src/features/engineering/useEngineeringDocumentsController.ts - Daily site logs
src/features/engineering/useDailySiteLogsController.ts - Financial workflows · Invoices, costs, expenses, payroll, and banking remain separate source domains.
src/lib/financialSettlement.ts - Cash and banking · Imports and reconciles transactions for settlement evidence.
src/lib/cashBanking.ts - Payroll workflow
src/lib/payrollWorkflow.ts
Supabase backend
- Workspace sync · Handles loading, refresh sequencing, conflicts, and realtime updates.
src/lib/workspaceSync.ts - Workspace load cache
src/lib/workspaceLoadCache.ts - Supabase client
src/lib/supabase.ts - PostgreSQL, RLS and RPCs · Database policy is the authority for tenant isolation and privileged actions.
supabase/migrations/20260824093000_company_tenancy_rls_and_admin_rpcs.sql - Workspace realtime schema
supabase/migrations/20260823180000_workspace_sync_realtime.sql
Guarded AI assistant
- Assistant provider · Requires human confirmation before write actions.
src/assistant/AssistantProvider.tsx - Node server
server.ts - Assistant handler
src/server/assistant/assistantHandler.ts - Company AI runtime · Resolves company credentials and validates authorized tool loops.
src/server/ai/companyAiRuntime.ts - Gemini-compatible models
Connections 26
- Client entry → App providers
- App providers → Application shell
- Application shell → Product router
- Application shell → Navigation model: menu and tour behavior
- App providers → Company access context: tenant-aware UI
- Product router → Demo runtime: parallel demo mode
- Product router → Project workspace: project routes
- Product router → Financial workflows: financial routes
- Project workspace → Engineering documents: project records
- Project workspace → Daily site logs: project records
- Project workspace → Workspace sync: load and synchronize
- Financial workflows → Cash and banking: settlement evidence
- Financial workflows → Payroll workflow: payroll settlement
- Financial workflows → Workspace sync: persist workflows
- Workspace sync → Workspace load cache: cached loading
- Workspace sync → Supabase client: tables and RPCs
- Supabase client → PostgreSQL, RLS and RPCs: tenant-scoped persistence
- Workspace realtime schema → PostgreSQL, RLS and RPCs: realtime changes
- PostgreSQL, RLS and RPCs → Workspace sync: shared state updates
- Company access context → PostgreSQL, RLS and RPCs: RLS-enforced access
- Assistant provider → Node server: context and attachments
- Node server → Assistant handler: assistant requests
- Assistant handler → Company AI runtime: authorized tool loop
- Company AI runtime → Gemini-compatible models: model calls
- Company AI runtime → Supabase client: company-scoped actions
- Assistant handler → Assistant provider: prepared actions