# ahmetaliunaall-prog/turk-hukuk-ai-mcp architecture

> Architecture diagram of the GitHub repository ahmetaliunaall-prog/turk-hukuk-ai-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/ahmetaliunaall-prog/turk-hukuk-ai-mcp
- Repository: https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp

## Overview

Türk Hukuk AI MCP turns a user’s case description into a privacy-masked legal research plan, searches case law and legislation through MCP tools, verifies source text, and presents cited research or a petition draft. The local web bridge handles access checks and research requests; the frontend also supports access-key entry and administrator key management. The graph follows documented workflows and excerpted imports/calls; vendor clients and some frontend-to-service wiring are described in the README rather than shown in source excerpts.

Main entry points: [`legal_mcp/orchestrator.py`](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/orchestrator.py) (Research orchestrator), [`local_ai/web.py`](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/local_ai/web.py) (Local web bridge), [`supabase/functions/thaimcp-access/index.ts`](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/supabase/functions/thaimcp-access/index.ts) (Access Edge Function), [`legal_mcp/planning.py`](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/planning.py) (Query planning)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_frontend["Research interface<br/>[app.js]"]
  node_admin_ui["Admin panel<br/>[admin.js]"]
end

subgraph group_local["Local research service"]
  node_local_web["Local web bridge<br/>[web.py]"]
  node_access_keys["Local access checks<br/>[access.py]"]
end

subgraph group_research["Research pipeline"]
  node_orchestrator["Research orchestrator<br/>[orchestrator.py]"]
  node_privacy["Privacy masking<br/>[privacy.py]"]
  node_planning["Query planning<br/>[planning.py]"]
  node_ollama["Local Qwen<br/>[ollama.py]"]
  node_evidence["Evidence ranking<br/>[evidence.py]"]
  node_cache["Source cache<br/>[cache.py]"]
end

subgraph group_sources["Legal source access"]
  node_mcp_client["MCP client<br/>[client.py]"]
  node_mcp_server["MCP server<br/>[server.py]"]
  node_adapters["Source adapters<br/>[adapters.py]"]
  node_transport["HTTP transport<br/>[transport.py]"]
end

subgraph group_access["Access management"]
  node_supabase_fn["Access Edge Function<br/>[index.ts]"]
  node_access_db[("Access database")]
end

node_researcher(("Researcher"))
node_admin(("Administrator"))
node_official_sources["Official legal sources"]
node_supabase["Supabase service"]

node_researcher -->|"submits research"| node_frontend
node_frontend -->|"sends request"| node_local_web
node_local_web -->|"validates key"| node_access_keys
node_local_web -->|"runs research"| node_orchestrator
node_local_web -->|"checks readiness"| node_ollama
node_admin -->|"manages keys"| node_admin_ui
node_admin_ui -->|"admin actions"| node_supabase_fn
node_access_keys -->|"verifies or consumes"| node_supabase_fn
node_supabase_fn -->|"reads and updates"| node_access_db
node_supabase_fn -->|"uses service role"| node_supabase
node_orchestrator -->|"masks and filters"| node_privacy
node_orchestrator -->|"builds queries"| node_planning
node_orchestrator -->|"requests analysis"| node_ollama
node_orchestrator -->|"calls tools"| node_mcp_client
node_orchestrator -->|"uses cache"| node_cache
node_orchestrator -->|"ranks and verifies"| node_evidence
node_planning -->|"uses plan types"| node_ollama
node_ollama -->|"uses fallback terms"| node_planning
node_evidence -->|"uses matching"| node_planning
node_mcp_client -->|"starts session"| node_mcp_server
node_mcp_server -->|"registers tools"| node_adapters
node_mcp_server -->|"configures lifespan"| node_transport
node_adapters -->|"uses pooled clients"| node_transport
node_adapters -->|"searches and fetches"| node_official_sources
node_evidence -->|"returns cited results"| node_frontend

