Vanshik Waghela commited on
Commit
28c1fa2
Β·
1 Parent(s): 26e3332

docs: add comprehensive README for CourtMitra MissionOS

Browse files
Files changed (1) hide show
  1. README.md +144 -0
README.md ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CourtMitra MissionOS
2
+
3
+ **Citizen-side grievance + legal-action autopilot for India.** A citizen describes a problem once (WhatsApp, Telegram, or browser); the system turns it into a **mission**, builds the evidence file, grounds it in Indian law/procedure, picks an official route, drafts + sends approved actions, follows up, and records the outcome.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ apps/{web, api, worker}
9
+ packages/{domain, ports, adapters, db, contracts, prompts, ui}
10
+ ```
11
+
12
+ | Layer | Tech | Role |
13
+ |---|---|---|
14
+ | `apps/web` | Next.js (App Router), i18n | Multi-tab mission UI, public case pages, ledger |
15
+ | `apps/api` | NestJS + Fastify | REST endpoints, action preview/consent/execution |
16
+ | `apps/worker` | Inngest | Async workflow engine: intake, evidence, route-plan, action execution, followups |
17
+ | `packages/domain` | Pure TS | Entities, policies (`canResolve`), use-cases β€” zero framework deps |
18
+ | `packages/ports` | TS interfaces | Adapter contracts for channels, storage, LLM, redaction |
19
+ | `packages/adapters` | Various | Resend (email), Telegram, WhatsApp, social copy-ready |
20
+ | `packages/db` | Postgres + Drizzle ORM | Schema, migrations, seeds, materialized views |
21
+ | `packages/contracts` | Zod + OpenAPI | Single source of truth for all API I/O and LLM output shapes |
22
+ | `packages/prompts` | Versioned prompts | Evals included; no inline prompts in controllers |
23
+ | `packages/ui` | shadcn/ui + Tailwind | Shared UI components |
24
+
25
+ ## Platform Features
26
+
27
+ ### Lifecycle (10 states)
28
+ `route_plan_ready` β†’ `actions_preview_ready` β†’ `actions_awaiting_consent` β†’ `action_executing` β†’ `user_confirmed_external_submission` β†’ `waiting_for_response` β†’ `resolver_reply_received` β†’ `resolution_claimed` β†’ `resolved`
29
+
30
+ Plus: `created`, `intake_in_progress`, `needs_user_input`, `human_review_required`, `facts_confirmed`, `closed_unresolved`, `paused`, `blocked`, `failed`
31
+
32
+ ### Mission Page (6 tabs)
33
+ 1. **Overview** β€” current status, next action, timeline
34
+ 2. **Facts** β€” extracted evidence timeline, missing info questions
35
+ 3. **Route** β€” route plan steps with legal citations
36
+ 4. **Action** β€” preview, approve, consent, execute, confirm external
37
+ 5. **Follow-up** β€” waiting timer, social media escalation (X/Threads copy-drafts)
38
+ 6. **Outcome** β€” resolution filing, ledger publication
39
+
40
+ ### Security & Safety
41
+ - **Rank-guarded state machine** β€” no snapshot can regress the mission lifecycle (`STATE_RANK`)
42
+ - **Consent-first** β€” every send is gated by a hash-verified consent grant
43
+ - **Redaction** β€” Presidio-based PII redaction before any public output
44
+ - **Stop-and-refer** β€” emergency/criminal flags trigger `human_review_required`
45
+ - **Idempotency keys** β€” all write endpoints and webhooks are idempotent
46
+
47
+ ### Social Proof & Leverage
48
+ - **EscalateSocialCard** β€” copy-ready X.com/Threads drafts for immediate public posting
49
+ - **Swarms** β€” entity resolution tracks repeat offenders (Flipkart, Amazon, Paytm, etc.)
50
+ - **Public Case Pages** β€” private-link anonymized summaries for social sharing
51
+ - **Ledger** β€” `ledger_stats_view` + `repeat_offender_view` materialized views
52
+
53
+ ### Demo Data
54
+ - 10+ realistic missions across all lifecycle states, domains (consumer, payment, cyber_fraud), and states (Delhi, Maharashtra, Karnataka, etc.)
55
+ - 7 swarms with aggregated case counts
56
+ - 1 takedown request (Meta/Instagram)
57
+ - 5 public case pages with anonymized summaries
58
+ - 8 case lookups and 8 scheduled follow-ups
59
+
60
+ ## Quick Start
61
+
62
+ ```bash
63
+ # Prerequisites
64
+ node >= 20
65
+ pnpm >= 10
66
+ docker (for local Postgres)
67
+
68
+ # Install
69
+ pnpm install
70
+
71
+ # Start infrastructure (Postgres + Redis)
72
+ pnpm infra:up
73
+
74
+ # Run migrations
75
+ pnpm db:migrate
76
+
77
+ # Seed demo data
78
+ pnpm db:seed
79
+
80
+ # Start dev servers (web + api + worker)
81
+ pnpm dev
82
+ ```
83
+
84
+ Open `http://localhost:3000` in your browser.
85
+
86
+ ## Commands
87
+
88
+ | Command | Description |
89
+ |---|---|
90
+ | `pnpm dev` | Run web + api + worker in parallel |
91
+ | `pnpm build` | Build all packages |
92
+ | `pnpm typecheck` | `tsc --noEmit` across all 10 packages |
93
+ | `pnpm lint` | ESLint with dependency-boundary rules |
94
+ | `pnpm test` | Vitest (unit + integration) |
95
+ | `pnpm test:contracts` | Zod/OpenAPI contract validation |
96
+ | `pnpm db:migrate` | Run Drizzle migrations |
97
+ | `pnpm db:seed` | Seed route rules + curated citations |
98
+ | `pnpm infra:up` | Docker compose: Postgres + Redis |
99
+ | `pnpm infra:down` | Stop Docker containers |
100
+
101
+ ## Environment
102
+
103
+ Copy `infra/.env.example` to `infra/.env` (see `infra/.env` for current values). Key variables:
104
+
105
+ | Variable | Required | Description |
106
+ |---|---|---|
107
+ | `DATABASE_URL` | Yes | Postgres connection string |
108
+ | `RESEND_API_KEY` | For email | Resend email API key |
109
+ | `TELEGRAM_BOT_TOKEN` | For Telegram | Telegram bot token |
110
+ | `WHATSAPP_*` | For WhatsApp | WhatsApp Cloud API credentials |
111
+ | `X_API_*` | For X posting | X/Twitter API v2 credentials |
112
+ | `OPENAI_API_KEY` | For LLM | OpenAI / OpenRouter API key |
113
+
114
+ ## Key Design Decisions
115
+
116
+ - **Hexagonal architecture** β€” domain is pure TS with zero framework imports
117
+ - **Everything external is an Action** β€” adapters never called directly from workflows
118
+ - **State machine is rank-guarded** β€” no transition can regress the lifecycle
119
+ - **Contracts-first** β€” Zod schemas in `packages/contracts` are single source of truth; API routes and frontend import them
120
+ - **Database transactions + events** β€” all mutations go through Drizzle transactions; mission events are append-only audit
121
+ - **No fake submissions** β€” `proofState` accurately reflects real delivery status
122
+ - **No legal claim without cited source** β€” every legal statement carries `cited_chunk_ids`
123
+ - **Public pages are private-link only** β€” no indexing, no defamation risk
124
+ - **i18n** β€” English + Hindi (`next-intl`), language switcher in header
125
+
126
+ ## Loading Demo Data
127
+
128
+ ```bash
129
+ # Seed all demo missions with full lifecycle data
130
+ pnpm exec tsx packages/db/src/seeds/demo-data.ts
131
+ ```
132
+
133
+ This creates 10+ missions across all lifecycle states, swarms, takedown requests, public case pages, and ledger entries. It preserves existing user missions.
134
+
135
+ ## Non-Goals (Phase 2)
136
+
137
+ - Complaint swarm dashboard
138
+ - Live social auto-publishing (API keys needed)
139
+ - Company resolver portal
140
+ - Qdrant/rerank RAG upgrade
141
+ - ASR/voice transcription
142
+ - Supervised Playwright portal automation
143
+ - eCourts real-time case scraping
144
+ - AI-run public social account