# marianovilla/the-tribunal architecture

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

- Interactive diagram: https://gitdiagram.com/marianovilla/the-tribunal
- Repository: https://github.com/marianovilla/the-tribunal

## Overview

The Tribunal is a web app for submitting a case to a theatrical AI trial, viewing and sharing its verdict, and optionally appealing it. The main flow runs from case entry and tribunal selection through asynchronous trial creation and polling, then displays the verdict, arguments, and panel judgments. Gallery publishing, browsing, profiles, and Google sign-in support the surrounding experience. The README documents the four-stage LLM process and safety checks; sampled server excerpts establish routing and persistence, but not every internal pipeline call, so some subsystem links are omitted.

Main entry points: [`server/src/routes/trials.ts`](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/trials.ts) (Trial API), [`server/src/index.ts`](https://github.com/marianovilla/the-tribunal/blob/main/server/src/index.ts) (HTTP Server), [`server/src/pipeline/index.ts`](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/index.ts) (Trial Orchestrator), [`server/src/db/index.ts`](https://github.com/marianovilla/the-tribunal/blob/main/server/src/db/index.ts) (Database Access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Trial Experience"]
  node_home["Case Entry<br/>[HomePage.tsx]"]
  node_trialview["Trial View<br/>[TrialPage.tsx]"]
  node_trialpoll["Trial Polling<br/>[useTrial.ts]"]
  node_appealui["Appeal Filing<br/>[AppealSelector.tsx]"]
  node_verdict["Verdict Card<br/>[VerdictCard.tsx]"]
  node_sharing["Share Export<br/>[ShareButtons.tsx]"]
  node_galleryui["Gallery<br/>[GalleryPage.tsx]"]
  node_profileui["User Profile<br/>[ProfilePage.tsx]"]
  node_app["Client Routes<br/>[App.tsx]"]
end

subgraph group_api["Application Services"]
  node_server["HTTP Server<br/>[index.ts]"]
  node_trialroutes["Trial API<br/>[trials.ts]"]
  node_galleryroutes["Gallery API<br/>[gallery.ts]"]
  node_tribunalroutes["Tribunal API<br/>[tribunals.ts]"]
  node_authroutes["Auth API<br/>[auth.ts]"]
  node_profileroutes["Profile API<br/>[profile.ts]"]
end

subgraph group_pipeline["Trial Pipeline"]
  node_pipeline["Trial Orchestrator<br/>[index.ts]"]
  node_steps["LLM Trial Steps<br/>[steps.ts]"]
  node_prompts["Trial Prompts<br/>[prompts.ts]"]
  node_appealcontext["Appeal Context<br/>[appeal-context.ts]"]
  node_safety["Safety Review<br/>[safety.ts]"]
  node_tribunals["Tribunal Definitions<br/>[tribunals.ts]"]
  node_openrouter["LLM Adapter<br/>[openrouter.ts]"]
end

subgraph group_identity["Identity and Storage"]
  node_authclient["Sign-in Context<br/>[AuthContext.tsx]"]
  node_authservice["Session Auth<br/>[auth.ts]"]
  node_db[("Trial and Account Data<br/>[schema.ts]")]
  node_dbaccess["Database Access<br/>[index.ts]"]
  node_seed["Sample Trials<br/>[seedSamples.ts]"]
end

node_user(("Visitor"))
node_llm{{"LLM Provider"}}
node_google{{"Google OAuth"}}

node_user -->|"submits case"| node_home
node_home -->|"enters app"| node_app
node_home -.->|"creates trial"| node_trialroutes
node_trialroutes -->|"starts processing"| node_pipeline
node_pipeline -->|"runs stages"| node_steps
node_steps -->|"uses prompts"| node_prompts
node_steps -->|"requests completion"| node_openrouter
node_openrouter -->|"sends requests"| node_llm
node_pipeline -->|"checks submission"| node_safety
node_pipeline -->|"builds appeal context"| node_appealcontext
node_steps -->|"loads tribunal setup"| node_tribunals
node_appealui -.->|"files appeal"| node_trialroutes
node_trialroutes -.->|"gets tribunal choices"| node_tribunalroutes
node_trialview -->|"polls status"| node_trialpoll
node_trialview -->|"renders result"| node_verdict
node_trialview -->|"offers sharing"| node_sharing
node_sharing -->|"exports card"| node_verdict
node_galleryui -.->|"loads public trials"| node_galleryroutes
node_trialview -.->|"publishes verdict"| node_trialroutes
node_profileui -.->|"loads profile"| node_profileroutes
node_server -->|"mounts route"| node_trialroutes
node_server -->|"mounts route"| node_galleryroutes
node_server -->|"mounts route"| node_tribunalroutes
node_server -->|"mounts route"| node_authroutes
node_server -->|"mounts route"| node_profileroutes
node_server -->|"seeds samples"| node_seed
node_authclient -.->|"requests sign-in"| node_authroutes
node_authroutes -.->|"authenticates with"| node_google
node_authroutes -->|"manages sessions"| node_authservice
node_authservice -->|"reads and writes"| node_dbaccess
node_pipeline -->|"stores trial progress"| node_dbaccess
node_trialroutes -->|"reads and writes trials"| node_dbaccess
node_galleryroutes -->|"reads public trials"| node_dbaccess
node_dbaccess -->|"accesses schema"| node_db

click node_home "https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/HomePage.tsx"
click node_trialview "https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/TrialPage.tsx"
click node_trialpoll "https://github.com/marianovilla/the-tribunal/blob/main/client/src/hooks/useTrial.ts"
click node_appealui "https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/AppealSelector.tsx"
click node_verdict "https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/VerdictCard.tsx"
click node_sharing "https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/ShareButtons.tsx"
click node_galleryui "https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/GalleryPage.tsx"
click node_profileui "https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/ProfilePage.tsx"
click node_app "https://github.com/marianovilla/the-tribunal/blob/main/client/src/App.tsx"
click node_server "https://github.com/marianovilla/the-tribunal/blob/main/server/src/index.ts"
click node_trialroutes "https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/trials.ts"
click node_galleryroutes "https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/gallery.ts"
click node_tribunalroutes "https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/tribunals.ts"
click node_authroutes "https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/auth.ts"
click node_profileroutes "https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/profile.ts"
click node_pipeline "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/index.ts"
click node_steps "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/steps.ts"
click node_prompts "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/prompts.ts"
click node_appealcontext "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/appeal-context.ts"
click node_safety "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/safety.ts"
click node_tribunals "https://github.com/marianovilla/the-tribunal/blob/main/server/src/tribunals.ts"
click node_openrouter "https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/openrouter.ts"
click node_authclient "https://github.com/marianovilla/the-tribunal/blob/main/client/src/auth/AuthContext.tsx"
click node_authservice "https://github.com/marianovilla/the-tribunal/blob/main/server/src/auth.ts"
click node_db "https://github.com/marianovilla/the-tribunal/blob/main/server/src/db/schema.ts"
click node_dbaccess "https://github.com/marianovilla/the-tribunal/blob/main/server/src/db/index.ts"
click node_seed "https://github.com/marianovilla/the-tribunal/blob/main/server/src/seedSamples.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_home,node_trialview,node_trialpoll,node_appealui,node_verdict,node_sharing,node_galleryui,node_profileui,node_app toneBlue
class node_server,node_trialroutes,node_galleryroutes,node_tribunalroutes,node_authroutes,node_profileroutes toneAmber
class node_pipeline,node_steps,node_prompts,node_appealcontext,node_safety,node_tribunals,node_openrouter toneMint
class node_authclient,node_authservice,node_db,node_dbaccess,node_seed toneRose
class node_user,node_llm,node_google toneIndigo
```

## Components

### Trial Experience

- [Case Entry](https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/HomePage.tsx): `client/src/pages/HomePage.tsx`
- [Trial View](https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/TrialPage.tsx): `client/src/pages/TrialPage.tsx`
- [Trial Polling](https://github.com/marianovilla/the-tribunal/blob/main/client/src/hooks/useTrial.ts): `client/src/hooks/useTrial.ts`
- [Appeal Filing](https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/AppealSelector.tsx): `client/src/components/AppealSelector.tsx`
- [Verdict Card](https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/VerdictCard.tsx): `client/src/components/VerdictCard.tsx`
- [Share Export](https://github.com/marianovilla/the-tribunal/blob/main/client/src/components/ShareButtons.tsx): `client/src/components/ShareButtons.tsx`
- [Gallery](https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/GalleryPage.tsx): `client/src/pages/GalleryPage.tsx`
- [User Profile](https://github.com/marianovilla/the-tribunal/blob/main/client/src/pages/ProfilePage.tsx): `client/src/pages/ProfilePage.tsx`
- [Client Routes](https://github.com/marianovilla/the-tribunal/blob/main/client/src/App.tsx): `client/src/App.tsx`

### Application Services

- [HTTP Server](https://github.com/marianovilla/the-tribunal/blob/main/server/src/index.ts): `server/src/index.ts`
- [Trial API](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/trials.ts): `server/src/routes/trials.ts`
- [Gallery API](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/gallery.ts): `server/src/routes/gallery.ts`
- [Tribunal API](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/tribunals.ts): `server/src/routes/tribunals.ts`
- [Auth API](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/auth.ts): `server/src/routes/auth.ts`
- [Profile API](https://github.com/marianovilla/the-tribunal/blob/main/server/src/routes/profile.ts): `server/src/routes/profile.ts`

### Trial Pipeline

- [Trial Orchestrator](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/index.ts): `server/src/pipeline/index.ts`
- [LLM Trial Steps](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/steps.ts): `server/src/pipeline/steps.ts`
- [Trial Prompts](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/prompts.ts): `server/src/pipeline/prompts.ts`
- [Appeal Context](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/appeal-context.ts): `server/src/pipeline/appeal-context.ts`
- [Safety Review](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/safety.ts): `server/src/pipeline/safety.ts`
- [Tribunal Definitions](https://github.com/marianovilla/the-tribunal/blob/main/server/src/tribunals.ts): `server/src/tribunals.ts`
- [LLM Adapter](https://github.com/marianovilla/the-tribunal/blob/main/server/src/pipeline/openrouter.ts): `server/src/pipeline/openrouter.ts`

### Identity and Storage

- [Sign-in Context](https://github.com/marianovilla/the-tribunal/blob/main/client/src/auth/AuthContext.tsx): `client/src/auth/AuthContext.tsx`
- [Session Auth](https://github.com/marianovilla/the-tribunal/blob/main/server/src/auth.ts): `server/src/auth.ts`
- [Trial and Account Data](https://github.com/marianovilla/the-tribunal/blob/main/server/src/db/schema.ts): `server/src/db/schema.ts`
- [Database Access](https://github.com/marianovilla/the-tribunal/blob/main/server/src/db/index.ts): `server/src/db/index.ts`
- [Sample Trials](https://github.com/marianovilla/the-tribunal/blob/main/server/src/seedSamples.ts): `server/src/seedSamples.ts`

### Other components

- **Visitor**
- **LLM Provider**
- **Google OAuth**

## Connections

- Visitor → Case Entry: submits case (evidence: `README.md`)
- Case Entry → Client Routes: enters app (evidence: `client/src/App.tsx`)
- Case Entry → Trial API: creates trial
- Trial API → Trial Orchestrator: starts processing (evidence: `server/src/routes/trials.ts`)
- Trial Orchestrator → LLM Trial Steps: runs stages (evidence: `README.md`)
- LLM Trial Steps → Trial Prompts: uses prompts (evidence: `server/src/pipeline/steps.ts`)
- LLM Trial Steps → LLM Adapter: requests completion (evidence: `server/src/pipeline/steps.ts`)
- LLM Adapter → LLM Provider: sends requests (evidence: `README.md`)
- Trial Orchestrator → Safety Review: checks submission (evidence: `README.md`)
- Trial Orchestrator → Appeal Context: builds appeal context (evidence: `server/src/pipeline/index.ts`)
- LLM Trial Steps → Tribunal Definitions: loads tribunal setup (evidence: `server/src/pipeline/steps.ts`)
- Appeal Filing → Trial API: files appeal
- Trial API → Tribunal API: gets tribunal choices
- Trial View → Trial Polling: polls status (evidence: `client/src/pages/TrialPage.tsx`)
- Trial View → Verdict Card: renders result (evidence: `client/src/pages/TrialPage.tsx`)
- Trial View → Share Export: offers sharing (evidence: `client/src/pages/TrialPage.tsx`)
- Share Export → Verdict Card: exports card (evidence: `client/src/components/ShareButtons.tsx`)
- Gallery → Gallery API: loads public trials
- Trial View → Trial API: publishes verdict
- User Profile → Profile API: loads profile
- HTTP Server → Trial API: mounts route (evidence: `server/src/index.ts`)
- HTTP Server → Gallery API: mounts route (evidence: `server/src/index.ts`)
- HTTP Server → Tribunal API: mounts route (evidence: `server/src/index.ts`)
- HTTP Server → Auth API: mounts route (evidence: `server/src/index.ts`)
- HTTP Server → Profile API: mounts route (evidence: `server/src/index.ts`)
- HTTP Server → Sample Trials: seeds samples (evidence: `server/src/index.ts`)
- Sign-in Context → Auth API: requests sign-in
- Auth API → Google OAuth: authenticates with
- Auth API → Session Auth: manages sessions (evidence: `server/src/routes/auth.ts`)
- Session Auth → Database Access: reads and writes (evidence: `server/src/auth.ts`)
- Trial Orchestrator → Database Access: stores trial progress (evidence: `server/src/pipeline/index.ts`)
- Trial API → Database Access: reads and writes trials (evidence: `server/src/routes/trials.ts`)
- Gallery API → Database Access: reads public trials (evidence: `server/src/routes/gallery.ts`)
- Database Access → Trial and Account Data: accesses schema (evidence: `server/src/db/index.ts`)
