# avee1000/pr architecture

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

- Interactive diagram: https://gitdiagram.com/avee1000/pr
- Repository: https://github.com/avee1000/pr

## Overview

#### 1. Purpose and Runtime
PriceRight & QuoteEasy is a Next.js 16 / React 19 TypeScript application for sole traders to calculate prices from costs and profit targets, issue quotes, manage orders through delivery, and view cash flow. It runs on Node.js 20+ and deploys to Vercel. Core persistence and identity are Supabase PostgreSQL and Supabase Auth.

Entry shell and global styling: `src/app/layout.tsx`, `src/app/page.tsx`, `src/app/globals.css`.

#### 2. Route Partitioning and Access Control
The App Router separates public marketing, authentication, authenticated operations, and public quote viewing. The dashboard route group has its own layout and is guarded by the proxy layer; quote links intentionally remain accessible without a session.

Key boundaries:
- Auth pages: `src/app/(auth)/login/page.tsx`, `src/app/(auth)/signup/page.tsx`
- Protected dashboard: `src/app/(dashboard)/layout.tsx`, `src/app/(dashboard)/dashboard/page.tsx`
- Public capability-link quote page: `src/app/quote/[token]/page.tsx`
- Session/access proxy: `src/proxy.ts`

#### 3. Supabase Data and Server Boundary
Supabase clients distinguish browser and server use, while feature server actions encapsulate mutations and revalidation-oriented application logic. PostgreSQL owns customer, order, quote, material, labor, profit-target, and testimonial records. Database RLS is a material security boundary, although cost catalogs are currently globally shared rather than user-scoped.

Paths: `src/lib/supabase/client.ts`, `src/lib/supabase/server.ts`, `src/lib/supabase/types.ts`; schema/RPC artifacts: `supabase/orders_quotes_rls.sql`, `supabase/quote_rpc.sql`.

#### 4. Cost-to-Price Configuration
Users maintain reusable material costs, labor costs, and target-profit settings. These inputs feed order/quote pricing rather than being a separate accounting service. Feature forms invoke cost actions against Supabase.

Paths: `src/app/(dashboard)/dashboard/costs/materials/page.tsx`, `src/components/dashboard/costs/materials/MaterialCostsForm.tsx`, `src/lib/costs/action.ts`.

#### 5. Customer and Order Lifecycle
Customers are created and edited before/during order creation. Orders bind a customer, description, price, due date, fulfillment status, and payment status; material line items support pricing composition. The workflow stages are quote sent, approved, in progress, and delivered. The board provides visual stage transitions, with a selector fallback.

Paths: `src/app/(dashboard)/dashboard/orders/create/page.tsx`, `src/components/dashboard/orders/create/OrderForm.tsx`, `src/components/dashboard/orders/board/OrderBoard.tsx`; actions: `src/lib/orders/action.ts`.

#### 6. Quotes and External Approval
A quote can be shared through a tokenized public URL. The external recipient views quote information and approves it without authentication. Approval crosses a deliberate public-to-database boundary: the route handler passes the token to the `approve_quote_by_token` database function, rather than accepting a caller-supplied order identity.

Paths: `src/app/quote/[token]/page.tsx`, `src/components/orders/QuoteView.tsx`, `src/app/api/quotes/[token]/approve/route.ts`.

#### 7. APIs, Cash Flow, and Notifications
Most reads/writes use Server Components and server actions. REST handlers exist where client invocation or public quote approval requires HTTP. `POST /api/orders` derives `user_id` from the authenticated Supabase session and stamps `paid_at` for paid orders. Cash flow aggregates paid orders by payment timestamp; notification UI/API supports workflow alerts.

Paths: `src/app/api/orders/route.ts`, `src/lib/dashboard/cashflow.ts`, `src/app/api/notifications/route.ts`.

#### 8. Operational Constraints
Hosting is Vercel with environment-provided public Supabase URL and anon key. Production deploys from `master`; PRs receive previews. Database evolution is currently manual and therefore prone to schema drift; only partial SQL artifacts are repository-managed. Key security debt: shared unscoped cost tables and broad testimonial write permissions.

Paths: `.env.example`, `supabase/testimonials.sql`, `sql/2026-07-31-costs-registration.sql`.

