# chnclsr/divan architecture

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

- Interactive diagram: https://gitdiagram.com/chnclsr/divan
- Repository: https://github.com/chnclsr/divan

## Overview

Divan is a Turkish legal-research platform that queries court and institutional decision sources and returns normalized decisions. Its documented user flow is search through MCP, REST, or CLI; fetch a decision’s full text; then read or export it. Search fans out concurrently through a client factory, while client implementations normalize source data and provide resilient, cached access. Semantic-search modules are present, but their wiring is not shown in the excerpts or README, so they are represented without inferred connections.

Main entry points: [`clients`](https://github.com/chnclsr/divan/tree/main/clients) (Court Clients), [`services/search.py`](https://github.com/chnclsr/divan/blob/main/services/search.py) (Unified Search), [`cli/app.py`](https://github.com/chnclsr/divan/blob/main/cli/app.py) (Command Line), [`api/server.py`](https://github.com/chnclsr/divan/blob/main/api/server.py) (REST API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli["Command Line<br/>[app.py]"]
  node_rest["REST API<br/>[server.py]"]
  node_mcp["MCP Server<br/>[server.py]"]
end

subgraph group_research["Legal Research"]
  node_search["Unified Search<br/>[search.py]"]
  node_documents["Document Retrieval<br/>[document.py]"]
  node_export["Decision Export<br/>[export.py]"]
end

subgraph group_sources["Court Sources"]
  node_factory["Client Factory<br/>[factory.py]"]
  node_court_clients["Court Clients"]
end

subgraph group_platform["Core and Resilience"]
  node_decision["Decision Model<br/>[models.py]"]
  node_interfaces_core["Core Contracts<br/>[interfaces.py]"]
  node_config["App Configuration<br/>[config.py]"]
  node_cache[("LRU Cache<br/>[cache.py]")]
  node_http["HTTP Client<br/>[http_client.py]"]
  node_limiter["Rate Limiter<br/>[rate_limiter.py]"]
  node_breaker["Circuit Breaker<br/>[circuit_breaker.py]"]
end

subgraph group_semantic["Semantic Search"]
  node_embedder["Embedding<br/>[embedder.py]"]
  node_expansion["Query Expansion<br/>[expansion.py]"]
  node_reranker["Result Reranking<br/>[reranker.py]"]
  node_vectors[("Vector Store<br/>[vector_store.py]")]
end

node_researcher(("Researcher / LLM"))

node_researcher -->|"searches or reads"| node_cli
node_researcher -->|"requests research"| node_rest
node_researcher -->|"invokes tools"| node_mcp
node_cli -->|"runs search"| node_search
node_rest -->|"runs search"| node_search
node_mcp -->|"runs search"| node_search
node_cli -->|"gets decision"| node_documents
node_rest -->|"gets decision"| node_documents
node_mcp -->|"gets decision"| node_documents
node_cli -->|"exports decision"| node_export
node_rest -->|"exports decision"| node_export
node_search -->|"creates clients"| node_factory
node_documents -->|"creates client"| node_factory
node_factory -->|"constructs clients"| node_court_clients
node_search -->|"merges decisions"| node_decision
node_court_clients -->|"reads and writes"| node_cache
node_court_clients -->|"makes requests"| node_http
node_court_clients -->|"uses limiter"| node_limiter
node_court_clients -->|"uses breaker"| node_breaker

click node_cli "https://github.com/chnclsr/divan/blob/main/cli/app.py"
click node_rest "https://github.com/chnclsr/divan/blob/main/api/server.py"
click node_mcp "https://github.com/chnclsr/divan/blob/main/mcp/server.py"
click node_search "https://github.com/chnclsr/divan/blob/main/services/search.py"
click node_documents "https://github.com/chnclsr/divan/blob/main/services/document.py"
click node_export "https://github.com/chnclsr/divan/blob/main/services/export.py"
click node_factory "https://github.com/chnclsr/divan/blob/main/clients/factory.py"
click node_court_clients "https://github.com/chnclsr/divan/tree/main/clients"
click node_decision "https://github.com/chnclsr/divan/blob/main/core/models.py"
click node_interfaces_core "https://github.com/chnclsr/divan/blob/main/core/interfaces.py"
click node_config "https://github.com/chnclsr/divan/blob/main/config.py"
click node_cache "https://github.com/chnclsr/divan/blob/main/infrastructure/cache.py"
click node_http "https://github.com/chnclsr/divan/blob/main/infrastructure/http_client.py"
click node_limiter "https://github.com/chnclsr/divan/blob/main/infrastructure/rate_limiter.py"
click node_breaker "https://github.com/chnclsr/divan/blob/main/infrastructure/circuit_breaker.py"
click node_embedder "https://github.com/chnclsr/divan/blob/main/services/semantic/embedder.py"
click node_expansion "https://github.com/chnclsr/divan/blob/main/services/semantic/expansion.py"
click node_reranker "https://github.com/chnclsr/divan/blob/main/services/semantic/reranker.py"
click node_vectors "https://github.com/chnclsr/divan/blob/main/services/semantic/vector_store.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_cli,node_rest,node_mcp toneBlue
class node_search,node_documents,node_export toneAmber
class node_factory,node_court_clients toneMint
class node_decision,node_interfaces_core,node_config,node_cache,node_http,node_limiter,node_breaker toneRose
class node_embedder,node_expansion,node_reranker,node_vectors,node_researcher toneIndigo
```

## Components

### User Interfaces

- [Command Line](https://github.com/chnclsr/divan/blob/main/cli/app.py): `cli/app.py`
- [REST API](https://github.com/chnclsr/divan/blob/main/api/server.py): `api/server.py`
- [MCP Server](https://github.com/chnclsr/divan/blob/main/mcp/server.py): `mcp/server.py`

### Legal Research

- [Unified Search](https://github.com/chnclsr/divan/blob/main/services/search.py): `services/search.py`
- [Document Retrieval](https://github.com/chnclsr/divan/blob/main/services/document.py): `services/document.py`
- [Decision Export](https://github.com/chnclsr/divan/blob/main/services/export.py): `services/export.py`

### Court Sources

- [Client Factory](https://github.com/chnclsr/divan/blob/main/clients/factory.py): `clients/factory.py`
- [Court Clients](https://github.com/chnclsr/divan/tree/main/clients): `clients`

### Core and Resilience

- [Decision Model](https://github.com/chnclsr/divan/blob/main/core/models.py): `core/models.py`
- [Core Contracts](https://github.com/chnclsr/divan/blob/main/core/interfaces.py): `core/interfaces.py`
- [App Configuration](https://github.com/chnclsr/divan/blob/main/config.py): `config.py`
- [LRU Cache](https://github.com/chnclsr/divan/blob/main/infrastructure/cache.py): `infrastructure/cache.py`
- [HTTP Client](https://github.com/chnclsr/divan/blob/main/infrastructure/http_client.py): `infrastructure/http_client.py`
- [Rate Limiter](https://github.com/chnclsr/divan/blob/main/infrastructure/rate_limiter.py): `infrastructure/rate_limiter.py`
- [Circuit Breaker](https://github.com/chnclsr/divan/blob/main/infrastructure/circuit_breaker.py): `infrastructure/circuit_breaker.py`

### Semantic Search

- [Embedding](https://github.com/chnclsr/divan/blob/main/services/semantic/embedder.py): `services/semantic/embedder.py`
- [Query Expansion](https://github.com/chnclsr/divan/blob/main/services/semantic/expansion.py): `services/semantic/expansion.py`
- [Result Reranking](https://github.com/chnclsr/divan/blob/main/services/semantic/reranker.py): `services/semantic/reranker.py`
- [Vector Store](https://github.com/chnclsr/divan/blob/main/services/semantic/vector_store.py): `services/semantic/vector_store.py`

### Other components

- **Researcher / LLM**

## Connections

- Researcher / LLM → Command Line: searches or reads (evidence: `README.md`)
- Researcher / LLM → REST API: requests research (evidence: `README.md`)
- Researcher / LLM → MCP Server: invokes tools (evidence: `README.md`)
- Command Line → Unified Search: runs search (evidence: `cli/app.py`)
- REST API → Unified Search: runs search (evidence: `api/server.py`)
- MCP Server → Unified Search: runs search (evidence: `mcp/server.py`)
- Command Line → Document Retrieval: gets decision (evidence: `cli/app.py`)
- REST API → Document Retrieval: gets decision (evidence: `api/server.py`)
- MCP Server → Document Retrieval: gets decision (evidence: `mcp/server.py`)
- Command Line → Decision Export: exports decision (evidence: `cli/app.py`)
- REST API → Decision Export: exports decision (evidence: `api/server.py`)
- Unified Search → Client Factory: creates clients (evidence: `services/search.py`)
- Document Retrieval → Client Factory: creates client (evidence: `services/document.py`)
- Client Factory → Court Clients: constructs clients (evidence: `clients/factory.py`)
- Unified Search → Decision Model: merges decisions (evidence: `services/search.py`)
- Court Clients → LRU Cache: reads and writes (evidence: `clients/base.py`)
- Court Clients → HTTP Client: makes requests (evidence: `clients/base.py`)
- Court Clients → Rate Limiter: uses limiter (evidence: `clients/base.py`)
- Court Clients → Circuit Breaker: uses breaker (evidence: `clients/base.py`)
