# paingsc/rtms-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/paingsc/rtms-v2
- Repository: https://github.com/paingsc/rtms-v2

## Overview

RTMS V2 is a multi-tenant rice-trading management web app. Its tenant workspace exposes setup and opening balances, master data and prices, purchases, sales, stock, money, reporting, and operational administration; login and staff management support access to that work. The sampled item and price managers call guarded Supabase RPCs, while the README identifies tenancy, roles, audit, and database guards as platform capabilities. Offline selling, purchasing, and collection are distinct documented-by-route capabilities in the tree, but their internal wiring was not sampled; those links are shown as unverified.

Main entry points: [`apps/web/src/app/[locale]/t/[slug]/page.tsx`](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/page.tsx) (Tenant workspace), [`apps/web/src/lib/supabase/browser.ts`](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/lib/supabase/browser.ts) (Browser Supabase client), [`apps/web/src/components/PriceManager.tsx`](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/PriceManager.tsx) (Price management), [`apps/web/src/components/ItemManager.tsx`](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/ItemManager.tsx) (Item management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and tenancy"]
  node_login["Login and MFA<br/>[page.tsx]"]
  node_tenant["Tenant workspace<br/>[page.tsx]"]
  node_staffadmin["Staff administration<br/>[StaffManager.tsx]"]
  node_admin["Platform administration<br/>[page.tsx]"]
end

subgraph group_operations["Trading operations"]
  node_items["Item management<br/>[ItemManager.tsx]"]
  node_prices["Price management<br/>[PriceManager.tsx]"]
  node_price_sheets["Price import and bulk<br/>[PriceSheets.tsx]"]
  node_sales["Sales<br/>[page.tsx]"]
  node_sale_review["Sale review<br/>[ReviewStep.tsx]"]
  node_purchases["Purchasing<br/>[page.tsx]"]
  node_stock["Stock operations<br/>[page.tsx]"]
  node_money["Customer and supplier money<br/>[page.tsx]"]
  node_opening["Opening balances and stock<br/>[page.tsx]"]
  node_dayclose["Day close<br/>[page.tsx]"]
end

subgraph group_insight["Reporting and records"]
  node_reports["Reports and summaries<br/>[page.tsx]"]
  node_history["Audit history<br/>[HistoryPanel.tsx]"]
  node_print["Print documents<br/>[page.tsx]"]
end

subgraph group_offline["Offline work"]
  node_offline["Offline selling, buying, collection"]
  node_offline_store[("Offline store and outbox")]
end

subgraph group_shared["Shared services"]
  node_providers["Client providers<br/>[Providers.tsx]"]
  node_ui["UI primitives"]
  node_supabase_browser["Browser Supabase client<br/>[browser.ts]"]
  node_database[("Supabase database")]
end

node_staff(("Staff user"))

node_staff -.->|"signs in"| node_login
node_login -.->|"opens workspace"| node_tenant
node_tenant -.->|"manages items"| node_items
node_tenant -.->|"sets prices"| node_prices
node_tenant -.->|"records sales"| node_sales
node_tenant -.->|"records purchases"| node_purchases
node_tenant -.->|"manages stock"| node_stock
node_tenant -.->|"tracks balances"| node_money
node_tenant -.->|"enters opening data"| node_opening
node_tenant -.->|"closes day"| node_dayclose
node_tenant -.->|"views reports"| node_reports
node_tenant -.->|"prints documents"| node_print
node_tenant -.->|"uses offline tools"| node_offline
node_tenant -.->|"manages staff"| node_staffadmin
node_staff -.->|"administers platform"| node_admin
node_items -->|"calls item RPCs"| node_supabase_browser
node_prices -->|"calls price RPCs"| node_supabase_browser
node_prices -->|"renders sheets"| node_price_sheets
node_price_sheets -->|"calls price RPCs"| node_supabase_browser
node_staffadmin -->|"calls staff RPCs"| node_supabase_browser
node_history -->|"reads audit log"| node_supabase_browser
node_history -->|"renders in manager"| node_items
node_sales -.->|"presents review"| node_sale_review
node_sale_review -->|"formats values"| node_providers
node_providers -->|"provides UI contexts"| node_ui
node_supabase_browser -.->|"reads and writes"| node_database
node_offline -.->|"uses local state"| node_offline_store

click node_login "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/login/page.tsx"
click node_tenant "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/page.tsx"
click node_staffadmin "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/StaffManager.tsx"
click node_admin "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/admin/page.tsx"
click node_items "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/ItemManager.tsx"
click node_prices "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/PriceManager.tsx"
click node_price_sheets "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/PriceSheets.tsx"
click node_sales "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/sales/page.tsx"
click node_sale_review "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/sale/ReviewStep.tsx"
click node_purchases "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/purchases/page.tsx"
click node_stock "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/stock/page.tsx"
click node_money "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/money/page.tsx"
click node_opening "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/opening/page.tsx"
click node_dayclose "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/day-close/page.tsx"
click node_reports "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/reports/page.tsx"
click node_history "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/HistoryPanel.tsx"
click node_print "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/print/%5Bslug%5D/%5Bdoc%5D/%5Bid%5D/page.tsx"
click node_offline "https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/components/offline"
click node_offline_store "https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/lib/offline"
click node_providers "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/Providers.tsx"
click node_ui "https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/components/ui"
click node_supabase_browser "https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/lib/supabase/browser.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_login,node_tenant,node_staffadmin,node_admin,node_staff toneBlue
class node_items,node_prices,node_price_sheets,node_sales,node_sale_review,node_purchases,node_stock,node_money,node_opening,node_dayclose toneAmber
class node_reports,node_history,node_print toneMint
class node_offline,node_offline_store toneRose
class node_providers,node_ui,node_supabase_browser,node_database toneIndigo
```

## Components

### Access and tenancy

- [Login and MFA](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/login/page.tsx): `apps/web/src/app/[locale]/login/page.tsx`
- [Tenant workspace](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/page.tsx): `apps/web/src/app/[locale]/t/[slug]/page.tsx`
- [Staff administration](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/StaffManager.tsx): `apps/web/src/components/StaffManager.tsx`
- [Platform administration](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/admin/page.tsx): `apps/web/src/app/[locale]/admin/page.tsx`

### Trading operations

- [Item management](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/ItemManager.tsx): `apps/web/src/components/ItemManager.tsx`
- [Price management](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/PriceManager.tsx): `apps/web/src/components/PriceManager.tsx`
- [Price import and bulk](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/PriceSheets.tsx): `apps/web/src/components/PriceSheets.tsx`
- [Sales](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/sales/page.tsx): `apps/web/src/app/[locale]/t/[slug]/sales/page.tsx`
- [Sale review](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/sale/ReviewStep.tsx): `apps/web/src/components/sale/ReviewStep.tsx`
- [Purchasing](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/purchases/page.tsx): `apps/web/src/app/[locale]/t/[slug]/purchases/page.tsx`
- [Stock operations](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/stock/page.tsx): `apps/web/src/app/[locale]/t/[slug]/stock/page.tsx`
- [Customer and supplier money](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/money/page.tsx): `apps/web/src/app/[locale]/t/[slug]/money/page.tsx`
- [Opening balances and stock](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/opening/page.tsx): `apps/web/src/app/[locale]/t/[slug]/opening/page.tsx`
- [Day close](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/day-close/page.tsx): `apps/web/src/app/[locale]/t/[slug]/day-close/page.tsx`

### Reporting and records

- [Reports and summaries](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/t/%5Bslug%5D/reports/page.tsx): `apps/web/src/app/[locale]/t/[slug]/reports/page.tsx`
- [Audit history](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/HistoryPanel.tsx): `apps/web/src/components/HistoryPanel.tsx`
- [Print documents](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/app/%5Blocale%5D/print/%5Bslug%5D/%5Bdoc%5D/%5Bid%5D/page.tsx): `apps/web/src/app/[locale]/print/[slug]/[doc]/[id]/page.tsx`

### Offline work

- [Offline selling, buying, collection](https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/components/offline): `apps/web/src/components/offline`
- [Offline store and outbox](https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/lib/offline): `apps/web/src/lib/offline`

### Shared services

- [Client providers](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/components/Providers.tsx): `apps/web/src/components/Providers.tsx`
- [UI primitives](https://github.com/paingsc/rtms-v2/tree/main/apps/web/src/components/ui): `apps/web/src/components/ui`
- [Browser Supabase client](https://github.com/paingsc/rtms-v2/blob/main/apps/web/src/lib/supabase/browser.ts): `apps/web/src/lib/supabase/browser.ts`
- **Supabase database**

### Other components

- **Staff user**

## Connections

- Staff user → Login and MFA: signs in
- Login and MFA → Tenant workspace: opens workspace
- Tenant workspace → Item management: manages items
- Tenant workspace → Price management: sets prices
- Tenant workspace → Sales: records sales
- Tenant workspace → Purchasing: records purchases
- Tenant workspace → Stock operations: manages stock
- Tenant workspace → Customer and supplier money: tracks balances
- Tenant workspace → Opening balances and stock: enters opening data
- Tenant workspace → Day close: closes day
- Tenant workspace → Reports and summaries: views reports
- Tenant workspace → Print documents: prints documents
- Tenant workspace → Offline selling, buying, collection: uses offline tools
- Tenant workspace → Staff administration: manages staff
- Staff user → Platform administration: administers platform
- Item management → Browser Supabase client: calls item RPCs (evidence: `apps/web/src/components/ItemManager.tsx`)
- Price management → Browser Supabase client: calls price RPCs (evidence: `apps/web/src/components/PriceManager.tsx`)
- Price management → Price import and bulk: renders sheets (evidence: `apps/web/src/components/PriceManager.tsx`)
- Price import and bulk → Browser Supabase client: calls price RPCs (evidence: `apps/web/src/components/PriceSheets.tsx`)
- Staff administration → Browser Supabase client: calls staff RPCs (evidence: `apps/web/src/components/StaffManager.tsx`)
- Audit history → Browser Supabase client: reads audit log (evidence: `apps/web/src/components/HistoryPanel.tsx`)
- Audit history → Item management: renders in manager (evidence: `apps/web/src/components/ItemManager.tsx`)
- Sales → Sale review: presents review
- Sale review → Client providers: formats values (evidence: `apps/web/src/components/sale/ReviewStep.tsx`)
- Client providers → UI primitives: provides UI contexts (evidence: `apps/web/src/components/Providers.tsx`)
- Browser Supabase client → Supabase database: reads and writes
- Offline selling, buying, collection → Offline store and outbox: uses local state
