# marveloussystem0-design/legalhub-deployment architecture

> Architecture diagram of the GitHub repository marveloussystem0-design/legalhub-deployment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marveloussystem0-design/legalhub-deployment
- Repository: https://github.com/marveloussystem0-design/legalhub-deployment

## Overview

#### Purpose and entry points
Legalhub is a legal-services platform for advocates, clients, and administrators: case management, client collaboration, court/eCourts tracking, document drafting, legal knowledge, notifications, verification, and subscriptions. The primary production surface is the Next.js App Router application under `web/src/app/page.tsx` and `web/src/app/dashboard/page.tsx`. A separate Expo/React Native mobile client is rooted at `mobile-app/app/_layout.tsx`.

#### Web application shell and role portals
The web runtime is a TypeScript Next.js 14 application with server-rendered routes, server actions, and route handlers. Authentication flows enter through `web/src/app/login/page.tsx`, `web/src/app/signup/page.tsx`, and `web/src/app/auth/callback/page.tsx`; role-specific navigation separates advocate, client, and admin workspaces under `web/src/app/dashboard/advocate/layout.tsx`, `web/src/app/dashboard/client/layout.tsx`, and `web/src/app/dashboard/admin/layout.tsx`.

#### Supabase identity, persistence, and security boundary
Supabase is the system of record and provides PostgreSQL, Auth, Storage, and access enforcement. Web code uses distinct browser, server, middleware, and privileged service-role clients in `web/src/lib/supabase/client.ts`, `web/src/lib/supabase/server.ts`, and `web/src/lib/supabase/service-role.ts`. Database evolution is migration-driven under `supabase/migrations/`, including signup/profile triggers, RLS hardening, case relationships, notifications, subscriptions, and document sharing. RLS is therefore the principal boundary between user-facing data access and admin/background operations.

#### Case lifecycle and collaboration
Advocates create, browse, filter, import, update, and synchronize matters; case detail includes participants, documents, timeline, reminders, court links, and eCourts data. The core UI and mutations are concentrated in `web/src/app/dashboard/advocate/cases/page.tsx`, `web/src/app/dashboard/advocate/cases/[id]/page.tsx`, and `web/src/app/actions/cases.ts`. Invite-based client participation crosses into public/authenticated onboarding via `web/src/app/api/cases/invite/route.ts` and `web/src/app/invite/[token]/page.tsx`. Advocate/client message views provide the collaboration boundary in `web/src/app/dashboard/advocate/messages/page.tsx` and `web/src/app/dashboard/client/messages/page.tsx`.

#### Court-data ingestion and scheduling
eCourts integration is a server-side acquisition and normalization pipeline: API routes invoke search/sync endpoints, scraper/parser/processor code extracts and transforms court data, and case records consume synchronized hearings and metadata. Key boundaries are `web/src/app/api/ecourts/sync/route.ts`, `web/src/lib/ecourts/scraper.ts`, and `web/src/lib/ecourts/processor.ts`. The repository also contains Puppeteer-based scraping and CAPTCHA/session infrastructure under `web/src/lib/scrapers/puppeteer-client.ts`, `web/src/lib/scrapers/tn-captcha-solver.ts`, and `web/src/lib/scrapers/advocate-scraper-session-manager.ts`. Hearing/reminder automation is exposed as scheduled endpoints in `web/src/app/api/cron/reminders/route.ts` and `web/src/app/api/scheduler/hearings/route.ts`.

#### Legal content and drafting
The platform has two content paths: database-backed legal acts/judgments and application-provided reference datasets/templates. Knowledge-base APIs are in `web/src/app/api/knowledge-base/acts/route.ts` and `web/src/app/api/knowledge-base/judgments/route.ts`, backed by `web/src/lib/db/legal-acts.ts`. Drafting uses an editor and structured templates in `web/src/app/dashboard/advocate/draft/page.tsx`, `web/src/components/editor/document-editor.tsx`, and `web/src/app/dashboard/advocate/draft/templates/index.ts`. The large `web/DRAFTS/` corpus is source content rather than application logic.

#### Monetization, notifications, and delivery
Razorpay-backed subscription and verification-badge payments are handled through API endpoints and billing services: `web/src/app/api/billing/create-order/route.ts`, `web/src/app/api/billing/webhook/route.ts`, and `web/src/lib/billing/razorpay.ts`. Notification dispatch is background-oriented through `web/src/app/api/cron/process-notifications/route.ts` and `web/src/lib/services/notifications.ts`. Deployment targets Vercel (`web/vercel.json`), while Docker support exists at `web/Dockerfile` and `docker-compose.yml`; CI/CD is defined in `.github/workflows/deploy.yml`.

