# kamelfcis/artilleryinternalcrm architecture

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

- Interactive diagram: https://gitdiagram.com/kamelfcis/artilleryinternalcrm
- Repository: https://github.com/kamelfcis/artilleryinternalcrm

## Overview

This is an Arabic RTL document-management and organizational CRM application. Users sign in, browse permission-controlled folders, manage documents, and retrieve files through authorized streaming; administrators also manage users and review audit history. The graph preserves the documented document lifecycle and the repository’s substantial CRM, search, import/OCR, linking, approvals, and task capabilities. Edges rely on README statements or SOURCE INDEX references; unsampled implementation details are represented without speculative call chains.

Main entry points: [`src/lib/prisma.ts`](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/prisma.ts) (Application database), [`src/app/api/documents/[id]/content/route.ts`](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/api/documents/%5Bid%5D/content/route.ts) (Authorized file route), [`src/lib/services/documents.ts`](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/documents.ts) (Document services), [`src/lib/events/index.ts`](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/index.ts) (Domain events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Authenticated app<br/>[layout.tsx]"]
  node_folder_ui["Folder explorer"]
  node_document_ui["Document preview"]
  node_crm_ui["CRM workspace<br/>[crm-manager.tsx]"]
  node_search_route["Search API<br/>[route.ts]"]
end

subgraph group_documents["Document lifecycle"]
  node_folder_service["Folder services<br/>[folders.ts]"]
  node_document_service["Document services<br/>[documents.ts]"]
  node_trash_service["Recycle bin<br/>[trash.ts]"]
  node_content_route["Authorized file route<br/>[route.ts]"]
  node_import["Document import<br/>[service.ts]"]
  node_ocr["OCR processing<br/>[service.ts]"]
end

subgraph group_workspace["Business workspace"]
  node_crm_api["CRM REST routes<br/>[rest.ts]"]
  node_crm_registry["CRM entity registry<br/>[registry.ts]"]
  node_search["Global search<br/>[engine.ts]"]
  node_extraction["Field extraction<br/>[service.ts]"]
  node_linking["Document linking<br/>[service.ts]"]
  node_link_review["Link review<br/>[review-service.ts]"]
  node_tasks["Task management<br/>[service.ts]"]
  node_crm_service_layer["CRM domain services"]
  node_search_providers["Search providers<br/>[providers.ts]"]
end

subgraph group_governance["Identity and governance"]
  node_approvals["Approval subjects<br/>[subjects.ts]"]
  node_auth["Current user<br/>[current-user.ts]"]
  node_authz["Role and folder access<br/>[authz.ts]"]
  node_audit["Audit trail<br/>[audit.ts]"]
  node_events["Domain events<br/>[index.ts]"]
  node_notifications["Notifications<br/>[service.ts]"]
  node_users["User administration<br/>[users.ts]"]
  node_audit_subscriber["Audit subscriber"]
  node_notification_subscriber["Notification subscriber"]
end

subgraph group_data["Persistence and integrations"]
  node_storage["File storage<br/>[storage.ts]"]
  node_database[("Application database<br/>[prisma.ts]")]
  node_external_files[("Private file store")]
end

node_browser(("Browser user"))

node_browser -->|"uses"| node_app
node_app -->|"presents"| node_folder_ui
node_folder_ui -.->|"reads and mutates"| node_folder_service
node_folder_service -->|"reads and writes"| node_database
node_folder_ui -.->|"uploads documents"| node_document_service
node_document_service -->|"stores metadata"| node_database
node_document_service -.->|"stores file bytes"| node_storage
node_trash_service -.->|"updates deleted state"| node_database
node_document_ui -->|"requests preview"| node_content_route
node_content_route -->|"checks identity"| node_auth
node_content_route -->|"checks access"| node_authz
node_content_route -->|"loads document"| node_database
node_content_route -->|"streams file"| node_storage
node_storage -->|"reads and writes"| node_external_files
node_crm_ui -.->|"uses REST routes"| node_crm_api
node_crm_api -->|"checks identity"| node_auth
node_crm_api -->|"dispatches entities"| node_crm_registry
node_crm_registry -->|"dispatches CRUD"| node_crm_service_layer
node_crm_service_layer -.->|"persists records"| node_database
node_search_route -->|"checks identity"| node_auth
node_search_route -->|"runs query"| node_search
node_search -->|"loads candidates"| node_search_providers
node_import -->|"creates folders"| node_folder_service
node_import -->|"uploads files"| node_document_service
node_ocr -->|"reads stored files"| node_storage
node_ocr -->|"uses import service"| node_import
node_link_review -->|"resolves subjects"| node_approvals
node_link_review -->|"emits review events"| node_events
node_tasks -->|"resolves subjects"| node_approvals
node_tasks -->|"emits task events"| node_events
node_events -->|"registers subscriber"| node_audit_subscriber
node_events -->|"registers subscriber"| node_notification_subscriber
node_auth -->|"re-reads user"| node_database
node_users -.->|"manages users"| node_database
node_browser -->|"manages records"| node_crm_ui

click node_app "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/(app)/layout.tsx"
click node_folder_ui "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/explorer/folder-explorer.tsx"
click node_document_ui "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/explorer/document-preview-modal.tsx"
click node_folder_service "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/folders.ts"
click node_document_service "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/documents.ts"
click node_trash_service "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/trash.ts"
click node_content_route "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/api/documents/%5Bid%5D/content/route.ts"
click node_storage "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/storage.ts"
click node_crm_ui "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/crm/crm-manager.tsx"
click node_crm_api "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/crm/rest.ts"
click node_crm_registry "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/crm/registry.ts"
click node_search "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/search/engine.ts"
click node_import "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/import/service.ts"
click node_ocr "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/ocr/service.ts"
click node_extraction "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/extraction/service.ts"
click node_linking "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/linking/service.ts"
click node_link_review "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/linking/review-service.ts"
click node_approvals "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/approvals/subjects.ts"
click node_tasks "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/tasks/service.ts"
click node_auth "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/auth/current-user.ts"
click node_authz "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/authz.ts"
click node_audit "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/audit.ts"
click node_events "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/index.ts"
click node_notifications "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/notifications/service.ts"
click node_users "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/users.ts"
click node_search_route "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/api/search/route.ts"
click node_database "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/prisma.ts"
click node_search_providers "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/search/providers.ts"
click node_audit_subscriber "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/subscribers/audit-subscriber.ts"
click node_notification_subscriber "https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/subscribers/notification-subscriber.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_folder_ui,node_document_ui,node_crm_ui,node_search_route,node_browser toneBlue
class node_folder_service,node_document_service,node_trash_service,node_content_route,node_import,node_ocr toneAmber
class node_crm_api,node_crm_registry,node_search,node_extraction,node_linking,node_link_review,node_tasks,node_crm_service_layer,node_search_providers toneMint
class node_approvals,node_auth,node_authz,node_audit,node_events,node_notifications,node_users,node_audit_subscriber,node_notification_subscriber toneRose
class node_storage,node_database,node_external_files toneIndigo
```

## Components

### User interface

- [Authenticated app](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/(app)/layout.tsx): `src/app/(app)/layout.tsx`
- [Folder explorer](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/explorer/folder-explorer.tsx): `src/components/explorer/folder-explorer.tsx`
- [Document preview](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/explorer/document-preview-modal.tsx): `src/components/explorer/document-preview-modal.tsx`
- [CRM workspace](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/components/crm/crm-manager.tsx): `src/components/crm/crm-manager.tsx`
- [Search API](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/api/search/route.ts): `src/app/api/search/route.ts`

### Document lifecycle

- [Folder services](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/folders.ts): `src/lib/services/folders.ts`
- [Document services](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/documents.ts): `src/lib/services/documents.ts`
- [Recycle bin](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/trash.ts): `src/lib/services/trash.ts`
- [Authorized file route](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/app/api/documents/%5Bid%5D/content/route.ts): `src/app/api/documents/[id]/content/route.ts`
- [Document import](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/import/service.ts): `src/lib/import/service.ts`
- [OCR processing](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/ocr/service.ts): `src/lib/ocr/service.ts`

### Business workspace

- [CRM REST routes](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/crm/rest.ts): `src/lib/crm/rest.ts`
- [CRM entity registry](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/crm/registry.ts): `src/lib/crm/registry.ts`
- [Global search](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/search/engine.ts): `src/lib/search/engine.ts`
- [Field extraction](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/extraction/service.ts): `src/lib/extraction/service.ts`
- [Document linking](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/linking/service.ts): `src/lib/linking/service.ts`
- [Link review](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/linking/review-service.ts): `src/lib/linking/review-service.ts`
- [Task management](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/tasks/service.ts): `src/lib/tasks/service.ts`
- **CRM domain services**: service
- [Search providers](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/search/providers.ts): `src/lib/search/providers.ts`

### Identity and governance

- [Approval subjects](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/approvals/subjects.ts): `src/lib/approvals/subjects.ts`
- [Current user](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/auth/current-user.ts): `src/lib/auth/current-user.ts`
- [Role and folder access](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/authz.ts): `src/lib/authz.ts`
- [Audit trail](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/audit.ts): `src/lib/audit.ts`
- [Domain events](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/index.ts): `src/lib/events/index.ts`
- [Notifications](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/notifications/service.ts): `src/lib/notifications/service.ts`
- [User administration](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/services/users.ts): `src/lib/services/users.ts`
- [Audit subscriber](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/subscribers/audit-subscriber.ts): `src/lib/events/subscribers/audit-subscriber.ts`
- [Notification subscriber](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/events/subscribers/notification-subscriber.ts): `src/lib/events/subscribers/notification-subscriber.ts`

### Persistence and integrations

- [File storage](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/storage.ts): `src/lib/storage.ts`
- [Application database](https://github.com/kamelfcis/artilleryinternalcrm/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- **Private file store**

### Other components

- **Browser user**

## Connections

- Browser user → Authenticated app: uses (evidence: `README.md`)
- Authenticated app → Folder explorer: presents (evidence: `README.md`)
- Folder explorer → Folder services: reads and mutates
- Folder services → Application database: reads and writes (evidence: `README.md`)
- Folder explorer → Document services: uploads documents
- Document services → Application database: stores metadata (evidence: `README.md`)
- Document services → File storage: stores file bytes
- Recycle bin → Application database: updates deleted state
- Document preview → Authorized file route: requests preview (evidence: `src/components/explorer/document-preview-modal.tsx`)
- Authorized file route → Current user: checks identity (evidence: `src/app/api/documents/[id]/content/route.ts`)
- Authorized file route → Role and folder access: checks access (evidence: `src/app/api/documents/[id]/content/route.ts`)
- Authorized file route → Application database: loads document (evidence: `src/app/api/documents/[id]/content/route.ts`)
- Authorized file route → File storage: streams file (evidence: `src/app/api/documents/[id]/content/route.ts`)
- File storage → Private file store: reads and writes (evidence: `src/lib/storage.ts`)
- CRM workspace → CRM REST routes: uses REST routes
- CRM REST routes → Current user: checks identity (evidence: `src/lib/crm/rest.ts`)
- CRM REST routes → CRM entity registry: dispatches entities (evidence: `src/lib/crm/rest.ts`)
- CRM entity registry → CRM domain services: dispatches CRUD (evidence: `src/lib/crm/registry.ts`)
- CRM domain services → Application database: persists records
- Search API → Current user: checks identity (evidence: `src/app/api/search/route.ts`)
- Search API → Global search: runs query (evidence: `src/app/api/search/route.ts`)
- Global search → Search providers: loads candidates (evidence: `src/lib/search/engine.ts`)
- Document import → Folder services: creates folders (evidence: `src/lib/import/service.ts`)
- Document import → Document services: uploads files (evidence: `src/lib/import/service.ts`)
- OCR processing → File storage: reads stored files (evidence: `src/lib/ocr/service.ts`)
- OCR processing → Document import: uses import service (evidence: `src/lib/ocr/service.ts`)
- Link review → Approval subjects: resolves subjects (evidence: `src/lib/linking/review-service.ts`)
- Link review → Domain events: emits review events (evidence: `src/lib/linking/review-service.ts`)
- Task management → Approval subjects: resolves subjects (evidence: `src/lib/tasks/service.ts`)
- Task management → Domain events: emits task events (evidence: `src/lib/tasks/service.ts`)
- Domain events → Audit subscriber: registers subscriber (evidence: `src/lib/events/index.ts`)
- Domain events → Notification subscriber: registers subscriber (evidence: `src/lib/events/index.ts`)
- Current user → Application database: re-reads user (evidence: `src/lib/auth/current-user.ts`)
- User administration → Application database: manages users
- Browser user → CRM workspace: manages records (evidence: `README.md`)
