# afsozer/doktor-mcp architecture

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

## Overview

Doktor MCP turns a clinician’s question into a source-grounded legal information pack, not a categorical legal opinion. The MCP tools accept requests and delegate pack preparation to the application service, which classifies the question, searches legislation and court decisions, filters and composes evidence, and returns a structured response with provenance and warnings. Major documented capabilities include live official legislation, multiple precedent-source adapters, health-law query expansion, and pack drill-down. The graph follows documented and indexed calls; some unsampled subsystems are represented at their directory path, and their internal links are omitted where evidence is unavailable.

Main entry points: [`src/app/precedentPhase.ts`](https://github.com/afsozer/doktor-mcp/blob/master/src/app/precedentPhase.ts) (Precedent phase), [`src/app/service.ts`](https://github.com/afsozer/doktor-mcp/blob/master/src/app/service.ts) (Pack service), [`src/sources/yargitay/liveYargitayAdapter.ts`](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/yargitay/liveYargitayAdapter.ts) (Yargıtay adapter), [`src/mcp/tools.ts`](https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/tools.ts) (MCP tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["MCP interface"]
  node_mcp_server["MCP server<br/>[server.ts]"]
  node_mcp_tools["MCP tools<br/>[tools.ts]"]
  node_response_format["Response formatting"]
end

subgraph group_workflow["Pack workflow"]
  node_service["Pack service<br/>[service.ts]"]
  node_classification["Question classification"]
  node_legislation_phase["Legislation phase"]
  node_precedent_phase["Precedent phase<br/>[precedentPhase.ts]"]
  node_answer_composer["Pack composition<br/>[answerComposer.ts]"]
  node_pack_contract["Legal pack contract<br/>[legal.ts]"]
  node_pack_cache[("Pack session cache")]
end

subgraph group_research["Legal research"]
  node_medical_router["Medical issue routing"]
  node_legislation_inventory["Health law inventory"]
  node_query_expansion["Query expansion"]
  node_precedent_relevance["Precedent relevance"]
  node_decision_filter["Decision eligibility<br/>[precedentFilter.ts]"]
  node_decision_provenance["Decision provenance"]
end

subgraph group_sources["Source adapters"]
  node_official_legislation["Official legislation"]
  node_yargitay_adapter["Yargıtay adapter"]
  node_danistay_adapter["Danıştay adapter"]
  node_bedesten_adapter["Bedesten adapter"]
  node_aym_adapter["AYM adapter<br/>[liveAymAdapter.ts]"]
  node_precedent_cache[("Precedent cache<br/>[precedentCache.ts]")]
end

subgraph group_runtime["Runtime support"]
  node_http_client["HTTP client<br/>[httpClient.ts]"]
  node_request_policy["Request policy<br/>[requestPolicy.ts]"]
  node_rate_limiter["Rate limiter<br/>[rateLimiter.ts]"]
end

node_clinician(("Clinician"))
node_official_site{{"Official legislation service"}}
node_bedesten_service{{"Bedesten service"}}
node_danistay_site{{"Danıştay service"}}

node_clinician -->|"requests pack"| node_mcp_server
node_mcp_server -->|"registers tools"| node_mcp_tools
node_mcp_tools -->|"delegates requests"| node_service
node_service -->|"classifies question"| node_classification
node_service -->|"runs phase"| node_legislation_phase
node_service -->|"runs phase"| node_precedent_phase
node_service -.->|"composes pack"| node_answer_composer
node_service -->|"stores pack"| node_pack_cache
node_mcp_tools -->|"retrieves pack"| node_pack_cache
node_mcp_tools -->|"formats response"| node_response_format
node_response_format -->|"formats contract"| node_pack_contract
node_answer_composer -->|"builds pack"| node_pack_contract
node_legislation_phase -->|"uses mappings"| node_legislation_inventory
node_legislation_phase -->|"routes issue"| node_medical_router
node_precedent_phase -->|"expands queries"| node_query_expansion
node_precedent_phase -->|"filters decisions"| node_decision_filter
node_precedent_phase -->|"ranks relevance"| node_precedent_relevance
node_query_expansion -->|"suggests queries"| node_precedent_relevance
node_official_legislation -->|"searches and retrieves"| node_official_site
node_legislation_phase -.->|"queries source"| node_official_legislation
node_precedent_phase -->|"queries source"| node_yargitay_adapter
node_precedent_phase -->|"queries source"| node_danistay_adapter
node_precedent_phase -->|"queries source"| node_bedesten_adapter
node_precedent_phase -.->|"queries source"| node_aym_adapter
node_yargitay_adapter -->|"searches and fetches"| node_bedesten_service
node_bedesten_adapter -->|"searches documents"| node_bedesten_service
node_danistay_adapter -->|"searches decisions"| node_danistay_site
node_yargitay_adapter -->|"derives provenance"| node_decision_provenance
node_danistay_adapter -->|"derives provenance"| node_decision_provenance
node_yargitay_adapter -->|"caches results"| node_precedent_cache
node_danistay_adapter -->|"caches results"| node_precedent_cache
node_yargitay_adapter -->|"sends requests"| node_http_client
node_bedesten_adapter -->|"sends requests"| node_http_client
node_http_client -->|"uses timeout policy"| node_request_policy
node_http_client -->|"uses limiter"| node_rate_limiter

click node_mcp_server "https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/server.ts"
click node_mcp_tools "https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/tools.ts"
click node_response_format "https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/formatDoctorPackResponse.ts"
click node_service "https://github.com/afsozer/doktor-mcp/blob/master/src/app/service.ts"
click node_classification "https://github.com/afsozer/doktor-mcp/blob/master/src/health/questionClassifier.ts"
click node_legislation_phase "https://github.com/afsozer/doktor-mcp/blob/master/src/app/legislationPhase.ts"
click node_precedent_phase "https://github.com/afsozer/doktor-mcp/blob/master/src/app/precedentPhase.ts"
click node_answer_composer "https://github.com/afsozer/doktor-mcp/blob/master/src/health/answerComposer.ts"
click node_pack_contract "https://github.com/afsozer/doktor-mcp/blob/master/src/contracts/legal.ts"
click node_pack_cache "https://github.com/afsozer/doktor-mcp/blob/master/src/app/packSessionCache.ts"
click node_medical_router "https://github.com/afsozer/doktor-mcp/blob/master/src/medicalIssueRouter.ts"
click node_legislation_inventory "https://github.com/afsozer/doktor-mcp/blob/master/src/healthLegislationInventory.ts"
click node_query_expansion "https://github.com/afsozer/doktor-mcp/blob/master/src/health/healthLawQueryExpansion.ts"
click node_precedent_relevance "https://github.com/afsozer/doktor-mcp/blob/master/src/health/precedentRelevance.ts"
click node_decision_filter "https://github.com/afsozer/doktor-mcp/blob/master/src/health/precedentFilter.ts"
click node_decision_provenance "https://github.com/afsozer/doktor-mcp/blob/master/src/live/decisionProvenance.ts"
click node_official_legislation "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/legislation/liveOfficialLegislationAdapter.ts"
click node_yargitay_adapter "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/yargitay/liveYargitayAdapter.ts"
click node_danistay_adapter "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/danistay/liveDanistayAdapter.ts"
click node_bedesten_adapter "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/bedesten/liveBedestenAdapter.ts"
click node_aym_adapter "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/aym/liveAymAdapter.ts"
click node_precedent_cache "https://github.com/afsozer/doktor-mcp/blob/master/src/sources/precedentCache.ts"
click node_http_client "https://github.com/afsozer/doktor-mcp/blob/master/src/core/httpClient.ts"
click node_request_policy "https://github.com/afsozer/doktor-mcp/blob/master/src/live/requestPolicy.ts"
click node_rate_limiter "https://github.com/afsozer/doktor-mcp/blob/master/src/core/rateLimiter.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_mcp_server,node_mcp_tools,node_response_format toneBlue
class node_service,node_classification,node_legislation_phase,node_precedent_phase,node_answer_composer,node_pack_contract,node_pack_cache toneAmber
class node_medical_router,node_legislation_inventory,node_query_expansion,node_precedent_relevance,node_decision_filter,node_decision_provenance toneMint
class node_official_legislation,node_yargitay_adapter,node_danistay_adapter,node_bedesten_adapter,node_aym_adapter,node_precedent_cache toneRose
class node_http_client,node_request_policy,node_rate_limiter,node_clinician,node_official_site,node_bedesten_service,node_danistay_site toneIndigo
```

## Components

### MCP interface

- [MCP server](https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/server.ts): `src/mcp/server.ts`
- [MCP tools](https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/tools.ts): `src/mcp/tools.ts`
- [Response formatting](https://github.com/afsozer/doktor-mcp/blob/master/src/mcp/formatDoctorPackResponse.ts): `src/mcp/formatDoctorPackResponse.ts`

### Pack workflow

- [Pack service](https://github.com/afsozer/doktor-mcp/blob/master/src/app/service.ts): `src/app/service.ts`
- [Question classification](https://github.com/afsozer/doktor-mcp/blob/master/src/health/questionClassifier.ts): `src/health/questionClassifier.ts`
- [Legislation phase](https://github.com/afsozer/doktor-mcp/blob/master/src/app/legislationPhase.ts): `src/app/legislationPhase.ts`
- [Precedent phase](https://github.com/afsozer/doktor-mcp/blob/master/src/app/precedentPhase.ts): `src/app/precedentPhase.ts`
- [Pack composition](https://github.com/afsozer/doktor-mcp/blob/master/src/health/answerComposer.ts): `src/health/answerComposer.ts`
- [Legal pack contract](https://github.com/afsozer/doktor-mcp/blob/master/src/contracts/legal.ts): `src/contracts/legal.ts`
- [Pack session cache](https://github.com/afsozer/doktor-mcp/blob/master/src/app/packSessionCache.ts): `src/app/packSessionCache.ts`

### Legal research

- [Medical issue routing](https://github.com/afsozer/doktor-mcp/blob/master/src/medicalIssueRouter.ts): `src/medicalIssueRouter.ts`
- [Health law inventory](https://github.com/afsozer/doktor-mcp/blob/master/src/healthLegislationInventory.ts): `src/healthLegislationInventory.ts`
- [Query expansion](https://github.com/afsozer/doktor-mcp/blob/master/src/health/healthLawQueryExpansion.ts): `src/health/healthLawQueryExpansion.ts`
- [Precedent relevance](https://github.com/afsozer/doktor-mcp/blob/master/src/health/precedentRelevance.ts): `src/health/precedentRelevance.ts`
- [Decision eligibility](https://github.com/afsozer/doktor-mcp/blob/master/src/health/precedentFilter.ts): `src/health/precedentFilter.ts`
- [Decision provenance](https://github.com/afsozer/doktor-mcp/blob/master/src/live/decisionProvenance.ts): `src/live/decisionProvenance.ts`

### Source adapters

- [Official legislation](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/legislation/liveOfficialLegislationAdapter.ts): `src/sources/legislation/liveOfficialLegislationAdapter.ts`
- [Yargıtay adapter](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/yargitay/liveYargitayAdapter.ts): `src/sources/yargitay/liveYargitayAdapter.ts`
- [Danıştay adapter](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/danistay/liveDanistayAdapter.ts): `src/sources/danistay/liveDanistayAdapter.ts`
- [Bedesten adapter](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/bedesten/liveBedestenAdapter.ts): `src/sources/bedesten/liveBedestenAdapter.ts`
- [AYM adapter](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/aym/liveAymAdapter.ts): `src/sources/aym/liveAymAdapter.ts`
- [Precedent cache](https://github.com/afsozer/doktor-mcp/blob/master/src/sources/precedentCache.ts): `src/sources/precedentCache.ts`

### Runtime support

- [HTTP client](https://github.com/afsozer/doktor-mcp/blob/master/src/core/httpClient.ts): `src/core/httpClient.ts`
- [Request policy](https://github.com/afsozer/doktor-mcp/blob/master/src/live/requestPolicy.ts): `src/live/requestPolicy.ts`
- [Rate limiter](https://github.com/afsozer/doktor-mcp/blob/master/src/core/rateLimiter.ts): `src/core/rateLimiter.ts`

### Other components

- **Clinician**
- **Official legislation service**
- **Bedesten service**
- **Danıştay service**

## Connections

- Clinician → MCP server: requests pack (evidence: `README.md`)
- MCP server → MCP tools: registers tools (evidence: `src/mcp/server.ts`)
- MCP tools → Pack service: delegates requests (evidence: `src/mcp/tools.ts`)
- Pack service → Question classification: classifies question (evidence: `src/app/service.ts`)
- Pack service → Legislation phase: runs phase (evidence: `src/app/service.ts`)
- Pack service → Precedent phase: runs phase (evidence: `src/app/service.ts`)
- Pack service → Pack composition: composes pack (evidence: `src/app/service.ts`)
- Pack service → Pack session cache: stores pack (evidence: `src/mcp/tools.ts`)
- MCP tools → Pack session cache: retrieves pack (evidence: `src/mcp/tools.ts`)
- MCP tools → Response formatting: formats response (evidence: `src/mcp/tools.ts`)
- Response formatting → Legal pack contract: formats contract (evidence: `src/mcp/formatDoctorPackResponse.ts`)
- Pack composition → Legal pack contract: builds pack (evidence: `README.md`)
- Legislation phase → Health law inventory: uses mappings (evidence: `src/app/legislationPhase.ts`)
- Legislation phase → Medical issue routing: routes issue (evidence: `src/app/legislationPhase.ts`)
- Precedent phase → Query expansion: expands queries (evidence: `src/app/precedentPhase.ts`)
- Precedent phase → Decision eligibility: filters decisions (evidence: `src/app/precedentPhase.ts`)
- Precedent phase → Precedent relevance: ranks relevance (evidence: `src/app/precedentPhase.ts`)
- Query expansion → Precedent relevance: suggests queries (evidence: `src/health/healthLawQueryExpansion.ts`)
- Official legislation → Official legislation service: searches and retrieves (evidence: `README.md`)
- Legislation phase → Official legislation: queries source
- Precedent phase → Yargıtay adapter: queries source (evidence: `src/app/precedentPhase.ts`)
- Precedent phase → Danıştay adapter: queries source (evidence: `src/app/precedentPhase.ts`)
- Precedent phase → Bedesten adapter: queries source (evidence: `src/app/precedentPhase.ts`)
- Precedent phase → AYM adapter: queries source
- Yargıtay adapter → Bedesten service: searches and fetches (evidence: `src/sources/yargitay/liveYargitayAdapter.ts`)
- Bedesten adapter → Bedesten service: searches documents (evidence: `src/sources/bedesten/liveBedestenAdapter.ts`)
- Danıştay adapter → Danıştay service: searches decisions (evidence: `src/sources/danistay/liveDanistayAdapter.ts`)
- Yargıtay adapter → Decision provenance: derives provenance (evidence: `src/sources/yargitay/liveYargitayAdapter.ts`)
- Danıştay adapter → Decision provenance: derives provenance (evidence: `src/sources/danistay/liveDanistayAdapter.ts`)
- Yargıtay adapter → Precedent cache: caches results (evidence: `src/sources/yargitay/liveYargitayAdapter.ts`)
- Danıştay adapter → Precedent cache: caches results (evidence: `src/sources/danistay/liveDanistayAdapter.ts`)
- Yargıtay adapter → HTTP client: sends requests (evidence: `src/sources/yargitay/liveYargitayAdapter.ts`)
- Bedesten adapter → HTTP client: sends requests (evidence: `src/sources/bedesten/liveBedestenAdapter.ts`)
- HTTP client → Request policy: uses timeout policy (evidence: `src/core/httpClient.ts`)
- HTTP client → Rate limiter: uses limiter (evidence: `src/core/httpClient.ts`)
