How zigsawsam/pyro works
Purpose and Entry Points
A Next.js App Router application for retail-shop operations: commission agents, sales, payouts, staff payroll, attendance, and reporting. It has role-specific journeys:
• Public/auth entry pages: app/page.tsx, app/auth/shop-login/page.tsx, app/auth/agent-login/page.tsx
• Shop-owner tenant workspace under a dynamic shop boundary: app/shop/[shopId]/page.tsx
• Agent workspace and cross-shop earnings views: app/agent/page.tsx, app/agent/earnings/page.tsx
Application Shell and Role Boundaries
The root layout provides shared application styling and likely providers. Shop and agent experiences use separate headers, sidebars, and page structures, establishing a UI-level role boundary rather than one shared dashboard.
• app/layout.tsx
• components/layout/ShopHeader.tsx
• components/layout/AgentSidebar.tsx
Shop-Tenant Operations
[shopId] is the primary tenancy/routing boundary. All owner workflows are scoped to the selected shop: dashboard, agent links, sales, payouts, inventory, staff, attendance, salary, and reports. Page files act as route entry points; paired *-client.tsx files host interactive browser behavior.
• app/shop/[shopId]/dashboard/page.tsx
• app/shop/[shopId]/sales/sales-client.tsx
• app/shop/[shopId]/salary/salary-client.tsx
Core flow: an owner enters a shop-scoped route, loads tenant-specific operational data, then records sales or manages personnel/payment state. Sales feed agent commissions; attendance and staff records feed salary generation; reports aggregate shop activity.
Agent Commission and Earnings Flow
Agents have a distinct navigation surface focused on dashboard performance, linked shops, commissions, payouts, and statements. This implies an agent can operate across shop relationships while shop owners administer each relationship within a tenant.
• app/agent/dashboard/dashboard-client.tsx
• app/agent/earnings/commissions/page.tsx
• app/agent/shops/shops-client.tsx
Shop-side agent management includes linking, profiles, and payment actions. Agent-side earnings then presents commission and payout history.
• app/shop/[shopId]/agents/agents-client.tsx
• components/agents/pay-agent-dialog.tsx
Payroll, Staff, and Attendance
Staff management is separate from agent commissions. Owners maintain staff profiles, mark attendance, generate/manage salary records, and execute payroll payments.
• app/shop/[shopId]/staff/staff-client.tsx
• app/shop/[shopId]/attendance/attendance-client.tsx
• components/payroll/payroll-payment-dialog.tsx
This separation is architecturally important: agent payouts are commission-driven, while staff payments are attendance/salary-driven.
Data Access, Authentication, and Runtime
Despite the README describing local SQLite and API routes, the supplied tree contains no app/api, lib/db.ts, or scripts. The implemented integration surface instead centers on Supabase clients and middleware, with authentication guards and shared domain types.
• lib/supabase/client.ts
• lib/supabase/server-client.ts
• lib/supabase/middleware.ts
• lib/auth.ts
• lib/auth-guard.ts
• lib/types.ts
The runtime is Next.js/React/TypeScript. Supabase is the material external backend boundary indicated by the repository; proxy.ts likely participates in request/session routing behavior.
Reporting and Presentation Layer
Both roles expose reporting/dashboard analytics assembled from reusable domain components, charts, tables, dialogs, and a shared shadcn-style UI layer. CSV export is a dedicated outward data boundary.
• app/shop/[shopId]/reports/reports-client.tsx
• app/agent/reports/reports-client.tsx
• components/dashboard/shop/ShopDashboardPage.tsx
• components/reports/csv-export-button.tsx
Main entry points: page.tsx Shop tenant boundary · client.ts Supabase data access · salary-client.tsx Salary management · dashboard-client.tsx Agent dashboard
Components 21
Role-specific UI
Separate shop-owner and agent application surfaces.
- Root application shell · Provides shared styling and application-level composition.
app/layout.tsx - Public and login entry · Home and role-specific login entry points.
app/page.tsx - Shop owner navigation · Owner-facing navigation surface.
components/layout/ShopHeader.tsx - Agent navigation · Agent-facing navigation surface.
components/layout/AgentSidebar.tsx - Role reports · Shop and agent reports aggregate operational activity.
app/shop/[shopId]/reports/reports-client.tsx - CSV export · Exports report data outward as CSV.
components/reports/csv-export-button.tsx
Shop tenant operations
Owner workflows are scoped by the dynamic shop route.
- Shop tenant boundary · Selected shop ID scopes owner operations.
app/shop/[shopId]/page.tsx - Shop dashboard · Presents tenant operational analytics.
components/dashboard/shop/ShopDashboardPage.tsx - Sales operations · Records shop sales that drive commissions.
app/shop/[shopId]/sales/sales-client.tsx - Agent relationships · Manages shop-agent links and profiles.
app/shop/[shopId]/agents/agents-client.tsx - Agent payout action · Executes commission-driven agent payments.
components/agents/pay-agent-dialog.tsx - Staff management · Maintains staff profiles separately from agents.
app/shop/[shopId]/staff/staff-client.tsx - Attendance tracking · Captures staff attendance for payroll.
app/shop/[shopId]/attendance/attendance-client.tsx - Salary management · Generates and manages staff salary records.
app/shop/[shopId]/salary/salary-client.tsx - Payroll payment action · Executes attendance- and salary-driven staff payments.
components/payroll/payroll-payment-dialog.tsx
Agent earnings
Cross-shop commission and payout views.
- Agent dashboard · Shows agent performance across relationships.
app/agent/dashboard/dashboard-client.tsx - Commission earnings · Presents commission history and earnings.
app/agent/earnings/commissions/page.tsx - Linked shops · Lists the agent's shop relationships.
app/agent/shops/shops-client.tsx
Auth and data platform
Next.js request guards and Supabase integration.
- Authentication guards · Enforces authenticated role and route access.
lib/auth-guard.ts - Supabase data access · Browser and server integration boundary for application data.
lib/supabase/client.ts - Session middleware · Participates in session handling during requests.
lib/supabase/middleware.ts
Connections 27
- Root application shell → Public and login entry: renders
- Root application shell → Shop tenant boundary: hosts
- Root application shell → Agent dashboard: hosts
- Shop tenant boundary → Shop owner navigation: uses navigation
- Shop tenant boundary → Shop dashboard: loads
- Shop tenant boundary → Sales operations: scopes
- Shop tenant boundary → Agent relationships: scopes
- Shop tenant boundary → Staff management: scopes
- Shop tenant boundary → Attendance tracking: scopes
- Shop tenant boundary → Salary management: scopes
- Shop tenant boundary → Role reports: scopes
- Sales operations → Commission earnings: creates commission basis
- Agent relationships → Agent payout action: initiates
- Agent payout action → Commission earnings: updates payout history
- Attendance tracking → Salary management: feeds
- Salary management → Payroll payment action: initiates
- Agent navigation → Agent dashboard: navigates
- Agent dashboard → Commission earnings: links to
- Agent dashboard → Linked shops: links to
- Role reports → CSV export: exports
- Public and login entry → Authentication guards: authenticates through
- Authentication guards → Session middleware: uses session
- Session middleware → Supabase data access: refreshes access for
- Sales operations → Supabase data access: reads and writes
- Salary management → Supabase data access: reads and writes
- Commission earnings → Supabase data access: reads
- Role reports → Supabase data access: aggregates data from