# waleedmandour/corpusmind architecture

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

- Interactive diagram: https://gitdiagram.com/waleedmandour/corpusmind
- Repository: https://github.com/waleedmandour/corpusmind

## Overview

CorpusMind is a local-first corpus-linguistics research workbench: users bring in texts, build annotated corpora, run linguistic and statistical analyses, and inspect or export results. Its main path runs from the web or desktop interface through the FastAPI engine to ingestion, NLP, persistent project data, and analysis services. Arabic processing, learner research, discourse analysis, reference-corpus comparison, AI assistance, and classroom server mode are important branches. The README places Vision in a companion repository, so it is not mapped here. Some route and UI wiring is unsampled; edges reflect only indexed imports or README-level product relationships.

Main entry points: [`engine/app/main.py`](https://github.com/waleedmandour/corpusmind/blob/main/engine/app/main.py) (Engine API), [`engine/storage/models.py`](https://github.com/waleedmandour/corpusmind/blob/main/engine/storage/models.py) (Project database), [`engine/api/analysis.py`](https://github.com/waleedmandour/corpusmind/blob/main/engine/api/analysis.py) (Analysis routes), [`engine/ingestion/service.py`](https://github.com/waleedmandour/corpusmind/blob/main/engine/ingestion/service.py) (Text ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User interfaces"]
  node_web["Web app<br/>[App.tsx]"]
  node_desktop["Desktop shell<br/>[lib.rs]"]
end

subgraph group_engine["Engine and API"]
  node_api["Engine API<br/>[main.py]"]
  node_corpus_routes["Corpus routes<br/>[corpora.py]"]
  node_database[("Project database<br/>[models.py]")]
  node_sessions["Database sessions<br/>[session.py]"]
  node_analysis_routes["Analysis routes<br/>[analysis.py]"]
  node_export["Result export<br/>[export.py]"]
  node_classroom["Classroom mode<br/>[server_mode.py]"]
end

subgraph group_analysis["Corpus analysis"]
  node_ingestion["Text ingestion<br/>[service.py]"]
  node_nlp["Language pipelines<br/>[pipeline.py]"]
  node_arabic["Arabic pipeline<br/>[pipeline.py]"]
  node_stats["Corpus statistics<br/>[service.py]"]
end

subgraph group_research["Research capabilities"]
  node_discourse["Discourse analysis<br/>[service.py]"]
  node_learner["Learner research<br/>[service.py]"]
  node_reference["Reference corpora<br/>[manager.py]"]
  node_ai["AI providers<br/>[providers.py]"]
  node_assistant["AI assistance<br/>[ai.py]"]
end

node_researcher(("Researcher"))

node_researcher -->|"uses"| node_web
node_researcher -->|"uses"| node_desktop
node_web -.->|"accesses engine"| node_api
node_desktop -.->|"runs engine"| node_api
node_api -->|"registers routes"| node_corpus_routes
node_api -->|"registers routes"| node_analysis_routes
node_corpus_routes -.->|"delegates"| node_ingestion
node_ingestion -->|"parses text"| node_nlp
node_ingestion -->|"creates records"| node_database
node_analysis_routes -->|"requests analyses"| node_stats
node_analysis_routes -->|"uses sessions"| node_sessions
node_sessions -->|"maps models"| node_database
node_api -->|"warms backend"| node_arabic
node_learner -->|"uses statistics"| node_stats
node_reference -.->|"stores metadata"| node_database
node_assistant -->|"reads corpus context"| node_database
node_assistant -.->|"uses providers"| node_ai
node_discourse -->|"uses statistics"| node_stats
node_api -->|"registers routes"| node_export
node_api -->|"enforces mode"| node_classroom

click node_web "https://github.com/waleedmandour/corpusmind/blob/main/web/src/App.tsx"
click node_desktop "https://github.com/waleedmandour/corpusmind/blob/main/desktop/src-tauri/src/lib.rs"
click node_api "https://github.com/waleedmandour/corpusmind/blob/main/engine/app/main.py"
click node_corpus_routes "https://github.com/waleedmandour/corpusmind/blob/main/engine/api/corpora.py"
click node_ingestion "https://github.com/waleedmandour/corpusmind/blob/main/engine/ingestion/service.py"
click node_nlp "https://github.com/waleedmandour/corpusmind/blob/main/engine/nlp/general/pipeline.py"
click node_arabic "https://github.com/waleedmandour/corpusmind/blob/main/engine/nlp/arabic/pipeline.py"
click node_database "https://github.com/waleedmandour/corpusmind/blob/main/engine/storage/models.py"
click node_sessions "https://github.com/waleedmandour/corpusmind/blob/main/engine/storage/session.py"
click node_analysis_routes "https://github.com/waleedmandour/corpusmind/blob/main/engine/api/analysis.py"
click node_stats "https://github.com/waleedmandour/corpusmind/blob/main/engine/stats/service.py"
click node_discourse "https://github.com/waleedmandour/corpusmind/blob/main/engine/discourse/service.py"
click node_learner "https://github.com/waleedmandour/corpusmind/blob/main/engine/learner/service.py"
click node_reference "https://github.com/waleedmandour/corpusmind/blob/main/engine/reference_corpus/manager.py"
click node_ai "https://github.com/waleedmandour/corpusmind/blob/main/engine/ai/providers.py"
click node_assistant "https://github.com/waleedmandour/corpusmind/blob/main/engine/api/ai.py"
click node_export "https://github.com/waleedmandour/corpusmind/blob/main/engine/api/export.py"
click node_classroom "https://github.com/waleedmandour/corpusmind/blob/main/engine/app/server_mode.py"

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_web,node_desktop toneBlue
class node_api,node_corpus_routes,node_database,node_sessions,node_analysis_routes,node_export,node_classroom toneAmber
class node_ingestion,node_nlp,node_arabic,node_stats toneMint
class node_discourse,node_learner,node_reference,node_ai,node_assistant toneRose
class node_researcher toneIndigo
```

## Components

### User interfaces

- [Web app](https://github.com/waleedmandour/corpusmind/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Desktop shell](https://github.com/waleedmandour/corpusmind/blob/main/desktop/src-tauri/src/lib.rs): `desktop/src-tauri/src/lib.rs`

### Engine and API

- [Engine API](https://github.com/waleedmandour/corpusmind/blob/main/engine/app/main.py): `engine/app/main.py`
- [Corpus routes](https://github.com/waleedmandour/corpusmind/blob/main/engine/api/corpora.py): `engine/api/corpora.py`
- [Project database](https://github.com/waleedmandour/corpusmind/blob/main/engine/storage/models.py): `engine/storage/models.py`
- [Database sessions](https://github.com/waleedmandour/corpusmind/blob/main/engine/storage/session.py): `engine/storage/session.py`
- [Analysis routes](https://github.com/waleedmandour/corpusmind/blob/main/engine/api/analysis.py): `engine/api/analysis.py`
- [Result export](https://github.com/waleedmandour/corpusmind/blob/main/engine/api/export.py): `engine/api/export.py`
- [Classroom mode](https://github.com/waleedmandour/corpusmind/blob/main/engine/app/server_mode.py): `engine/app/server_mode.py`

### Corpus analysis

- [Text ingestion](https://github.com/waleedmandour/corpusmind/blob/main/engine/ingestion/service.py): `engine/ingestion/service.py`
- [Language pipelines](https://github.com/waleedmandour/corpusmind/blob/main/engine/nlp/general/pipeline.py): `engine/nlp/general/pipeline.py`
- [Arabic pipeline](https://github.com/waleedmandour/corpusmind/blob/main/engine/nlp/arabic/pipeline.py): `engine/nlp/arabic/pipeline.py`
- [Corpus statistics](https://github.com/waleedmandour/corpusmind/blob/main/engine/stats/service.py): `engine/stats/service.py`

### Research capabilities

- [Discourse analysis](https://github.com/waleedmandour/corpusmind/blob/main/engine/discourse/service.py): `engine/discourse/service.py`
- [Learner research](https://github.com/waleedmandour/corpusmind/blob/main/engine/learner/service.py): `engine/learner/service.py`
- [Reference corpora](https://github.com/waleedmandour/corpusmind/blob/main/engine/reference_corpus/manager.py): `engine/reference_corpus/manager.py`
- [AI providers](https://github.com/waleedmandour/corpusmind/blob/main/engine/ai/providers.py): `engine/ai/providers.py`
- [AI assistance](https://github.com/waleedmandour/corpusmind/blob/main/engine/api/ai.py): `engine/api/ai.py`

### Other components

- **Researcher**

## Connections

- Researcher → Web app: uses
- Researcher → Desktop shell: uses
- Web app → Engine API: accesses engine
- Desktop shell → Engine API: runs engine
- Engine API → Corpus routes: registers routes (evidence: `engine/app/main.py`)
- Engine API → Analysis routes: registers routes (evidence: `engine/app/main.py`)
- Corpus routes → Text ingestion: delegates
- Text ingestion → Language pipelines: parses text (evidence: `engine/ingestion/service.py`)
- Text ingestion → Project database: creates records (evidence: `engine/ingestion/service.py`)
- Analysis routes → Corpus statistics: requests analyses (evidence: `engine/api/analysis.py`)
- Analysis routes → Database sessions: uses sessions (evidence: `engine/api/analysis.py`)
- Database sessions → Project database: maps models (evidence: `engine/storage/session.py`)
- Engine API → Arabic pipeline: warms backend (evidence: `engine/app/main.py`)
- Learner research → Corpus statistics: uses statistics (evidence: `engine/learner/service.py`)
- Reference corpora → Project database: stores metadata
- AI assistance → Project database: reads corpus context (evidence: `engine/api/ai.py`)
- AI assistance → AI providers: uses providers
- Discourse analysis → Corpus statistics: uses statistics (evidence: `engine/discourse/service.py`)
- Engine API → Result export: registers routes (evidence: `engine/app/main.py`)
- Engine API → Classroom mode: enforces mode (evidence: `engine/app/main.py`)