Main entry points: [`src/app/(dashboard)/layout.tsx`](https://github.com/avee1000/pr/blob/master/src/app/(dashboard)/layout.tsx) (Protected dashboard), [`src/lib/supabase/server.ts`](https://github.com/avee1000/pr/blob/master/src/lib/supabase/server.ts) (Supabase clients), [`src/app/layout.tsx`](https://github.com/avee1000/pr/blob/master/src/app/layout.tsx) (App shell), [`src/lib/orders/action.ts`](https://github.com/avee1000/pr/blob/master/src/lib/orders/action.ts) (Order actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_shell["App shell<br/>Next.js entry<br/>[layout.tsx]"]
  node_auth_pages["Auth pages<br/>public routes<br/>[page.tsx]"]
  node_dashboard["Protected dashboard<br/>route group<br/>[layout.tsx]"]
  node_access_proxy{{"Session proxy<br/>access control<br/>[proxy.ts]"}}
  node_quote_public["Public quote link<br/>capability route<br/>[page.tsx]"]
  node_order_api["Orders API<br/>REST handler<br/>[route.ts]"]
  node_approval_api["Quote approval API<br/>public REST handler<br/>[route.ts]"]
  node_notification_api["Notifications API<br/>REST handler<br/>[route.ts]"]
end

subgraph group_operations["Business workflows"]
  node_costs["Cost configuration<br/>dashboard feature<br/>[page.tsx]"]
  node_cost_actions["Cost actions<br/>server actions<br/>[action.ts]"]
  node_order_entry["Order creation<br/>dashboard feature<br/>[OrderForm.tsx]"]
  node_order_board["Order workflow board<br/>dashboard feature<br/>[OrderBoard.tsx]"]
  node_order_actions["Order actions<br/>server actions<br/>[action.ts]"]
  node_cash_flow["Cash flow<br/>dashboard aggregation<br/>[cashflow.ts]"]
end

subgraph group_backend["Supabase boundary"]
  node_supabase_clients["Supabase clients<br/>browser/server adapters<br/>[server.ts]"]
  node_supabase_auth{{"Supabase Auth<br/>identity provider"}}
  node_postgres[("Supabase PostgreSQL<br/>primary datastore")]
  node_rls_rpc{{"RLS and quote RPC<br/>database security<br/>[quote_rpc.sql]"}}
end

node_vercel(("Vercel<br/>hosting"))

node_shell --> node_auth_pages
node_shell --> node_dashboard
node_shell --> node_quote_public
node_access_proxy -->|"guards"| node_dashboard
node_access_proxy -->|"validates session"| node_supabase_auth
node_dashboard --> node_costs
node_dashboard --> node_order_entry
node_dashboard --> node_order_board
node_dashboard --> node_cash_flow
node_costs -->|"updates costs"| node_cost_actions
node_order_entry -->|"creates orders"| node_order_actions
node_order_board -->|"changes stage"| node_order_actions
node_cost_actions --> node_supabase_clients
node_order_actions --> node_supabase_clients
node_cash_flow -->|"reads paid orders"| node_supabase_clients
node_order_api -->|"derives user"| node_supabase_auth
node_order_api -->|"writes orders"| node_supabase_clients
node_quote_public -->|"approves quote"| node_approval_api
node_approval_api -->|"passes token"| node_rls_rpc
node_notification_api --> node_supabase_clients
node_supabase_clients -->|"queries"| node_postgres
node_rls_rpc -->|"enforces and executes"| node_postgres
node_vercel -->|"hosts"| node_shell

click node_shell "https://github.com/avee1000/pr/blob/master/src/app/layout.tsx"
click node_auth_pages "https://github.com/avee1000/pr/blob/master/src/app/(auth)/login/page.tsx"
click node_dashboard "https://github.com/avee1000/pr/blob/master/src/app/(dashboard)/layout.tsx"
click node_access_proxy "https://github.com/avee1000/pr/blob/master/src/proxy.ts"
click node_quote_public "https://github.com/avee1000/pr/blob/master/src/app/quote/%5Btoken%5D/page.tsx"
click node_costs "https://github.com/avee1000/pr/blob/master/src/app/(dashboard)/dashboard/costs/materials/page.tsx"
click node_cost_actions "https://github.com/avee1000/pr/blob/master/src/lib/costs/action.ts"
click node_order_entry "https://github.com/avee1000/pr/blob/master/src/components/dashboard/orders/create/OrderForm.tsx"
click node_order_board "https://github.com/avee1000/pr/blob/master/src/components/dashboard/orders/board/OrderBoard.tsx"
click node_order_actions "https://github.com/avee1000/pr/blob/master/src/lib/orders/action.ts"
click node_cash_flow "https://github.com/avee1000/pr/blob/master/src/lib/dashboard/cashflow.ts"
click node_order_api "https://github.com/avee1000/pr/blob/master/src/app/api/orders/route.ts"
click node_approval_api "https://github.com/avee1000/pr/blob/master/src/app/api/quotes/%5Btoken%5D/approve/route.ts"
click node_notification_api "https://github.com/avee1000/pr/blob/master/src/app/api/notifications/route.ts"
click node_supabase_clients "https://github.com/avee1000/pr/blob/master/src/lib/supabase/server.ts"
click node_postgres "https://github.com/avee1000/pr/blob/master/supabase/orders_quotes_rls.sql"
click node_rls_rpc "https://github.com/avee1000/pr/blob/master/supabase/quote_rpc.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_shell,node_auth_pages,node_dashboard,node_access_proxy,node_quote_public,node_order_api,node_approval_api,node_notification_api toneBlue
class node_costs,node_cost_actions,node_order_entry,node_order_board,node_order_actions,node_cash_flow toneAmber
class node_supabase_clients,node_supabase_auth,node_postgres,node_rls_rpc toneMint
class node_vercel toneNeutral
```

## Components

### Next.js application

- [App shell](https://github.com/avee1000/pr/blob/master/src/app/layout.tsx): Next.js entry · Global layout, landing page, and styles. · `src/app/layout.tsx`
- [Auth pages](https://github.com/avee1000/pr/blob/master/src/app/(auth)/login/page.tsx): public routes · `src/app/(auth)/login/page.tsx`
- [Protected dashboard](https://github.com/avee1000/pr/blob/master/src/app/(dashboard)/layout.tsx): route group · Authenticated operational UI. · `src/app/(dashboard)/layout.tsx`
- [Session proxy](https://github.com/avee1000/pr/blob/master/src/proxy.ts): access control · Guards dashboard routes while leaving quote links public. · `src/proxy.ts`
- [Public quote link](https://github.com/avee1000/pr/blob/master/src/app/quote/%5Btoken%5D/page.tsx): capability route · Unauthenticated token-based quote viewing. · `src/app/quote/[token]/page.tsx`
- [Orders API](https://github.com/avee1000/pr/blob/master/src/app/api/orders/route.ts): REST handler · Derives user identity from the session and stamps paid orders. · `src/app/api/orders/route.ts`
- [Quote approval API](https://github.com/avee1000/pr/blob/master/src/app/api/quotes/%5Btoken%5D/approve/route.ts): public REST handler · Approves only through the supplied quote token. · `src/app/api/quotes/[token]/approve/route.ts`
- [Notifications API](https://github.com/avee1000/pr/blob/master/src/app/api/notifications/route.ts): REST handler · Supports workflow alerts. · `src/app/api/notifications/route.ts`

### Business workflows

- [Cost configuration](https://github.com/avee1000/pr/blob/master/src/app/(dashboard)/dashboard/costs/materials/page.tsx): dashboard feature · Reusable material, labor, and profit-target inputs. · `src/app/(dashboard)/dashboard/costs/materials/page.tsx`
- [Cost actions](https://github.com/avee1000/pr/blob/master/src/lib/costs/action.ts): server actions · `src/lib/costs/action.ts`
- [Order creation](https://github.com/avee1000/pr/blob/master/src/components/dashboard/orders/create/OrderForm.tsx): dashboard feature · Binds customers, pricing inputs, due dates, and payment state. · `src/components/dashboard/orders/create/OrderForm.tsx`
- [Order workflow board](https://github.com/avee1000/pr/blob/master/src/components/dashboard/orders/board/OrderBoard.tsx): dashboard feature · Moves work through quote, approval, progress, and delivery. · `src/components/dashboard/orders/board/OrderBoard.tsx`
- [Order actions](https://github.com/avee1000/pr/blob/master/src/lib/orders/action.ts): server actions · `src/lib/orders/action.ts`
- [Cash flow](https://github.com/avee1000/pr/blob/master/src/lib/dashboard/cashflow.ts): dashboard aggregation · Aggregates paid orders by payment timestamp. · `src/lib/dashboard/cashflow.ts`

### Supabase boundary

- [Supabase clients](https://github.com/avee1000/pr/blob/master/src/lib/supabase/server.ts): browser/server adapters · Separates browser and server database access. · `src/lib/supabase/server.ts`
- **Supabase Auth**: identity provider
- [Supabase PostgreSQL](https://github.com/avee1000/pr/blob/master/supabase/orders_quotes_rls.sql): primary datastore · Stores customers, orders, quotes, costs, profit targets, and testimonials. · `supabase/orders_quotes_rls.sql`
- [RLS and quote RPC](https://github.com/avee1000/pr/blob/master/supabase/quote_rpc.sql): database security · RLS enforces access; token approval uses approve_quote_by_token. · `supabase/quote_rpc.sql`

### Other components

- **Vercel**: hosting · Deploys master production and PR previews.

## Connections

- App shell → Auth pages
- App shell → Protected dashboard
- App shell → Public quote link
- Session proxy → Protected dashboard: guards
- Session proxy → Supabase Auth: validates session
- Protected dashboard → Cost configuration
- Protected dashboard → Order creation
- Protected dashboard → Order workflow board
- Protected dashboard → Cash flow
- Cost configuration → Cost actions: updates costs
- Order creation → Order actions: creates orders
- Order workflow board → Order actions: changes stage
- Cost actions → Supabase clients
- Order actions → Supabase clients
- Cash flow → Supabase clients: reads paid orders
- Orders API → Supabase Auth: derives user
- Orders API → Supabase clients: writes orders
- Public quote link → Quote approval API: approves quote
- Quote approval API → RLS and quote RPC: passes token
- Notifications API → Supabase clients
- Supabase clients → Supabase PostgreSQL: queries
- RLS and quote RPC → Supabase PostgreSQL: enforces and executes
- Vercel → App shell: hosts
