# veeviiiii/parchi architecture

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

- Interactive diagram: https://gitdiagram.com/veeviiiii/parchi
- Repository: https://github.com/veeviiiii/parchi

## Overview

Parchi turns pasted WhatsApp chats into grouped, priced orders and printable bills, and provides Crowdmind, a role-based community feed for stock, offers, order calls, and quotes. The main flow is chat parsing, per-message Gemma interpretation, validated aggregation, organiser pricing, and bill creation. Crowdmind separately checks and moderates posts before storing them. Source excerpts support key calls; several page and domain links are documented in the README or SOURCE INDEX rather than shown in full.

Main entry points: [`components/Builder.tsx`](https://github.com/veeviiiii/parchi/blob/main/components/Builder.tsx) (Order builder), [`app/api/crowdmind/posts/route.ts`](https://github.com/veeviiiii/parchi/blob/main/app/api/crowdmind/posts/route.ts) (Crowdmind posts API), [`lib/crowdmind/checkPost.ts`](https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/checkPost.ts) (Post checking), [`lib/gemmaJson.ts`](https://github.com/veeviiiii/parchi/blob/main/lib/gemmaJson.ts) (Gemma JSON validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_order["Order building"]
  node_builder["Order builder<br/>[Builder.tsx]"]
  node_chatparse["Chat parser<br/>[parseChat.ts]"]
  node_parseapi["Message API<br/>[route.ts]"]
  node_reader["Message reader<br/>[readMessage.ts]"]
  node_jsonhelper["Gemma JSON validation<br/>[gemmaJson.ts]"]
  node_orderschema["Order schema and guards<br/>[schema.ts]"]
  node_aggregator["Order aggregation<br/>[aggregate.ts]"]
  node_gemma["Gemma client<br/>[gemma.ts]"]
end

subgraph group_billing["Pricing and bills"]
  node_pricing["Pricing and owing<br/>[money.ts]"]
  node_billlogic["Bill generation<br/>[bill.ts]"]
  node_billstore["Browser bill storage<br/>[billStore.ts]"]
  node_billpage["Printable bill<br/>[page.tsx]"]
end

subgraph group_community["Crowdmind"]
  node_crowdpage["Crowdmind feed<br/>[page.tsx]"]
  node_crowdapi["Crowdmind posts API<br/>[route.ts]"]
  node_postchecker["Post checking<br/>[checkPost.ts]"]
  node_postprompt["Post prompt<br/>[prompt.ts]"]
  node_postschema["Post schema and guards<br/>[schema.ts]"]
  node_poststore["Post storage<br/>[store.ts]"]
end

subgraph group_identity["Roles and interface"]
  node_rolelogic["Role permissions<br/>[roles.ts]"]
  node_profile["Browser profile<br/>[profile.ts]"]
  node_startpage["Role selection<br/>[page.tsx]"]
  node_header["App navigation<br/>[AppHeader.tsx]"]
  node_menus["Themes and language<br/>[Menus.tsx]"]
  node_landing["Landing page<br/>[page.tsx]"]
end

node_organizer(("Organizer"))
node_geminiservice["Gemini API"]
node_supabase[("Supabase")]

node_organizer -->|"enters chat"| node_builder
node_builder -->|"parses chat"| node_chatparse
node_builder -->|"requests message reads"| node_parseapi
node_parseapi -->|"calls reader"| node_reader
node_reader -->|"validates response"| node_jsonhelper
node_jsonhelper -->|"checks schema"| node_orderschema
node_jsonhelper -->|"requests generation"| node_gemma
node_gemma -->|"calls model"| node_geminiservice
node_builder -->|"groups reads"| node_aggregator
node_aggregator -->|"uses result type"| node_orderschema
node_builder -->|"calculates totals"| node_pricing
node_builder -->|"builds bill"| node_billlogic
node_billlogic -->|"uses order groups"| node_aggregator
node_billlogic -->|"uses prices"| node_pricing
node_builder -->|"saves bill"| node_billstore
node_billpage -->|"loads bill"| node_billstore
node_billpage -->|"formats bill"| node_billlogic
node_crowdpage -->|"fetches and posts"| node_crowdapi
node_crowdpage -->|"chooses spaces"| node_rolelogic
node_crowdapi -->|"checks submission"| node_postchecker
node_postchecker -->|"uses prompt"| node_postprompt
node_postchecker -->|"validates model output"| node_jsonhelper
node_postchecker -->|"applies guards"| node_postschema
node_crowdapi -->|"reads and writes posts"| node_poststore
node_poststore -.->|"persists when configured"| node_supabase
node_crowdapi -->|"checks permissions"| node_rolelogic
node_startpage -->|"saves profile"| node_profile
node_header -->|"reads profile"| node_profile
node_header -->|"renders theme menu"| node_menus
node_landing -->|"renders menus"| node_menus

click node_builder "https://github.com/veeviiiii/parchi/blob/main/components/Builder.tsx"
click node_chatparse "https://github.com/veeviiiii/parchi/blob/main/lib/parseChat.ts"
click node_parseapi "https://github.com/veeviiiii/parchi/blob/main/app/api/parse/route.ts"
click node_reader "https://github.com/veeviiiii/parchi/blob/main/lib/readMessage.ts"
click node_jsonhelper "https://github.com/veeviiiii/parchi/blob/main/lib/gemmaJson.ts"
click node_orderschema "https://github.com/veeviiiii/parchi/blob/main/lib/schema.ts"
click node_aggregator "https://github.com/veeviiiii/parchi/blob/main/lib/aggregate.ts"
click node_gemma "https://github.com/veeviiiii/parchi/blob/main/lib/gemma.ts"
click node_pricing "https://github.com/veeviiiii/parchi/blob/main/lib/money.ts"
click node_billlogic "https://github.com/veeviiiii/parchi/blob/main/lib/bill.ts"
click node_billstore "https://github.com/veeviiiii/parchi/blob/main/lib/billStore.ts"
click node_billpage "https://github.com/veeviiiii/parchi/blob/main/app/bill/%5Bid%5D/page.tsx"
click node_crowdpage "https://github.com/veeviiiii/parchi/blob/main/app/crowdmind/page.tsx"
click node_crowdapi "https://github.com/veeviiiii/parchi/blob/main/app/api/crowdmind/posts/route.ts"
click node_postchecker "https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/checkPost.ts"
click node_postprompt "https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/prompt.ts"
click node_postschema "https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/schema.ts"
click node_poststore "https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/store.ts"
click node_rolelogic "https://github.com/veeviiiii/parchi/blob/main/lib/roles.ts"
click node_profile "https://github.com/veeviiiii/parchi/blob/main/lib/profile.ts"
click node_startpage "https://github.com/veeviiiii/parchi/blob/main/app/start/page.tsx"
click node_header "https://github.com/veeviiiii/parchi/blob/main/components/AppHeader.tsx"
click node_menus "https://github.com/veeviiiii/parchi/blob/main/components/Menus.tsx"
click node_landing "https://github.com/veeviiiii/parchi/blob/main/app/page.tsx"

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_builder,node_chatparse,node_parseapi,node_reader,node_jsonhelper,node_orderschema,node_aggregator,node_gemma toneBlue
class node_pricing,node_billlogic,node_billstore,node_billpage,node_supabase toneAmber
class node_crowdpage,node_crowdapi,node_postchecker,node_postprompt,node_postschema,node_poststore,node_geminiservice toneMint
class node_rolelogic,node_profile,node_startpage,node_header,node_menus,node_landing toneRose
class node_organizer toneIndigo
```

## Components

### Order building

- [Order builder](https://github.com/veeviiiii/parchi/blob/main/components/Builder.tsx): `components/Builder.tsx`
- [Chat parser](https://github.com/veeviiiii/parchi/blob/main/lib/parseChat.ts): `lib/parseChat.ts`
- [Message API](https://github.com/veeviiiii/parchi/blob/main/app/api/parse/route.ts): `app/api/parse/route.ts`
- [Message reader](https://github.com/veeviiiii/parchi/blob/main/lib/readMessage.ts): `lib/readMessage.ts`
- [Gemma JSON validation](https://github.com/veeviiiii/parchi/blob/main/lib/gemmaJson.ts): `lib/gemmaJson.ts`
- [Order schema and guards](https://github.com/veeviiiii/parchi/blob/main/lib/schema.ts): `lib/schema.ts`
- [Order aggregation](https://github.com/veeviiiii/parchi/blob/main/lib/aggregate.ts): `lib/aggregate.ts`
- [Gemma client](https://github.com/veeviiiii/parchi/blob/main/lib/gemma.ts): `lib/gemma.ts`

### Pricing and bills

- [Pricing and owing](https://github.com/veeviiiii/parchi/blob/main/lib/money.ts): `lib/money.ts`
- [Bill generation](https://github.com/veeviiiii/parchi/blob/main/lib/bill.ts): `lib/bill.ts`
- [Browser bill storage](https://github.com/veeviiiii/parchi/blob/main/lib/billStore.ts): `lib/billStore.ts`
- [Printable bill](https://github.com/veeviiiii/parchi/blob/main/app/bill/%5Bid%5D/page.tsx): `app/bill/[id]/page.tsx`

### Crowdmind

- [Crowdmind feed](https://github.com/veeviiiii/parchi/blob/main/app/crowdmind/page.tsx): `app/crowdmind/page.tsx`
- [Crowdmind posts API](https://github.com/veeviiiii/parchi/blob/main/app/api/crowdmind/posts/route.ts): `app/api/crowdmind/posts/route.ts`
- [Post checking](https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/checkPost.ts): `lib/crowdmind/checkPost.ts`
- [Post prompt](https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/prompt.ts): `lib/crowdmind/prompt.ts`
- [Post schema and guards](https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/schema.ts): `lib/crowdmind/schema.ts`
- [Post storage](https://github.com/veeviiiii/parchi/blob/main/lib/crowdmind/store.ts): `lib/crowdmind/store.ts`

### Roles and interface

- [Role permissions](https://github.com/veeviiiii/parchi/blob/main/lib/roles.ts): `lib/roles.ts`
- [Browser profile](https://github.com/veeviiiii/parchi/blob/main/lib/profile.ts): `lib/profile.ts`
- [Role selection](https://github.com/veeviiiii/parchi/blob/main/app/start/page.tsx): `app/start/page.tsx`
- [App navigation](https://github.com/veeviiiii/parchi/blob/main/components/AppHeader.tsx): `components/AppHeader.tsx`
- [Themes and language](https://github.com/veeviiiii/parchi/blob/main/components/Menus.tsx): `components/Menus.tsx`
- [Landing page](https://github.com/veeviiiii/parchi/blob/main/app/page.tsx): `app/page.tsx`

### Other components

- **Organizer**
- **Gemini API**
- **Supabase**

## Connections

- Organizer → Order builder: enters chat (evidence: `README.md`)
- Order builder → Chat parser: parses chat (evidence: `components/Builder.tsx`)
- Order builder → Message API: requests message reads (evidence: `README.md`)
- Message API → Message reader: calls reader (evidence: `app/api/parse/route.ts`)
- Message reader → Gemma JSON validation: validates response (evidence: `lib/readMessage.ts`)
- Gemma JSON validation → Order schema and guards: checks schema (evidence: `lib/gemmaJson.ts`)
- Gemma JSON validation → Gemma client: requests generation (evidence: `lib/gemmaJson.ts`)
- Gemma client → Gemini API: calls model (evidence: `README.md`)
- Order builder → Order aggregation: groups reads (evidence: `components/Builder.tsx`)
- Order aggregation → Order schema and guards: uses result type (evidence: `lib/aggregate.ts`)
- Order builder → Pricing and owing: calculates totals (evidence: `components/Builder.tsx`)
- Order builder → Bill generation: builds bill (evidence: `components/Builder.tsx`)
- Bill generation → Order aggregation: uses order groups (evidence: `lib/bill.ts`)
- Bill generation → Pricing and owing: uses prices (evidence: `lib/bill.ts`)
- Order builder → Browser bill storage: saves bill (evidence: `components/Builder.tsx`)
- Printable bill → Browser bill storage: loads bill (evidence: `app/bill/[id]/page.tsx`)
- Printable bill → Bill generation: formats bill (evidence: `app/bill/[id]/page.tsx`)
- Crowdmind feed → Crowdmind posts API: fetches and posts (evidence: `app/crowdmind/page.tsx`)
- Crowdmind feed → Role permissions: chooses spaces (evidence: `app/crowdmind/page.tsx`)
- Crowdmind posts API → Post checking: checks submission (evidence: `app/api/crowdmind/posts/route.ts`)
- Post checking → Post prompt: uses prompt (evidence: `lib/crowdmind/checkPost.ts`)
- Post checking → Gemma JSON validation: validates model output (evidence: `lib/crowdmind/checkPost.ts`)
- Post checking → Post schema and guards: applies guards (evidence: `lib/crowdmind/checkPost.ts`)
- Crowdmind posts API → Post storage: reads and writes posts (evidence: `app/api/crowdmind/posts/route.ts`)
- Post storage → Supabase: persists when configured (evidence: `lib/crowdmind/store.ts`)
- Crowdmind posts API → Role permissions: checks permissions (evidence: `app/api/crowdmind/posts/route.ts`)
- Role selection → Browser profile: saves profile (evidence: `app/start/page.tsx`)
- App navigation → Browser profile: reads profile (evidence: `components/AppHeader.tsx`)
- App navigation → Themes and language: renders theme menu (evidence: `components/AppHeader.tsx`)
- Landing page → Themes and language: renders menus (evidence: `app/page.tsx`)
