# afsozer/emsal-mcp architecture

> Architecture diagram of the GitHub repository afsozer/emsal-mcp, 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/afsozer/emsal-mcp
- Repository: https://github.com/afsozer/emsal-mcp

## Overview

Dayanak is an MCP server and CLI for citation-safe research, search, and document preparation across Turkish legal sources. The principal workflow starts with an MCP client request, dispatches through the server to live-source or local-corpus search, and returns sourced results; research can fetch documents and assemble a quality-checked bundle. Separate capabilities include legislation lookup, citation checks, drafting, privacy tools, watches, exports, and health administration. Edges reflect README-documented tool behavior and source-index references; unsampled implementation details are not inferred.

Main entry points: [`src/dayanak/server.py`](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/server.py) (MCP tool server), [`src/dayanak/sources/registry.py`](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/registry.py) (Source registry), [`src/dayanak/research.py`](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/research.py) (Topic research), [`src/dayanak/semantic.py`](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/semantic.py) (Hybrid search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Client interface"]
  node_server["MCP tool server<br/>[server.py]"]
  node_cli["CLI commands<br/>[cli.py]"]
end

subgraph group_sources["Legal sources"]
  node_registry["Source registry<br/>[registry.py]"]
  node_bedesten["Bedesten decisions<br/>[bedesten.py]"]
  node_official_law["Official legislation<br/>[mevzuatgov.py]"]
  node_law_sources["Other public sources<br/>[simple_public.py]"]
  node_legislation["Legislation tools<br/>[legislation.py]"]
end

subgraph group_corpus["Local corpus"]
  node_cache[("Document cache<br/>[cache.py]")]
  node_semantic["Hybrid search<br/>[semantic.py]"]
  node_embeddings["Embedding providers<br/>[embeddings.py]"]
  node_law_corpus[("Legislation corpus")]
  node_pdf["PDF extraction<br/>[pdf_extractor.py]"]
end

subgraph group_workflows["Research workflows"]
  node_research["Topic research<br/>[research.py]"]
  node_watch["Research watches<br/>[research_watch.py]"]
  node_draft["Petition drafting<br/>[petition.py]"]
  node_arguments["Argument building<br/>[argument.py]"]
  node_export["Document export<br/>[exporter.py]"]
end

subgraph group_assurance["Trust and operations"]
  node_safety["Citation safety<br/>[safety.py]"]
  node_privacy["Privacy controls<br/>[privacy.py]"]
  node_ops["Source health<br/>[ops_status.py]"]
end

node_client(("MCP client"))

node_client -->|"invokes tools"| node_server
node_server -->|"routes searches"| node_registry
node_registry -->|"registers adapter"| node_bedesten
node_registry -->|"registers adapter"| node_official_law
node_registry -->|"registers adapters"| node_law_sources
node_server -->|"dispatches legislation"| node_legislation
node_server -->|"dispatches local search"| node_semantic
node_semantic -->|"searches corpus"| node_cache
node_semantic -->|"uses embeddings"| node_embeddings
node_server -->|"starts research"| node_research
node_research -->|"searches sources"| node_registry
node_research -->|"reads cached documents"| node_cache
node_server -->|"dispatches watch tools"| node_watch
node_watch -->|"reruns topic research"| node_research
node_server -->|"dispatches drafting"| node_draft
node_server -->|"dispatches argument tools"| node_arguments
node_server -->|"dispatches export"| node_export
node_server -->|"dispatches privacy tools"| node_privacy
node_server -->|"dispatches health checks"| node_ops
node_draft -->|"checks safe use"| node_safety
node_server -->|"extracts legal files"| node_pdf
node_pdf -->|"reads cached documents"| node_cache
node_legislation -->|"queries local corpus"| node_law_corpus
node_cli -->|"starts server"| node_server

click node_server "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/server.py"
click node_cli "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/cli.py"
click node_registry "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/registry.py"
click node_bedesten "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/bedesten.py"
click node_official_law "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/mevzuatgov.py"
click node_law_sources "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/simple_public.py"
click node_legislation "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/legislation.py"
click node_research "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/research.py"
click node_watch "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/research_watch.py"
click node_draft "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/petition.py"
click node_arguments "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/argument.py"
click node_export "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/exporter.py"
click node_cache "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/cache.py"
click node_semantic "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/semantic.py"
click node_embeddings "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/embeddings.py"
click node_law_corpus "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/legislation_corpus.py"
click node_pdf "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/pdf_extractor.py"
click node_safety "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/safety.py"
click node_privacy "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/privacy.py"
click node_ops "https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/ops_status.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_server,node_cli,node_client toneBlue
class node_registry,node_bedesten,node_official_law,node_law_sources,node_legislation toneAmber
class node_cache,node_semantic,node_embeddings,node_law_corpus,node_pdf toneMint
class node_research,node_watch,node_draft,node_arguments,node_export toneRose
class node_safety,node_privacy,node_ops toneIndigo
```

## Components

### Client interface

- [MCP tool server](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/server.py): `src/dayanak/server.py`
- [CLI commands](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/cli.py): `src/dayanak/cli.py`

### Legal sources

- [Source registry](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/registry.py): `src/dayanak/sources/registry.py`
- [Bedesten decisions](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/bedesten.py): `src/dayanak/sources/bedesten.py`
- [Official legislation](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/mevzuatgov.py): `src/dayanak/sources/mevzuatgov.py`
- [Other public sources](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/sources/simple_public.py): `src/dayanak/sources/simple_public.py`
- [Legislation tools](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/legislation.py): `src/dayanak/legislation.py`

### Local corpus

- [Document cache](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/cache.py): `src/dayanak/cache.py`
- [Hybrid search](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/semantic.py): `src/dayanak/semantic.py`
- [Embedding providers](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/embeddings.py): `src/dayanak/embeddings.py`
- [Legislation corpus](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/legislation_corpus.py): `src/dayanak/legislation_corpus.py`
- [PDF extraction](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/pdf_extractor.py): `src/dayanak/pdf_extractor.py`

### Research workflows

- [Topic research](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/research.py): `src/dayanak/research.py`
- [Research watches](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/research_watch.py): `src/dayanak/research_watch.py`
- [Petition drafting](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/petition.py): `src/dayanak/petition.py`
- [Argument building](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/argument.py): `src/dayanak/argument.py`
- [Document export](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/exporter.py): `src/dayanak/exporter.py`

### Trust and operations

- [Citation safety](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/safety.py): `src/dayanak/safety.py`
- [Privacy controls](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/privacy.py): `src/dayanak/privacy.py`
- [Source health](https://github.com/afsozer/emsal-mcp/blob/master/src/dayanak/ops_status.py): `src/dayanak/ops_status.py`

### Other components

- **MCP client**

## Connections

- MCP client → MCP tool server: invokes tools (evidence: `README.md`)
- MCP tool server → Source registry: routes searches (evidence: `src/dayanak/server.py`)
- Source registry → Bedesten decisions: registers adapter (evidence: `src/dayanak/sources/registry.py`)
- Source registry → Official legislation: registers adapter (evidence: `src/dayanak/sources/registry.py`)
- Source registry → Other public sources: registers adapters (evidence: `src/dayanak/sources/registry.py`)
- MCP tool server → Legislation tools: dispatches legislation (evidence: `src/dayanak/server.py`)
- MCP tool server → Hybrid search: dispatches local search (evidence: `src/dayanak/server.py`)
- Hybrid search → Document cache: searches corpus (evidence: `src/dayanak/semantic.py`)
- Hybrid search → Embedding providers: uses embeddings (evidence: `src/dayanak/semantic.py`)
- MCP tool server → Topic research: starts research (evidence: `README.md`)
- Topic research → Source registry: searches sources (evidence: `src/dayanak/research.py`)
- Topic research → Document cache: reads cached documents (evidence: `src/dayanak/research.py`)
- MCP tool server → Research watches: dispatches watch tools (evidence: `README.md`)
- Research watches → Topic research: reruns topic research (evidence: `src/dayanak/research_watch.py`)
- MCP tool server → Petition drafting: dispatches drafting (evidence: `src/dayanak/server.py`)
- MCP tool server → Argument building: dispatches argument tools (evidence: `src/dayanak/server.py`)
- MCP tool server → Document export: dispatches export (evidence: `src/dayanak/server.py`)
- MCP tool server → Privacy controls: dispatches privacy tools (evidence: `README.md`)
- MCP tool server → Source health: dispatches health checks (evidence: `README.md`)
- Petition drafting → Citation safety: checks safe use (evidence: `src/dayanak/petition.py`)
- MCP tool server → PDF extraction: extracts legal files (evidence: `src/dayanak/server.py`)
- PDF extraction → Document cache: reads cached documents (evidence: `src/dayanak/pdf_extractor.py`)
- Legislation tools → Legislation corpus: queries local corpus (evidence: `src/dayanak/legislation.py`)
- CLI commands → MCP tool server: starts server (evidence: `src/dayanak/cli.py`)
