# ulasnazim/cn-crm architecture

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

- Interactive diagram: https://gitdiagram.com/ulasnazim/cn-crm
- Repository: https://github.com/ulasnazim/cn-crm

## Overview

CN CRM is a multi-tenant legal-firm CRM organized around the matter record. A firm user signs in, opens a matter, and works across its parties, notes, calendar, tasks, information, finance, and documents; firm-wide views expose shared records. The README also identifies contacts, AI assistance and document generation, reporting, and administration as product capabilities. The graph preserves those branches, plus external messaging and cloud-drive integrations. Several feature paths are unsampled, so their connections are shown as unverified; source-index references support the cited internal calls and data access.

Main entry points: [`src/server/matters.ts`](https://github.com/ulasnazim/cn-crm/blob/main/src/server/matters.ts) (Matter services), [`src/server/documents.ts`](https://github.com/ulasnazim/cn-crm/blob/main/src/server/documents.ts) (Document services), [`src/lib/db.ts`](https://github.com/ulasnazim/cn-crm/blob/main/src/lib/db.ts) (Tenant database), [`src/server/tasks.ts`](https://github.com/ulasnazim/cn-crm/blob/main/src/server/tasks.ts) (Tasks and reminders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and tenancy"]
  node_authui["Sign-in and account"]
  node_auth["Session and auth<br/>[auth.ts]"]
  node_tenant["Tenant permissions<br/>[tenancy.ts]"]
  node_database[("Tenant database<br/>[db.ts]")]
end

subgraph group_matter["Matter work"]
  node_matterui["Matter workspace"]
  node_matters["Matter services<br/>[matters.ts]"]
  node_contacts["Contacts"]
  node_tasks["Tasks and reminders<br/>[tasks.ts]"]
  node_calendar["Calendar and agenda<br/>[page.tsx]"]
  node_notes["Notes"]
end

subgraph group_documents["Documents and AI"]
  node_documentsui["Document workspace"]
  node_documents["Document services<br/>[documents.ts]"]
  node_blobstore[("Document storage")]
  node_aidocs["AI documents<br/>[ai-docs.ts]"]
  node_assistant["AI assistant<br/>[assistant.ts]"]
end

subgraph group_operations["Firm operations"]
  node_finance["Finance and billing<br/>[page.tsx]"]
  node_reports["Reports and export"]
  node_admin["Administration"]
end

subgraph group_integrations["External integrations"]
  node_drive["Google Drive"]
  node_gmail["Google Gmail"]
  node_whatsapp["WhatsApp"]
end

node_user(("Firm user"))

node_user -.->|"signs in"| node_authui
node_authui -.->|"authenticates"| node_auth
node_user -.->|"works matters"| node_matterui
node_matterui -.->|"loads matter data"| node_matters
node_matters -->|"checks scope"| node_tenant
node_matters -->|"queries matters"| node_database
node_user -.->|"manages contacts"| node_contacts
node_user -.->|"manages tasks"| node_tasks
node_tasks -->|"scopes matter tasks"| node_matters
node_tasks -->|"reads and writes"| node_database
node_user -.->|"uses calendar"| node_calendar
node_user -.->|"writes notes"| node_notes
node_user -.->|"manages documents"| node_documentsui
node_documentsui -->|"downloads documents"| node_documents
node_documents -.->|"stores document bytes"| node_blobstore
node_documents -->|"uses tenant data"| node_database
node_user -.->|"generates documents"| node_aidocs
node_user -.->|"requests assistance"| node_assistant
node_user -.->|"manages billing"| node_finance
node_user -.->|"views reports"| node_reports
node_reports -->|"loads firm finance"| node_matters
node_reports -.->|"reads tenant data"| node_database
node_user -.->|"configures firm"| node_admin
node_drive -.->|"mirrors files"| node_documents
node_gmail -.->|"connects account"| node_admin
node_whatsapp -.->|"configures messaging"| node_admin

click node_authui "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(auth)"
click node_auth "https://github.com/ulasnazim/cn-crm/blob/main/src/lib/auth.ts"
click node_tenant "https://github.com/ulasnazim/cn-crm/blob/main/src/lib/tenancy.ts"
click node_matterui "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/matters"
click node_matters "https://github.com/ulasnazim/cn-crm/blob/main/src/server/matters.ts"
click node_contacts "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/contacts"
click node_tasks "https://github.com/ulasnazim/cn-crm/blob/main/src/server/tasks.ts"
click node_calendar "https://github.com/ulasnazim/cn-crm/blob/main/src/app/(app)/calendar/page.tsx"
click node_notes "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/notes"
click node_documentsui "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/documents"
click node_documents "https://github.com/ulasnazim/cn-crm/blob/main/src/server/documents.ts"
click node_blobstore "https://github.com/ulasnazim/cn-crm/blob/main/src/server/document-storage.ts"
click node_aidocs "https://github.com/ulasnazim/cn-crm/blob/main/src/server/ai-docs.ts"
click node_assistant "https://github.com/ulasnazim/cn-crm/blob/main/src/server/assistant.ts"
click node_finance "https://github.com/ulasnazim/cn-crm/blob/main/src/app/(app)/finance/page.tsx"
click node_reports "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/reports"
click node_admin "https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/admin"
click node_database "https://github.com/ulasnazim/cn-crm/blob/main/src/lib/db.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_authui,node_auth,node_tenant,node_database,node_user toneBlue
class node_matterui,node_matters,node_contacts,node_tasks,node_calendar,node_notes toneAmber
class node_documentsui,node_documents,node_blobstore,node_aidocs,node_assistant toneMint
class node_finance,node_reports,node_admin toneRose
class node_drive,node_gmail,node_whatsapp toneIndigo
```

## Components

### Access and tenancy

- [Sign-in and account](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(auth)): `src/app/(auth)`
- [Session and auth](https://github.com/ulasnazim/cn-crm/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Tenant permissions](https://github.com/ulasnazim/cn-crm/blob/main/src/lib/tenancy.ts): `src/lib/tenancy.ts`
- [Tenant database](https://github.com/ulasnazim/cn-crm/blob/main/src/lib/db.ts): `src/lib/db.ts`

### Matter work

- [Matter workspace](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/matters): `src/app/(app)/matters`
- [Matter services](https://github.com/ulasnazim/cn-crm/blob/main/src/server/matters.ts): `src/server/matters.ts`
- [Contacts](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/contacts): `src/app/(app)/contacts`
- [Tasks and reminders](https://github.com/ulasnazim/cn-crm/blob/main/src/server/tasks.ts): `src/server/tasks.ts`
- [Calendar and agenda](https://github.com/ulasnazim/cn-crm/blob/main/src/app/(app)/calendar/page.tsx): `src/app/(app)/calendar/page.tsx`
- [Notes](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/notes): `src/app/(app)/notes`

### Documents and AI

- [Document workspace](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/documents): `src/app/(app)/documents`
- [Document services](https://github.com/ulasnazim/cn-crm/blob/main/src/server/documents.ts): `src/server/documents.ts`
- [Document storage](https://github.com/ulasnazim/cn-crm/blob/main/src/server/document-storage.ts): `src/server/document-storage.ts`
- [AI documents](https://github.com/ulasnazim/cn-crm/blob/main/src/server/ai-docs.ts): `src/server/ai-docs.ts`
- [AI assistant](https://github.com/ulasnazim/cn-crm/blob/main/src/server/assistant.ts): `src/server/assistant.ts`

### Firm operations

- [Finance and billing](https://github.com/ulasnazim/cn-crm/blob/main/src/app/(app)/finance/page.tsx): `src/app/(app)/finance/page.tsx`
- [Reports and export](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/reports): `src/app/(app)/reports`
- [Administration](https://github.com/ulasnazim/cn-crm/tree/main/src/app/(app)/admin): `src/app/(app)/admin`

### External integrations

- **Google Drive**
- **Google Gmail**
- **WhatsApp**

### Other components

- **Firm user**

## Connections

- Firm user → Sign-in and account: signs in (evidence: `README.md`)
- Sign-in and account → Session and auth: authenticates
- Firm user → Matter workspace: works matters (evidence: `README.md`)
- Matter workspace → Matter services: loads matter data
- Matter services → Tenant permissions: checks scope (evidence: `src/server/matters.ts`)
- Matter services → Tenant database: queries matters (evidence: `src/server/matters.ts`)
- Firm user → Contacts: manages contacts (evidence: `README.md`)
- Firm user → Tasks and reminders: manages tasks (evidence: `README.md`)
- Tasks and reminders → Matter services: scopes matter tasks (evidence: `src/server/tasks.ts`)
- Tasks and reminders → Tenant database: reads and writes (evidence: `src/server/tasks.ts`)
- Firm user → Calendar and agenda: uses calendar (evidence: `README.md`)
- Firm user → Notes: writes notes (evidence: `README.md`)
- Firm user → Document workspace: manages documents (evidence: `README.md`)
- Document workspace → Document services: downloads documents (evidence: `src/app/(app)/documents/[id]/download/route.ts`)
- Document services → Document storage: stores document bytes
- Document services → Tenant database: uses tenant data
- Firm user → AI documents: generates documents (evidence: `README.md`)
- Firm user → AI assistant: requests assistance (evidence: `README.md`)
- Firm user → Finance and billing: manages billing (evidence: `README.md`)
- Firm user → Reports and export: views reports (evidence: `README.md`)
- Reports and export → Matter services: loads firm finance (evidence: `src/app/(app)/reports/export/route.ts`)
- Reports and export → Tenant database: reads tenant data
- Firm user → Administration: configures firm (evidence: `README.md`)
- Google Drive → Document services: mirrors files
- Google Gmail → Administration: connects account
- WhatsApp → Administration: configures messaging
