# adhityacl/new-clm architecture

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

- Interactive diagram: https://gitdiagram.com/adhityacl/new-clm
- Repository: https://github.com/adhityacl/new-clm

## Overview

Legalio is a multi-tenant CLM for managing contracts, partners, insertion orders, due diligence, and document drafting. Users sign in, select an organization, work with scoped business records or create and redline contract documents, then monitor activity and renewals. The main internal layers are the React application, Express API and SQLite persistence, and shared authorization and policy logic. The README documents additional AI, Google, and administration capabilities; several of their implementation paths are present in the tree but were not sampled, so those links are marked unverified.

Main entry points: [`src/App.tsx`](https://github.com/adhityacl/new-clm/blob/main/src/App.tsx) (Application Shell), [`server.ts`](https://github.com/adhityacl/new-clm/blob/main/server.ts) (Express API), [`src/server/authConsoleRoutes.ts`](https://github.com/adhityacl/new-clm/blob/main/src/server/authConsoleRoutes.ts) (Admin Console API), [`src/server/documentRoutes.ts`](https://github.com/adhityacl/new-clm/blob/main/src/server/documentRoutes.ts) (Document API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application UI"]
  node_app["Application Shell<br/>[App.tsx]"]
  node_language["Language Provider"]
end

subgraph group_records["Business Records"]
  node_dashboard["Dashboard<br/>[DashboardView.tsx]"]
  node_contracts["Contracts<br/>[ContractsView.tsx]"]
  node_partners["Partners and Evaluation<br/>[PartnersView.tsx]"]
  node_spendings["Partner Spendings"]
  node_orders["Insertion Orders<br/>[IOView.tsx]"]
  node_hierarchy["Legal Structure"]
  node_bulk["Bulk Import<br/>[BulkImportView.tsx]"]
  node_settings["Tenant Settings<br/>[SettingsView.tsx]"]
end

subgraph group_creator["Document Creator"]
  node_creator["Contract Creator"]
  node_doc_ui["Document Explorer and Redlining"]
  node_doc_api["Document API<br/>[documentRoutes.ts]"]
end

subgraph group_access["Identity and Scope"]
  node_auth_ui["Sign-in and Session<br/>[AuthContext.tsx]"]
  node_tenant_ui["Organization Context<br/>[TenantContext.tsx]"]
  node_rbac["RBAC Engine<br/>[rbac.ts]"]
  node_rbac_routes["RBAC Routes<br/>[rbacRoutes.ts]"]
  node_console["Admin Console API"]
  node_policy["Tenant Policy Packs<br/>[index.ts]"]
end

subgraph group_platform["API and Integrations"]
  node_api["Express API<br/>[server.ts]"]
  node_sqlite[("SQLite Data<br/>[auth.ts]")]
  node_ocr["Document Parsing and OCR"]
  node_drive["Google Drive Sync<br/>[googleDriveSync.ts]"]
  node_gemini["Google Gemini"]
  node_google["Google Drive and Sheets"]
  node_email["SMTP Email"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"provides session"| node_auth_ui
node_app -->|"provides tenant"| node_tenant_ui
node_app -->|"provides language"| node_language
node_app -->|"renders"| node_dashboard
node_app -.->|"renders"| node_contracts
node_app -.->|"renders"| node_partners
node_app -.->|"renders"| node_spendings
node_app -.->|"renders"| node_orders
node_app -->|"renders"| node_hierarchy
node_app -.->|"renders"| node_bulk
node_app -.->|"renders"| node_settings
node_app -.->|"renders"| node_creator
node_creator -.->|"includes explorer"| node_doc_ui
node_creator -.->|"uses AI workflows"| node_gemini
node_doc_ui -.->|"requests documents"| node_doc_api
node_api -->|"mounts routes"| node_doc_api
node_doc_api -->|"checks permissions"| node_rbac
node_doc_api -->|"reads and writes"| node_sqlite
node_api -->|"mounts routes"| node_rbac_routes
node_rbac_routes -->|"delegates decisions"| node_rbac
node_api -->|"mounts routes"| node_console
node_console -->|"enforces access"| node_rbac
node_console -->|"resolves settings"| node_policy
node_api -.->|"persists application data"| node_sqlite
node_ocr -->|"caches extraction"| node_sqlite
node_api -->|"provisions folders"| node_drive
node_drive -.->|"synchronizes files"| node_google
node_api -.->|"provides AI features"| node_gemini
node_console -.->|"sends invitations"| node_email
node_user -.->|"signs in"| node_auth_ui
node_tenant_ui -.->|"loads tenant data"| node_api

click node_app "https://github.com/adhityacl/new-clm/blob/main/src/App.tsx"
click node_auth_ui "https://github.com/adhityacl/new-clm/blob/main/src/context/AuthContext.tsx"
click node_tenant_ui "https://github.com/adhityacl/new-clm/blob/main/src/context/TenantContext.tsx"
click node_language "https://github.com/adhityacl/new-clm/blob/main/src/context/LanguageContext.tsx"
click node_dashboard "https://github.com/adhityacl/new-clm/blob/main/src/components/DashboardView.tsx"
click node_contracts "https://github.com/adhityacl/new-clm/blob/main/src/components/ContractsView.tsx"
click node_partners "https://github.com/adhityacl/new-clm/blob/main/src/components/PartnersView.tsx"
click node_spendings "https://github.com/adhityacl/new-clm/blob/main/src/components/PartnerSpendingView.tsx"
click node_orders "https://github.com/adhityacl/new-clm/blob/main/src/components/IOView.tsx"
click node_hierarchy "https://github.com/adhityacl/new-clm/blob/main/src/components/HierarchyTreemapView.tsx"
click node_bulk "https://github.com/adhityacl/new-clm/blob/main/src/components/BulkImportView.tsx"
click node_settings "https://github.com/adhityacl/new-clm/blob/main/src/components/SettingsView.tsx"
click node_creator "https://github.com/adhityacl/new-clm/blob/main/src/components/ContractCreatorView.tsx"
click node_doc_ui "https://github.com/adhityacl/new-clm/blob/main/src/components/documents/DocumentExplorer.tsx"
click node_doc_api "https://github.com/adhityacl/new-clm/blob/main/src/server/documentRoutes.ts"
click node_api "https://github.com/adhityacl/new-clm/blob/main/server.ts"
click node_sqlite "https://github.com/adhityacl/new-clm/blob/main/src/lib/auth.ts"
click node_rbac "https://github.com/adhityacl/new-clm/blob/main/server/rbac.ts"
click node_rbac_routes "https://github.com/adhityacl/new-clm/blob/main/server/rbacRoutes.ts"
click node_console "https://github.com/adhityacl/new-clm/blob/main/src/server/authConsoleRoutes.ts"
click node_policy "https://github.com/adhityacl/new-clm/blob/main/src/lib/policy/index.ts"
click node_ocr "https://github.com/adhityacl/new-clm/blob/main/src/lib/cheapOcrPipeline.ts"
click node_drive "https://github.com/adhityacl/new-clm/blob/main/src/lib/googleDriveSync.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_language,node_user toneBlue
class node_dashboard,node_contracts,node_partners,node_spendings,node_orders,node_hierarchy,node_bulk,node_settings toneAmber
class node_creator,node_doc_ui,node_doc_api toneMint
class node_auth_ui,node_tenant_ui,node_rbac,node_rbac_routes,node_console,node_policy toneRose
class node_api,node_sqlite,node_ocr,node_drive,node_gemini,node_google,node_email toneIndigo
```

## Components

### Application UI

- [Application Shell](https://github.com/adhityacl/new-clm/blob/main/src/App.tsx): `src/App.tsx`
- [Language Provider](https://github.com/adhityacl/new-clm/blob/main/src/context/LanguageContext.tsx): `src/context/LanguageContext.tsx`

### Business Records

- [Dashboard](https://github.com/adhityacl/new-clm/blob/main/src/components/DashboardView.tsx): `src/components/DashboardView.tsx`
- [Contracts](https://github.com/adhityacl/new-clm/blob/main/src/components/ContractsView.tsx): `src/components/ContractsView.tsx`
- [Partners and Evaluation](https://github.com/adhityacl/new-clm/blob/main/src/components/PartnersView.tsx): `src/components/PartnersView.tsx`
- [Partner Spendings](https://github.com/adhityacl/new-clm/blob/main/src/components/PartnerSpendingView.tsx): `src/components/PartnerSpendingView.tsx`
- [Insertion Orders](https://github.com/adhityacl/new-clm/blob/main/src/components/IOView.tsx): `src/components/IOView.tsx`
- [Legal Structure](https://github.com/adhityacl/new-clm/blob/main/src/components/HierarchyTreemapView.tsx): `src/components/HierarchyTreemapView.tsx`
- [Bulk Import](https://github.com/adhityacl/new-clm/blob/main/src/components/BulkImportView.tsx): `src/components/BulkImportView.tsx`
- [Tenant Settings](https://github.com/adhityacl/new-clm/blob/main/src/components/SettingsView.tsx): `src/components/SettingsView.tsx`

### Document Creator

- [Contract Creator](https://github.com/adhityacl/new-clm/blob/main/src/components/ContractCreatorView.tsx): `src/components/ContractCreatorView.tsx`
- [Document Explorer and Redlining](https://github.com/adhityacl/new-clm/blob/main/src/components/documents/DocumentExplorer.tsx): `src/components/documents/DocumentExplorer.tsx`
- [Document API](https://github.com/adhityacl/new-clm/blob/main/src/server/documentRoutes.ts): `src/server/documentRoutes.ts`

### Identity and Scope

- [Sign-in and Session](https://github.com/adhityacl/new-clm/blob/main/src/context/AuthContext.tsx): `src/context/AuthContext.tsx`
- [Organization Context](https://github.com/adhityacl/new-clm/blob/main/src/context/TenantContext.tsx): `src/context/TenantContext.tsx`
- [RBAC Engine](https://github.com/adhityacl/new-clm/blob/main/server/rbac.ts): `server/rbac.ts`
- [RBAC Routes](https://github.com/adhityacl/new-clm/blob/main/server/rbacRoutes.ts): `server/rbacRoutes.ts`
- [Admin Console API](https://github.com/adhityacl/new-clm/blob/main/src/server/authConsoleRoutes.ts): `src/server/authConsoleRoutes.ts`
- [Tenant Policy Packs](https://github.com/adhityacl/new-clm/blob/main/src/lib/policy/index.ts): `src/lib/policy/index.ts`

### API and Integrations

- [Express API](https://github.com/adhityacl/new-clm/blob/main/server.ts): `server.ts`
- [SQLite Data](https://github.com/adhityacl/new-clm/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Document Parsing and OCR](https://github.com/adhityacl/new-clm/blob/main/src/lib/cheapOcrPipeline.ts): `src/lib/cheapOcrPipeline.ts`
- [Google Drive Sync](https://github.com/adhityacl/new-clm/blob/main/src/lib/googleDriveSync.ts): `src/lib/googleDriveSync.ts`
- **Google Gemini**
- **Google Drive and Sheets**
- **SMTP Email**

### Other components

- **User**

## Connections

- User → Application Shell: uses
- Application Shell → Sign-in and Session: provides session (evidence: `src/App.tsx`)
- Application Shell → Organization Context: provides tenant (evidence: `src/App.tsx`)
- Application Shell → Language Provider: provides language (evidence: `src/App.tsx`)
- Application Shell → Dashboard: renders (evidence: `src/App.tsx`)
- Application Shell → Contracts: renders (evidence: `src/App.tsx`)
- Application Shell → Partners and Evaluation: renders (evidence: `src/App.tsx`)
- Application Shell → Partner Spendings: renders (evidence: `src/App.tsx`)
- Application Shell → Insertion Orders: renders (evidence: `src/App.tsx`)
- Application Shell → Legal Structure: renders (evidence: `src/App.tsx`)
- Application Shell → Bulk Import: renders (evidence: `src/App.tsx`)
- Application Shell → Tenant Settings: renders (evidence: `src/App.tsx`)
- Application Shell → Contract Creator: renders (evidence: `src/App.tsx`)
- Contract Creator → Document Explorer and Redlining: includes explorer
- Contract Creator → Google Gemini: uses AI workflows
- Document Explorer and Redlining → Document API: requests documents
- Express API → Document API: mounts routes (evidence: `server.ts`)
- Document API → RBAC Engine: checks permissions (evidence: `src/server/documentRoutes.ts`)
- Document API → SQLite Data: reads and writes (evidence: `src/server/documentRoutes.ts`)
- Express API → RBAC Routes: mounts routes (evidence: `server.ts`)
- RBAC Routes → RBAC Engine: delegates decisions (evidence: `server/rbacRoutes.ts`)
- Express API → Admin Console API: mounts routes (evidence: `server.ts`)
- Admin Console API → RBAC Engine: enforces access (evidence: `src/server/authConsoleRoutes.ts`)
- Admin Console API → Tenant Policy Packs: resolves settings (evidence: `src/server/authConsoleRoutes.ts`)
- Express API → SQLite Data: persists application data (evidence: `server.ts`)
- Document Parsing and OCR → SQLite Data: caches extraction (evidence: `src/lib/cheapOcrPipeline.ts`)
- Express API → Google Drive Sync: provisions folders (evidence: `server.ts`)
- Google Drive Sync → Google Drive and Sheets: synchronizes files
- Express API → Google Gemini: provides AI features
- Admin Console API → SMTP Email: sends invitations
- User → Sign-in and Session: signs in
- Organization Context → Express API: loads tenant data