Main entry points: [`web/src/lib/supabase/server.ts`](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/supabase/server.ts) (Supabase), [`web/src/app/actions/cases.ts`](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/actions/cases.ts) (Case management), [`web/src/app/dashboard/advocate/layout.tsx`](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/dashboard/advocate/layout.tsx) (Role portals), [`web/src/app/page.tsx`](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/page.tsx) (Next.js web app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client runtimes"]
  node_mobile_app["Mobile client<br/>Expo / React Native<br/>[_layout.tsx]"]
end

subgraph group_web["Web platform"]
  node_web_app["Next.js web app<br/>Next.js 14<br/>[page.tsx]"]
  node_auth["Authentication<br/>App Router routes<br/>[page.tsx]"]
  node_role_portals["Role portals<br/>Dashboard layouts<br/>[layout.tsx]"]
  node_case_management["Case management<br/>Pages + server actions<br/>[cases.ts]"]
  node_collaboration["Client collaboration<br/>Messages and invites<br/>[route.ts]"]
  node_knowledge_base["Legal knowledge<br/>Knowledge APIs<br/>[route.ts]"]
  node_drafting["Document drafting<br/>Editor + templates<br/>[page.tsx]"]
end

subgraph group_integrations["Server integrations"]
  node_ecourts_api["eCourts sync API<br/>Route handler<br/>[route.ts]"]
  node_ecourts_acquisition["Court acquisition<br/>Scraper + session stack<br/>[scraper.ts]"]
  node_ecourts_processor["Court normalization<br/>Processor<br/>[processor.ts]"]
  node_billing["Subscriptions and payments<br/>Razorpay API<br/>[route.ts]"]
end

subgraph group_data["Data and security"]
  node_supabase[("Supabase<br/>PostgreSQL, Auth, Storage<br/>[server.ts]")]
  node_rls_migrations["RLS and migrations<br/>Database policy"]
end

subgraph group_operations["Operations"]
  node_hearing_scheduler["Hearing scheduler<br/>Scheduled endpoint<br/>[route.ts]"]
  node_notifications["Notification dispatch<br/>Cron + service<br/>[route.ts]"]
  node_deployment["Deployment pipeline<br/>Vercel, Docker, CI/CD<br/>[deploy.yml]"]
end

node_web_app -->|"serves"| node_auth
node_auth -->|"uses Auth"| node_supabase
node_web_app -->|"routes users to"| node_role_portals
node_role_portals -->|"advocate workflow"| node_case_management
node_role_portals -->|"message workspaces"| node_collaboration
node_case_management -->|"invites clients"| node_collaboration
node_case_management -->|"syncs court data"| node_ecourts_api
node_ecourts_api -->|"acquires"| node_ecourts_acquisition
node_ecourts_acquisition -->|"raw court data"| node_ecourts_processor
node_ecourts_processor -->|"stores normalized data"| node_supabase
node_hearing_scheduler -->|"updates hearings"| node_case_management
node_case_management -->|"persists matters"| node_supabase
node_collaboration -->|"persists access and messages"| node_supabase
node_knowledge_base -->|"reads legal content"| node_supabase
node_drafting -->|"uses case context"| node_case_management
node_billing -->|"updates entitlements"| node_supabase
node_notifications -->|"reads and records notifications"| node_supabase
node_supabase -->|"enforced by"| node_rls_migrations
node_mobile_app -->|"accesses platform data"| node_supabase
node_deployment -->|"deploys"| node_web_app

click node_web_app "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/page.tsx"
click node_mobile_app "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/mobile-app/app/_layout.tsx"
click node_auth "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/login/page.tsx"
click node_role_portals "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/dashboard/advocate/layout.tsx"
click node_case_management "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/actions/cases.ts"
click node_collaboration "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/cases/invite/route.ts"
click node_ecourts_api "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/ecourts/sync/route.ts"
click node_ecourts_acquisition "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/ecourts/scraper.ts"
click node_ecourts_processor "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/ecourts/processor.ts"
click node_hearing_scheduler "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/scheduler/hearings/route.ts"
click node_knowledge_base "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/knowledge-base/acts/route.ts"
click node_drafting "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/dashboard/advocate/draft/page.tsx"
click node_billing "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/billing/create-order/route.ts"
click node_notifications "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/cron/process-notifications/route.ts"
click node_supabase "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/supabase/server.ts"
click node_rls_migrations "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/supabase/migrations/20260123_final_rls_lockdown.sql"
click node_deployment "https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/.github/workflows/deploy.yml"

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_mobile_app toneBlue
class node_web_app,node_auth,node_role_portals,node_case_management,node_collaboration,node_knowledge_base,node_drafting toneAmber
class node_ecourts_api,node_ecourts_acquisition,node_ecourts_processor,node_billing toneMint
class node_supabase,node_rls_migrations toneRose
class node_hearing_scheduler,node_notifications,node_deployment toneIndigo
```

## Components

### Client runtimes

- [Mobile client](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/mobile-app/app/_layout.tsx): Expo / React Native · `mobile-app/app/_layout.tsx`

### Web platform

- [Next.js web app](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/page.tsx): Next.js 14 · Primary server-rendered application and API runtime. · `web/src/app/page.tsx`
- [Authentication](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/login/page.tsx): App Router routes · `web/src/app/login/page.tsx`
- [Role portals](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/dashboard/advocate/layout.tsx): Dashboard layouts · Separate advocate, client, and admin workspaces. · `web/src/app/dashboard/advocate/layout.tsx`
- [Case management](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/actions/cases.ts): Pages + server actions · Matter lifecycle, participants, documents, and timelines. · `web/src/app/actions/cases.ts`
- [Client collaboration](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/cases/invite/route.ts): Messages and invites · Client participation is initiated by case invitations. · `web/src/app/api/cases/invite/route.ts`
- [Legal knowledge](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/knowledge-base/acts/route.ts): Knowledge APIs · Acts and judgments served from database-backed content. · `web/src/app/api/knowledge-base/acts/route.ts`
- [Document drafting](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/dashboard/advocate/draft/page.tsx): Editor + templates · Structured legal drafting for advocates. · `web/src/app/dashboard/advocate/draft/page.tsx`

### Server integrations

- [eCourts sync API](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/ecourts/sync/route.ts): Route handler · `web/src/app/api/ecourts/sync/route.ts`
- [Court acquisition](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/ecourts/scraper.ts): Scraper + session stack · Handles court extraction, CAPTCHA, and sessions. · `web/src/lib/ecourts/scraper.ts`
- [Court normalization](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/ecourts/processor.ts): Processor · Transforms acquired court data for case records. · `web/src/lib/ecourts/processor.ts`
- [Subscriptions and payments](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/billing/create-order/route.ts): Razorpay API · Orders, webhooks, subscriptions, and verification badges. · `web/src/app/api/billing/create-order/route.ts`

### Data and security

- [Supabase](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/lib/supabase/server.ts): PostgreSQL, Auth, Storage · System of record and identity provider. · `web/src/lib/supabase/server.ts`
- [RLS and migrations](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/supabase/migrations/20260123_final_rls_lockdown.sql): Database policy · Migration-driven schema, triggers, and access enforcement. · `supabase/migrations/20260123_final_rls_lockdown.sql`

### Operations

- [Hearing scheduler](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/scheduler/hearings/route.ts): Scheduled endpoint · `web/src/app/api/scheduler/hearings/route.ts`
- [Notification dispatch](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/web/src/app/api/cron/process-notifications/route.ts): Cron + service · Background-oriented notification processing. · `web/src/app/api/cron/process-notifications/route.ts`
- [Deployment pipeline](https://github.com/marveloussystem0-design/legalhub-deployment/blob/main/.github/workflows/deploy.yml): Vercel, Docker, CI/CD · `.github/workflows/deploy.yml`

## Connections

- Next.js web app → Authentication: serves
- Authentication → Supabase: uses Auth
- Next.js web app → Role portals: routes users to
- Role portals → Case management: advocate workflow
- Role portals → Client collaboration: message workspaces
- Case management → Client collaboration: invites clients
- Case management → eCourts sync API: syncs court data
- eCourts sync API → Court acquisition: acquires
- Court acquisition → Court normalization: raw court data
- Court normalization → Supabase: stores normalized data
- Hearing scheduler → Case management: updates hearings
- Case management → Supabase: persists matters
- Client collaboration → Supabase: persists access and messages
- Legal knowledge → Supabase: reads legal content
- Document drafting → Case management: uses case context
- Subscriptions and payments → Supabase: updates entitlements
- Notification dispatch → Supabase: reads and records notifications
- Supabase → RLS and migrations: enforced by
- Mobile client → Supabase: accesses platform data
- Deployment pipeline → Next.js web app: deploys
