# shoaibkhan-sde/legallens architecture

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

- Interactive diagram: https://gitdiagram.com/shoaibkhan-sde/legallens
- Repository: https://github.com/shoaibkhan-sde/legallens

## Overview

LegalLens is a bilingual AI contract-auditing application for people who need to understand, compare, and act on legal documents. The primary workflow runs from document capture through the browser API and server-side audit stages to an interactive review, with separate comparison, voice-assistance, and legal-aid capabilities. The README documents pipeline stages and generated outputs; sampled source confirms key frontend calls, backend processing, and state persistence. Some subsystem links rely on README descriptions because their implementation excerpts were not included.

Main entry points: [`src/App.tsx`](https://github.com/shoaibkhan-sde/legallens/blob/main/src/App.tsx) (Application shell), [`server/src/services/astraBackend.ts`](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts) (Audit pipeline), [`src/services/apiClient.ts`](https://github.com/shoaibkhan-sde/legallens/blob/main/src/services/apiClient.ts) (Browser API client), [`src/components/DocumentCapture.tsx`](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/DocumentCapture.tsx) (Document capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_app["Application shell<br/>[App.tsx]"]
  node_capture["Document capture"]
  node_review["Audit dashboard<br/>[DocumentViewer.tsx]"]
  node_clause["Clause review<br/>[ClauseCard.tsx]"]
  node_compare["Contract comparison<br/>[ComparisonView.tsx]"]
end

subgraph group_audit["Contract Audit"]
  node_pipeline["Audit pipeline<br/>[astraBackend.ts]"]
  node_gate["Legal input gate<br/>[astraBackend.ts]"]
  node_extract["Document extraction<br/>[astraBackend.ts]"]
  node_chunk["Clause taxonomy<br/>[astraBackend.ts]"]
  node_risk["Risk and grounding<br/>[astraBackend.ts]"]
  node_synthesis["Audit synthesis<br/>[astraBackend.ts]"]
  node_outputs["Actionable outputs"]
  node_ical["Calendar export<br/>[icalExporter.ts]"]
  node_alignment["Clause alignment<br/>[clauseAlignment.ts]"]
end

subgraph group_assistance["User Assistance"]
  node_voice["Voice assistant"]
  node_speech["Speech utilities<br/>[speech.ts]"]
  node_chat["AI chat assistant"]
  node_legal_aid["Legal aid locator"]
end

subgraph group_platform["API and State"]
  node_audit_api["Browser API client<br/>[apiClient.ts]"]
  node_server["HTTP API routes<br/>[index.ts]"]
  node_schemas["Domain schemas<br/>[schemas.ts]"]
  node_language["Bilingual support"]
  node_persistence[("Browser persistence<br/>[persistence.ts]")]
end

node_user(("Contract user"))
node_groq(("Groq AI service"))

node_user -->|"uses"| node_app
node_app -->|"presents"| node_capture
node_app -->|"presents"| node_review
node_app -->|"presents"| node_clause
node_app -->|"presents"| node_compare
node_capture -->|"submits document"| node_audit_api
node_audit_api -->|"requests analysis"| node_server
node_compare -->|"requests comparison"| node_audit_api
node_server -->|"invokes audit"| node_pipeline
node_pipeline -->|"checks intent"| node_gate
node_pipeline -->|"parses document"| node_extract
node_pipeline -->|"chunks clauses"| node_chunk
node_pipeline -->|"tags and grounds"| node_risk
node_pipeline -->|"synthesizes audit"| node_synthesis
node_pipeline -.->|"uses AI"| node_groq
node_audit_api -->|"returns analysis"| node_app
node_app -->|"displays artifacts"| node_outputs
node_outputs -->|"exports deadlines"| node_ical
node_compare -->|"aligns clauses"| node_alignment
node_app -->|"presents"| node_voice
node_voice -->|"sends questions"| node_audit_api
node_voice -->|"uses speech"| node_speech
node_app -->|"presents"| node_chat
node_chat -->|"sends questions"| node_audit_api
node_app -->|"presents"| node_legal_aid
node_app -->|"provides translations"| node_language
node_capture -->|"saves session"| node_persistence
node_outputs -->|"saves view state"| node_persistence
node_app -->|"saves analysis state"| node_persistence
node_pipeline -->|"produces typed results"| node_schemas
node_audit_api -->|"uses result types"| node_schemas
node_review -->|"renders analysis"| node_schemas

click node_app "https://github.com/shoaibkhan-sde/legallens/blob/main/src/App.tsx"
click node_capture "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/DocumentCapture.tsx"
click node_review "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/DocumentViewer.tsx"
click node_clause "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ClauseCard.tsx"
click node_compare "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ComparisonView.tsx"
click node_audit_api "https://github.com/shoaibkhan-sde/legallens/blob/main/src/services/apiClient.ts"
click node_server "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/index.ts"
click node_schemas "https://github.com/shoaibkhan-sde/legallens/blob/main/src/types/schemas.ts"
click node_pipeline "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_gate "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_extract "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_chunk "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_risk "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_synthesis "https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts"
click node_outputs "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ActionableOutputs.tsx"
click node_ical "https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/icalExporter.ts"
click node_alignment "https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/clauseAlignment.ts"
click node_voice "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/VoiceGroundedChat.tsx"
click node_speech "https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/speech.ts"
click node_chat "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/RoboAiAssistant.tsx"
click node_legal_aid "https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/LegalAidLocator.tsx"
click node_language "https://github.com/shoaibkhan-sde/legallens/blob/main/src/context/LanguageContext.tsx"
click node_persistence "https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/persistence.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_app,node_capture,node_review,node_clause,node_compare,node_user toneBlue
class node_pipeline,node_gate,node_extract,node_chunk,node_risk,node_synthesis,node_outputs,node_ical,node_alignment toneAmber
class node_voice,node_speech,node_chat,node_legal_aid toneMint
class node_audit_api,node_server,node_schemas,node_language,node_persistence toneRose
class node_groq toneIndigo
```

## Components

### User Experience

- [Application shell](https://github.com/shoaibkhan-sde/legallens/blob/main/src/App.tsx): `src/App.tsx`
- [Document capture](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/DocumentCapture.tsx): `src/components/DocumentCapture.tsx`
- [Audit dashboard](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/DocumentViewer.tsx): `src/components/DocumentViewer.tsx`
- [Clause review](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ClauseCard.tsx): `src/components/ClauseCard.tsx`
- [Contract comparison](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ComparisonView.tsx): `src/components/ComparisonView.tsx`

### Contract Audit

- [Audit pipeline](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Legal input gate](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Document extraction](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Clause taxonomy](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Risk and grounding](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Audit synthesis](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/services/astraBackend.ts): `server/src/services/astraBackend.ts`
- [Actionable outputs](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/ActionableOutputs.tsx): `src/components/ActionableOutputs.tsx`
- [Calendar export](https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/icalExporter.ts): `src/utils/icalExporter.ts`
- [Clause alignment](https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/clauseAlignment.ts): `src/utils/clauseAlignment.ts`

### User Assistance

- [Voice assistant](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/VoiceGroundedChat.tsx): `src/components/VoiceGroundedChat.tsx`
- [Speech utilities](https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/speech.ts): `src/utils/speech.ts`
- [AI chat assistant](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/RoboAiAssistant.tsx): `src/components/RoboAiAssistant.tsx`
- [Legal aid locator](https://github.com/shoaibkhan-sde/legallens/blob/main/src/components/LegalAidLocator.tsx): `src/components/LegalAidLocator.tsx`

### API and State

- [Browser API client](https://github.com/shoaibkhan-sde/legallens/blob/main/src/services/apiClient.ts): `src/services/apiClient.ts`
- [HTTP API routes](https://github.com/shoaibkhan-sde/legallens/blob/main/server/src/index.ts): `server/src/index.ts`
- [Domain schemas](https://github.com/shoaibkhan-sde/legallens/blob/main/src/types/schemas.ts): `src/types/schemas.ts`
- [Bilingual support](https://github.com/shoaibkhan-sde/legallens/blob/main/src/context/LanguageContext.tsx): `src/context/LanguageContext.tsx`
- [Browser persistence](https://github.com/shoaibkhan-sde/legallens/blob/main/src/utils/persistence.ts): `src/utils/persistence.ts`

### Other components

- **Contract user**
- **Groq AI service**

## Connections

- Contract user → Application shell: uses (evidence: `README.md`)
- Application shell → Document capture: presents (evidence: `src/App.tsx`)
- Application shell → Audit dashboard: presents (evidence: `src/App.tsx`)
- Application shell → Clause review: presents (evidence: `src/App.tsx`)
- Application shell → Contract comparison: presents (evidence: `src/App.tsx`)
- Document capture → Browser API client: submits document (evidence: `src/components/DocumentCapture.tsx`)
- Browser API client → HTTP API routes: requests analysis (evidence: `src/services/apiClient.ts`)
- Contract comparison → Browser API client: requests comparison (evidence: `src/services/apiClient.ts`)
- HTTP API routes → Audit pipeline: invokes audit (evidence: `server/src/index.ts`)
- Audit pipeline → Legal input gate: checks intent (evidence: `server/src/services/astraBackend.ts`)
- Audit pipeline → Document extraction: parses document (evidence: `README.md`)
- Audit pipeline → Clause taxonomy: chunks clauses (evidence: `server/src/services/astraBackend.ts`)
- Audit pipeline → Risk and grounding: tags and grounds (evidence: `server/src/services/astraBackend.ts`)
- Audit pipeline → Audit synthesis: synthesizes audit (evidence: `README.md`)
- Audit pipeline → Groq AI service: uses AI (evidence: `README.md`)
- Browser API client → Application shell: returns analysis (evidence: `src/services/apiClient.ts`)
- Application shell → Actionable outputs: displays artifacts (evidence: `README.md`)
- Actionable outputs → Calendar export: exports deadlines (evidence: `README.md`)
- Contract comparison → Clause alignment: aligns clauses (evidence: `README.md`)
- Application shell → Voice assistant: presents (evidence: `src/App.tsx`)
- Voice assistant → Browser API client: sends questions (evidence: `src/components/VoiceGroundedChat.tsx`)
- Voice assistant → Speech utilities: uses speech (evidence: `src/utils/speech.ts`)
- Application shell → AI chat assistant: presents (evidence: `src/App.tsx`)
- AI chat assistant → Browser API client: sends questions (evidence: `src/components/RoboAiAssistant.tsx`)
- Application shell → Legal aid locator: presents (evidence: `src/App.tsx`)
- Application shell → Bilingual support: provides translations (evidence: `src/context/LanguageContext.tsx`)
- Document capture → Browser persistence: saves session (evidence: `src/components/DocumentCapture.tsx`)
- Actionable outputs → Browser persistence: saves view state (evidence: `src/components/ActionableOutputs.tsx`)
- Application shell → Browser persistence: saves analysis state (evidence: `src/App.tsx`)
- Audit pipeline → Domain schemas: produces typed results (evidence: `server/src/services/astraBackend.ts`)
- Browser API client → Domain schemas: uses result types (evidence: `src/services/apiClient.ts`)
- Audit dashboard → Domain schemas: renders analysis (evidence: `README.md`)
