# zigsawsam/pyro architecture

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

- Interactive diagram: https://gitdiagram.com/zigsawsam/pyro
- Repository: https://github.com/zigsawsam/pyro

## Overview

#### 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: [`app/shop/[shopId]/page.tsx`](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/page.tsx) (Shop tenant boundary), [`lib/supabase/client.ts`](https://github.com/zigsawsam/pyro/blob/main/lib/supabase/client.ts) (Supabase data access), [`app/shop/[shopId]/salary/salary-client.tsx`](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/salary/salary-client.tsx) (Salary management), [`app/agent/dashboard/dashboard-client.tsx`](https://github.com/zigsawsam/pyro/blob/main/app/agent/dashboard/dashboard-client.tsx) (Agent dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Role-specific UI"]
  node_root_layout["Root application shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_public_auth["Public and login entry<br/>route pages<br/>[page.tsx]"]
  node_shop_shell["Shop owner navigation<br/>header layout<br/>[ShopHeader.tsx]"]
  node_agent_shell["Agent navigation<br/>sidebar layout<br/>[AgentSidebar.tsx]"]
  node_reports["Role reports<br/>reporting UI<br/>[reports-client.tsx]"]
  node_csv_export["CSV export<br/>data export"]
end

subgraph group_shop["Shop tenant operations"]
  node_shop_route["Shop tenant boundary<br/>dynamic route<br/>[page.tsx]"]
  node_shop_dashboard["Shop dashboard<br/>dashboard UI"]
  node_sales["Sales operations<br/>interactive workflow<br/>[sales-client.tsx]"]
  node_shop_agents["Agent relationships<br/>interactive workflow<br/>[agents-client.tsx]"]
  node_agent_payout["Agent payout action<br/>payment dialog"]
  node_staff["Staff management<br/>interactive workflow<br/>[staff-client.tsx]"]
  node_attendance["Attendance tracking<br/>interactive workflow"]
  node_salary["Salary management<br/>interactive workflow<br/>[salary-client.tsx]"]
  node_payroll_payment["Payroll payment action<br/>payment dialog"]
end

subgraph group_agent["Agent earnings"]
  node_agent_dashboard["Agent dashboard<br/>interactive workflow"]
  node_commissions["Commission earnings<br/>route page<br/>[page.tsx]"]
  node_agent_shops["Linked shops<br/>interactive workflow<br/>[shops-client.tsx]"]
end

subgraph group_platform["Auth and data platform"]
  node_auth_guard{{"Authentication guards<br/>auth module<br/>[auth-guard.ts]"}}
  node_supabase_clients[("Supabase data access<br/>client/server clients<br/>[client.ts]")]
  node_supabase_middleware["Session middleware<br/>request middleware<br/>[middleware.ts]"]
end

node_root_layout -->|"renders"| node_public_auth
node_root_layout -->|"hosts"| node_shop_route
node_root_layout -->|"hosts"| node_agent_dashboard
node_shop_route -->|"uses navigation"| node_shop_shell
node_shop_route -->|"loads"| node_shop_dashboard
node_shop_route -->|"scopes"| node_sales
node_shop_route -->|"scopes"| node_shop_agents
node_shop_route -->|"scopes"| node_staff
node_shop_route -->|"scopes"| node_attendance
node_shop_route -->|"scopes"| node_salary
node_shop_route -->|"scopes"| node_reports
node_sales -->|"creates commission basis"| node_commissions
node_shop_agents -->|"initiates"| node_agent_payout
node_agent_payout -->|"updates payout history"| node_commissions
node_attendance -->|"feeds"| node_salary
node_salary -->|"initiates"| node_payroll_payment
node_agent_shell -->|"navigates"| node_agent_dashboard
node_agent_dashboard -->|"links to"| node_commissions
node_agent_dashboard -->|"links to"| node_agent_shops
node_reports -->|"exports"| node_csv_export
node_public_auth -->|"authenticates through"| node_auth_guard
node_auth_guard -->|"uses session"| node_supabase_middleware
node_supabase_middleware -->|"refreshes access for"| node_supabase_clients
node_sales -->|"reads and writes"| node_supabase_clients
node_salary -->|"reads and writes"| node_supabase_clients
node_commissions -->|"reads"| node_supabase_clients
node_reports -->|"aggregates data from"| node_supabase_clients

click node_root_layout "https://github.com/zigsawsam/pyro/blob/main/app/layout.tsx"
click node_public_auth "https://github.com/zigsawsam/pyro/blob/main/app/page.tsx"
click node_shop_shell "https://github.com/zigsawsam/pyro/blob/main/components/layout/ShopHeader.tsx"
click node_agent_shell "https://github.com/zigsawsam/pyro/blob/main/components/layout/AgentSidebar.tsx"
click node_shop_route "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/page.tsx"
click node_shop_dashboard "https://github.com/zigsawsam/pyro/blob/main/components/dashboard/shop/ShopDashboardPage.tsx"
click node_sales "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/sales/sales-client.tsx"
click node_shop_agents "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/agents/agents-client.tsx"
click node_agent_payout "https://github.com/zigsawsam/pyro/blob/main/components/agents/pay-agent-dialog.tsx"
click node_staff "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/staff/staff-client.tsx"
click node_attendance "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/attendance/attendance-client.tsx"
click node_salary "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/salary/salary-client.tsx"
click node_payroll_payment "https://github.com/zigsawsam/pyro/blob/main/components/payroll/payroll-payment-dialog.tsx"
click node_agent_dashboard "https://github.com/zigsawsam/pyro/blob/main/app/agent/dashboard/dashboard-client.tsx"
click node_commissions "https://github.com/zigsawsam/pyro/blob/main/app/agent/earnings/commissions/page.tsx"
click node_agent_shops "https://github.com/zigsawsam/pyro/blob/main/app/agent/shops/shops-client.tsx"
click node_reports "https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/reports/reports-client.tsx"
click node_csv_export "https://github.com/zigsawsam/pyro/blob/main/components/reports/csv-export-button.tsx"
click node_auth_guard "https://github.com/zigsawsam/pyro/blob/main/lib/auth-guard.ts"
click node_supabase_clients "https://github.com/zigsawsam/pyro/blob/main/lib/supabase/client.ts"
click node_supabase_middleware "https://github.com/zigsawsam/pyro/blob/main/lib/supabase/middleware.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_root_layout,node_public_auth,node_shop_shell,node_agent_shell,node_reports,node_csv_export toneBlue
class node_shop_route,node_shop_dashboard,node_sales,node_shop_agents,node_agent_payout,node_staff,node_attendance,node_salary,node_payroll_payment toneAmber
class node_agent_dashboard,node_commissions,node_agent_shops toneMint
class node_auth_guard,node_supabase_clients,node_supabase_middleware toneRose
```

## Components

### Role-specific UI

Separate shop-owner and agent application surfaces.

- [Root application shell](https://github.com/zigsawsam/pyro/blob/main/app/layout.tsx): Next.js layout · Provides shared styling and application-level composition. · `app/layout.tsx`
- [Public and login entry](https://github.com/zigsawsam/pyro/blob/main/app/page.tsx): route pages · Home and role-specific login entry points. · `app/page.tsx`
- [Shop owner navigation](https://github.com/zigsawsam/pyro/blob/main/components/layout/ShopHeader.tsx): header layout · Owner-facing navigation surface. · `components/layout/ShopHeader.tsx`
- [Agent navigation](https://github.com/zigsawsam/pyro/blob/main/components/layout/AgentSidebar.tsx): sidebar layout · Agent-facing navigation surface. · `components/layout/AgentSidebar.tsx`
- [Role reports](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/reports/reports-client.tsx): reporting UI · Shop and agent reports aggregate operational activity. · `app/shop/[shopId]/reports/reports-client.tsx`
- [CSV export](https://github.com/zigsawsam/pyro/blob/main/components/reports/csv-export-button.tsx): data 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](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/page.tsx): dynamic route · Selected shop ID scopes owner operations. · `app/shop/[shopId]/page.tsx`
- [Shop dashboard](https://github.com/zigsawsam/pyro/blob/main/components/dashboard/shop/ShopDashboardPage.tsx): dashboard UI · Presents tenant operational analytics. · `components/dashboard/shop/ShopDashboardPage.tsx`
- [Sales operations](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/sales/sales-client.tsx): interactive workflow · Records shop sales that drive commissions. · `app/shop/[shopId]/sales/sales-client.tsx`
- [Agent relationships](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/agents/agents-client.tsx): interactive workflow · Manages shop-agent links and profiles. · `app/shop/[shopId]/agents/agents-client.tsx`
- [Agent payout action](https://github.com/zigsawsam/pyro/blob/main/components/agents/pay-agent-dialog.tsx): payment dialog · Executes commission-driven agent payments. · `components/agents/pay-agent-dialog.tsx`
- [Staff management](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/staff/staff-client.tsx): interactive workflow · Maintains staff profiles separately from agents. · `app/shop/[shopId]/staff/staff-client.tsx`
- [Attendance tracking](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/attendance/attendance-client.tsx): interactive workflow · Captures staff attendance for payroll. · `app/shop/[shopId]/attendance/attendance-client.tsx`
- [Salary management](https://github.com/zigsawsam/pyro/blob/main/app/shop/[shopId]/salary/salary-client.tsx): interactive workflow · Generates and manages staff salary records. · `app/shop/[shopId]/salary/salary-client.tsx`
- [Payroll payment action](https://github.com/zigsawsam/pyro/blob/main/components/payroll/payroll-payment-dialog.tsx): payment dialog · Executes attendance- and salary-driven staff payments. · `components/payroll/payroll-payment-dialog.tsx`

### Agent earnings

Cross-shop commission and payout views.

- [Agent dashboard](https://github.com/zigsawsam/pyro/blob/main/app/agent/dashboard/dashboard-client.tsx): interactive workflow · Shows agent performance across relationships. · `app/agent/dashboard/dashboard-client.tsx`
- [Commission earnings](https://github.com/zigsawsam/pyro/blob/main/app/agent/earnings/commissions/page.tsx): route page · Presents commission history and earnings. · `app/agent/earnings/commissions/page.tsx`
- [Linked shops](https://github.com/zigsawsam/pyro/blob/main/app/agent/shops/shops-client.tsx): interactive workflow · 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](https://github.com/zigsawsam/pyro/blob/main/lib/auth-guard.ts): auth module · Enforces authenticated role and route access. · `lib/auth-guard.ts`
- [Supabase data access](https://github.com/zigsawsam/pyro/blob/main/lib/supabase/client.ts): client/server clients · Browser and server integration boundary for application data. · `lib/supabase/client.ts`
- [Session middleware](https://github.com/zigsawsam/pyro/blob/main/lib/supabase/middleware.ts): request middleware · Participates in session handling during requests. · `lib/supabase/middleware.ts`

## Connections

- 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