click node_frontend "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/frontend/app.js"
click node_admin_ui "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/frontend/admin.js"
click node_local_web "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/local_ai/web.py"
click node_access_keys "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/access.py"
click node_orchestrator "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/orchestrator.py"
click node_privacy "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/privacy.py"
click node_planning "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/planning.py"
click node_ollama "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/local_ai/ollama.py"
click node_evidence "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/evidence.py"
click node_cache "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/cache.py"
click node_mcp_client "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/client.py"
click node_mcp_server "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/server.py"
click node_adapters "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/adapters.py"
click node_transport "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/transport.py"
click node_supabase_fn "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/supabase/functions/thaimcp-access/index.ts"
click node_access_db "https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/supabase/migrations/202609280001_thaimcp_access.sql"

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_frontend,node_admin_ui toneBlue
class node_local_web,node_access_keys toneAmber
class node_orchestrator,node_privacy,node_planning,node_ollama,node_evidence,node_cache toneMint
class node_mcp_client,node_mcp_server,node_adapters,node_transport toneRose
class node_supabase_fn,node_access_db,node_researcher,node_admin,node_official_sources,node_supabase toneIndigo
```

## Components

### User interface

- [Research interface](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/frontend/app.js): `frontend/app.js`
- [Admin panel](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/frontend/admin.js): `frontend/admin.js`

### Local research service

- [Local web bridge](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/local_ai/web.py): `local_ai/web.py`
- [Local access checks](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/access.py): `legal_mcp/access.py`

### Research pipeline

- [Research orchestrator](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/orchestrator.py): `legal_mcp/orchestrator.py`
- [Privacy masking](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/privacy.py): `legal_mcp/privacy.py`
- [Query planning](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/planning.py): `legal_mcp/planning.py`
- [Local Qwen](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/local_ai/ollama.py): `local_ai/ollama.py`
- [Evidence ranking](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/evidence.py): `legal_mcp/evidence.py`
- [Source cache](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/cache.py): `legal_mcp/cache.py`

### Legal source access

- [MCP client](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/client.py): `legal_mcp/client.py`
- [MCP server](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/server.py): `legal_mcp/server.py`
- [Source adapters](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/adapters.py): `legal_mcp/adapters.py`
- [HTTP transport](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/legal_mcp/transport.py): `legal_mcp/transport.py`

### Access management

- [Access Edge Function](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/supabase/functions/thaimcp-access/index.ts): `supabase/functions/thaimcp-access/index.ts`
- [Access database](https://github.com/ahmetaliunaall-prog/turk-hukuk-ai-mcp/blob/main/supabase/migrations/202609280001_thaimcp_access.sql): `supabase/migrations/202609280001_thaimcp_access.sql`

### Other components

- **Researcher**
- **Administrator**
- **Official legal sources**
- **Supabase service**

## Connections

- Researcher → Research interface: submits research (evidence: `README.md`)
- Research interface → Local web bridge: sends request (evidence: `README.md`)
- Local web bridge → Local access checks: validates key (evidence: `local_ai/web.py`)
- Local web bridge → Research orchestrator: runs research (evidence: `local_ai/web.py`)
- Local web bridge → Local Qwen: checks readiness (evidence: `local_ai/web.py`)
- Administrator → Admin panel: manages keys (evidence: `README.md`)
- Admin panel → Access Edge Function: admin actions (evidence: `README.md`)
- Local access checks → Access Edge Function: verifies or consumes (evidence: `legal_mcp/access.py`)
- Access Edge Function → Access database: reads and updates (evidence: `README.md`)
- Access Edge Function → Supabase service: uses service role (evidence: `README.md`)
- Research orchestrator → Privacy masking: masks and filters (evidence: `legal_mcp/orchestrator.py`)
- Research orchestrator → Query planning: builds queries (evidence: `legal_mcp/orchestrator.py`)
- Research orchestrator → Local Qwen: requests analysis (evidence: `legal_mcp/orchestrator.py`)
- Research orchestrator → MCP client: calls tools (evidence: `legal_mcp/orchestrator.py`)
- Research orchestrator → Source cache: uses cache (evidence: `legal_mcp/orchestrator.py`)
- Research orchestrator → Evidence ranking: ranks and verifies (evidence: `legal_mcp/orchestrator.py`)
- Query planning → Local Qwen: uses plan types (evidence: `legal_mcp/planning.py`)
- Local Qwen → Query planning: uses fallback terms (evidence: `local_ai/ollama.py`)
- Evidence ranking → Query planning: uses matching (evidence: `legal_mcp/evidence.py`)
- MCP client → MCP server: starts session (evidence: `legal_mcp/client.py`)
- MCP server → Source adapters: registers tools (evidence: `legal_mcp/server.py`)
- MCP server → HTTP transport: configures lifespan (evidence: `legal_mcp/server.py`)
- Source adapters → HTTP transport: uses pooled clients (evidence: `legal_mcp/adapters.py`)
- Source adapters → Official legal sources: searches and fetches (evidence: `legal_mcp/adapters.py`)
- Evidence ranking → Research interface: returns cited results (evidence: `README.md`)
