# roshaanmehar/stalls-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/roshaanmehar/stalls-tracker
- Repository: https://github.com/roshaanmehar/stalls-tracker

## Overview

#### Purpose and Runtime
This is a Next.js App Router application for managing a portfolio of stalls, their operating days, payments, lifecycle state, profit analytics, and audit history. It runs as a TypeScript React server/client application, with Supabase as the backend database/auth integration. Primary entry routes are `app/page.tsx`, `app/login/admin/page.tsx`, `app/login/operator/page.tsx`, `app/(admin)/admin/page.tsx`, and `app/(operator)/operator/page.tsx`.

#### Role-Based Application Boundaries
The route tree separates administrator and operator experiences through route groups and dedicated layouts. Administrators have management, analytics, audit, and settings surfaces; operators have a narrower stall/day workflow. Route and UI boundaries are established in:
- `app/(admin)/admin/layout.tsx`
- `app/(operator)/operator/layout.tsx`
- `middleware.ts`

Authentication entry points and session/token support sit at:
- `app/login/actions.ts`
- `components/auth/PasskeyLoginForm.tsx`
- `lib/auth/session.ts`

#### Stall and Day Management
Stalls are the central domain aggregate. Admin users create and manage stalls, navigate stall detail pages, and create or edit associated day records. The UI forms invoke colocated server actions, separating mutation handling from pages:
- `app/(admin)/admin/stalls/[stallId]/page.tsx`
- `app/(admin)/admin/stalls/[stallId]/days/[dayId]/edit/page.tsx`
- `app/(admin)/admin/_actions/stalls.ts`
- `app/(admin)/admin/_actions/days.ts`
- `components/admin/StallForm.tsx`
- `components/admin/StallDayForm.tsx`

Operators use parallel day-management routes and their own action boundary:
- `app/(operator)/operator/stalls/[stallId]/days/new/page.tsx`
- `app/(operator)/operator/_actions/days.ts`

#### Administrative Operations and Financial State
Admin-only server actions cover stall lifecycle transitions, operator settings, and split-related records. These represent the main control boundary for privileged mutations and map to dedicated admin components:
- `app/(admin)/admin/_actions/stall-lifecycle.ts`
- `app/(admin)/admin/_actions/splits.ts`
- `app/(admin)/admin/_actions/operator-settings.ts`
- `components/admin/StallLifecycleActions.tsx`
- `components/admin/SplitHistoryPanel.tsx`
- `components/admin/StallDaysPaidPanel.tsx`

#### Analytics Pipeline
Portfolio analytics are computed in domain logic and rendered in the admin analytics route. The calculation module is independently tested, making it the likely source of truth for period/profit aggregation rather than embedding calculations in presentation components:
- `lib/analytics/portfolio.ts`
- `app/(admin)/admin/analytics/page.tsx`
- `components/analytics/AnalyticsDashboard.tsx`
- `components/analytics/AnalyticsMonthlyProfitChart.tsx`

#### Persistence, Audit, and Schema
Supabase server access is centralized behind environment and server-client modules. Database concerns include audit records, operator settings, and split data, while migrations define the persistent domain schema and later payment/completion additions:
- `lib/supabase/server.ts`
- `lib/supabase/env.ts`
- `lib/db/audit.ts`
- `lib/db/operator-settings.ts`
- `supabase/migrations/20260401000000_initial.sql`
- `supabase/migrations/20260428180000_stalls_completion_and_day_paid.sql`

The admin audit screen is the read-side boundary for recorded operational history:
- `app/(admin)/admin/audit/page.tsx`

#### Shared Shell and Presentation
Role pages are rendered within common shell and visual infrastructure, while focused shared controls support data entry. Styling is global plus stall-specific, with reusable UI primitives underneath domain components:
- `components/shell/AppShell.tsx`
- `components/shared/QuickAddEntry.tsx`
- `app/layout.tsx`
- `app/globals.css`
- `app/stalls-theme.css`

Main entry points: [`lib/supabase/server.ts`](https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/supabase/server.ts) (Supabase server client), [`middleware.ts`](https://github.com/roshaanmehar/stalls-tracker/blob/main/middleware.ts) (Route guard), [`app/login/actions.ts`](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/login/actions.ts) (Login actions), [`app/(admin)/admin/_actions/stall-lifecycle.ts`](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/_actions/stall-lifecycle.ts) (Lifecycle, splits & settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access &amp; Shell"]
  node_root["Public entry<br/>Next.js route<br/>[page.tsx]"]
  node_login["Login actions<br/>auth server actions<br/>[actions.ts]"]
  node_passkey["Passkey login form<br/>React client UI"]
  node_session["Session support<br/>auth library<br/>[session.ts]"]
  node_middleware["Route guard<br/>Next.js middleware<br/>[middleware.ts]"]
end

subgraph group_admin["Admin Operations"]
  node_admin_layout["Admin layout<br/>route layout<br/>[layout.tsx]"]
  node_admin_stalls["Stall detail &amp; days<br/>admin route<br/>[page.tsx]"]
  node_stall_forms["Stall and day forms<br/>admin UI<br/>[StallForm.tsx]"]
  node_admin_mutations["Stall &amp; day actions<br/>server actions<br/>[stalls.ts]"]
  node_admin_controls["Lifecycle, splits &amp; settings<br/>privileged actions<br/>[stall-lifecycle.ts]"]
  node_audit["Audit screen<br/>admin route<br/>[page.tsx]"]
end

subgraph group_operator["Operator Workflow"]
  node_operator_layout["Operator layout<br/>route layout<br/>[layout.tsx]"]
  node_operator_days["Operator day entry<br/>operator route<br/>[page.tsx]"]
  node_operator_actions["Operator day actions<br/>server actions<br/>[days.ts]"]
end

subgraph group_analytics["Analytics"]
  node_analytics_route["Analytics route<br/>admin route<br/>[page.tsx]"]
  node_portfolio["Portfolio calculations<br/>domain analytics<br/>[portfolio.ts]"]
  node_analytics_ui["Analytics dashboard<br/>React UI"]
end

subgraph group_data["Data &amp; Persistence"]
  node_supabase[("Supabase server client<br/>database/auth gateway<br/>[server.ts]")]
  node_audit_store["Audit repository<br/>database access<br/>[audit.ts]"]
  node_schema[("Domain schema migrations<br/>SQL migrations")]
end

node_root -->|"starts authentication"| node_login
node_passkey -->|"submits credentials"| node_login
node_login -->|"creates session"| node_session
node_middleware -->|"validates access"| node_session
node_middleware -->|"admits admins"| node_admin_layout
node_middleware -->|"admits operators"| node_operator_layout
node_admin_layout -->|"hosts"| node_admin_stalls
node_admin_stalls -->|"renders"| node_stall_forms
node_stall_forms -->|"invokes"| node_admin_mutations
node_admin_mutations -->|"persists stalls and days"| node_supabase
node_admin_controls -->|"updates privileged state"| node_supabase
node_admin_controls -->|"records operations"| node_audit_store
node_audit -->|"reads history"| node_audit_store
node_operator_layout -->|"hosts"| node_operator_days
node_operator_days -->|"submits day data"| node_operator_actions
node_operator_actions -->|"persists days"| node_supabase
node_analytics_route -->|"computes portfolio metrics"| node_portfolio
node_analytics_route -->|"renders"| node_analytics_ui
node_portfolio -->|"reads portfolio data"| node_supabase
node_supabase -.->|"uses schema"| node_schema

click node_root "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/page.tsx"
click node_login "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/login/actions.ts"
click node_passkey "https://github.com/roshaanmehar/stalls-tracker/blob/main/components/auth/PasskeyLoginForm.tsx"
click node_session "https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/auth/session.ts"
click node_middleware "https://github.com/roshaanmehar/stalls-tracker/blob/main/middleware.ts"
click node_admin_layout "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/layout.tsx"
click node_admin_stalls "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/stalls/%5BstallId%5D/page.tsx"
click node_stall_forms "https://github.com/roshaanmehar/stalls-tracker/blob/main/components/admin/StallForm.tsx"
click node_admin_mutations "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/_actions/stalls.ts"
click node_admin_controls "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/_actions/stall-lifecycle.ts"
click node_audit "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/audit/page.tsx"
click node_operator_layout "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/layout.tsx"
click node_operator_days "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/stalls/%5BstallId%5D/days/new/page.tsx"
click node_operator_actions "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/_actions/days.ts"
click node_analytics_route "https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/analytics/page.tsx"
click node_portfolio "https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/analytics/portfolio.ts"
click node_analytics_ui "https://github.com/roshaanmehar/stalls-tracker/blob/main/components/analytics/AnalyticsDashboard.tsx"
click node_supabase "https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/supabase/server.ts"
click node_audit_store "https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/db/audit.ts"
click node_schema "https://github.com/roshaanmehar/stalls-tracker/blob/main/supabase/migrations/20260428180000_stalls_completion_and_day_paid.sql"

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,node_login,node_passkey,node_session,node_middleware toneBlue
class node_admin_layout,node_admin_stalls,node_stall_forms,node_admin_mutations,node_admin_controls,node_audit toneAmber
class node_operator_layout,node_operator_days,node_operator_actions toneMint
class node_analytics_route,node_portfolio,node_analytics_ui toneRose
class node_supabase,node_audit_store,node_schema toneIndigo
```

## Components

### Access & Shell

- [Public entry](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/page.tsx): Next.js route · `app/page.tsx`
- [Login actions](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/login/actions.ts): auth server actions · `app/login/actions.ts`
- [Passkey login form](https://github.com/roshaanmehar/stalls-tracker/blob/main/components/auth/PasskeyLoginForm.tsx): React client UI · `components/auth/PasskeyLoginForm.tsx`
- [Session support](https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/auth/session.ts): auth library · `lib/auth/session.ts`
- [Route guard](https://github.com/roshaanmehar/stalls-tracker/blob/main/middleware.ts): Next.js middleware · Protects role-specific route boundaries. · `middleware.ts`

### Admin Operations

- [Admin layout](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/layout.tsx): route layout · `app/(admin)/admin/layout.tsx`
- [Stall detail & days](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/stalls/%5BstallId%5D/page.tsx): admin route · Central management surface for stalls and associated operating days. · `app/(admin)/admin/stalls/[stallId]/page.tsx`
- [Stall and day forms](https://github.com/roshaanmehar/stalls-tracker/blob/main/components/admin/StallForm.tsx): admin UI · `components/admin/StallForm.tsx`
- [Stall & day actions](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/_actions/stalls.ts): server actions · `app/(admin)/admin/_actions/stalls.ts`
- [Lifecycle, splits & settings](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/_actions/stall-lifecycle.ts): privileged actions · Admin-only financial and lifecycle mutation boundary. · `app/(admin)/admin/_actions/stall-lifecycle.ts`
- [Audit screen](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/audit/page.tsx): admin route · `app/(admin)/admin/audit/page.tsx`

### Operator Workflow

- [Operator layout](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/layout.tsx): route layout · `app/(operator)/operator/layout.tsx`
- [Operator day entry](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/stalls/%5BstallId%5D/days/new/page.tsx): operator route · `app/(operator)/operator/stalls/[stallId]/days/new/page.tsx`
- [Operator day actions](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(operator)/operator/_actions/days.ts): server actions · `app/(operator)/operator/_actions/days.ts`

### Analytics

- [Analytics route](https://github.com/roshaanmehar/stalls-tracker/blob/main/app/(admin)/admin/analytics/page.tsx): admin route · `app/(admin)/admin/analytics/page.tsx`
- [Portfolio calculations](https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/analytics/portfolio.ts): domain analytics · Source of truth for period and profit aggregation. · `lib/analytics/portfolio.ts`
- [Analytics dashboard](https://github.com/roshaanmehar/stalls-tracker/blob/main/components/analytics/AnalyticsDashboard.tsx): React UI · `components/analytics/AnalyticsDashboard.tsx`

### Data & Persistence

- [Supabase server client](https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/supabase/server.ts): database/auth gateway · `lib/supabase/server.ts`
- [Audit repository](https://github.com/roshaanmehar/stalls-tracker/blob/main/lib/db/audit.ts): database access · `lib/db/audit.ts`
- [Domain schema migrations](https://github.com/roshaanmehar/stalls-tracker/blob/main/supabase/migrations/20260428180000_stalls_completion_and_day_paid.sql): SQL migrations · Defines stalls, days, payments, completion, and related records. · `supabase/migrations/20260428180000_stalls_completion_and_day_paid.sql`

## Connections

- Public entry → Login actions: starts authentication
- Passkey login form → Login actions: submits credentials
- Login actions → Session support: creates session
- Route guard → Session support: validates access
- Route guard → Admin layout: admits admins
- Route guard → Operator layout: admits operators
- Admin layout → Stall detail & days: hosts
- Stall detail & days → Stall and day forms: renders
- Stall and day forms → Stall & day actions: invokes
- Stall & day actions → Supabase server client: persists stalls and days
- Lifecycle, splits & settings → Supabase server client: updates privileged state
- Lifecycle, splits & settings → Audit repository: records operations
- Audit screen → Audit repository: reads history
- Operator layout → Operator day entry: hosts
- Operator day entry → Operator day actions: submits day data
- Operator day actions → Supabase server client: persists days
- Analytics route → Portfolio calculations: computes portfolio metrics
- Analytics route → Analytics dashboard: renders
- Portfolio calculations → Supabase server client: reads portfolio data
- Supabase server client → Domain schema migrations: uses schema
