> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/contents/5f559fac.md).

# Hub-Based Architecture: MCP, JSON-RPC ile Merkezi Sistem

[r/ClaudeCode](https://reddit.com/r/ClaudeCode/comments/1osfxb1/im_building_a_hubbased_architecture_with/) • [r/ClaudeAI](https://reddit.com/r/ClaudeAI/comments/1osfy23/im_building_a_hubbased_architecture_with/) • [r/ExperiencedDevs](https://reddit.com/r/ExperiencedDevs/comments/1osgg8b/im_building_a_hubbased_architecture_with/) • [r/backend](https://reddit.com/r/Backend/comments/1osggbe/im_building_a_hubbased_architecture_with/) • [r/softwarearchitecture](https://reddit.com/r/softwarearchitecture/comments/1osggf5/im_building_a_hubbased_architecture_with/)

MCP, JSON-RPC, WebSocket ve HTTP protokolleriyle merkezi hub üzerinden her şeyin birbiriyle iletişim kurduğu bir sistem kuruyorum. Şu an %80 oranında tamamlandı, gerekirse mimariyi ayarlayacağım. Hedef: keşif ve fikirleri modelleme.

Bildiklerim: MCP, JSON-RPC, n8n, VSCode/Claude Code settings.json gibi YAML konfigürasyonları Claude Code hook sistemi

Değerlerim: Initial ∞ OK, Operational → 0

1. Compile > Runtime (+500 LOC types → 0 runtime error)
2. Centralized > Distributed (+Hub → 1 terminal)
3. Auto > Manual (+PM2 → 0 restart action)
4. Linkage > Search (+ts-morph → 0 find-replace)
5. Introspection > Docs (+API → 0 outdated)
6. Single > Multiple (+Router → 0 cognitive)

Hangi teknolojileri veya anahtar kelimeleri bilmem gerekir? Finansal olarak özgürüm, yani ücretsiz olmak zorunda değil ama ROI yüksek olsun lütfen.

## Architecture Flow

```sh
FINAL ARCHITECTURE

  ┌──────────────────────────────────────────────────────────┐
  │ CLIENTS (Send requests to Hub)                           │
  ├──────────────────────────────────────────────────────────┤
  │ clients/telegram/yemreak/     → Voice, text, commands    │
  │ clients/hammerspoon/          → macOS automation         │
  │ clients/cli/                  → gitc, stt, fetch         │
  │ clients/vscode/               → Extensions               │
  └──────────────────────────────────────────────────────────┘
                          ↓ HTTP :8772 (JSON-RPC)
  ┌──────────────────────────────────────────────────────────┐
  │ HUB (Central Router)                                     │
  ├──────────────────────────────────────────────────────────┤
  │ hub/server.ts                 → Request router           │
  │ hub/ports/registry.ts         → Port discovery           │
  └──────────────────────────────────────────────────────────┘
                          ↓ registry.call()
  ┌──────────────────────────────────────────────────────────┐
  │ LAYERS (Receive from Hub, proxy to external services)    │
  ├──────────────────────────────────────────────────────────┤
  │ layers/api/           → Raw API clients                  │
  │ ├─ whisper.ts         → :8770 WebSocket                  │
  │ ├─ macos.ts           → :8766 HTTP                       │
  │ ├─ chrome.ts          → Chrome DevTools WebSocket        │
  │ └─ yemreak.ts         → Telegram bot API                 │
  │                                                          │
  │ layers/protocol/      → JSON-RPC wrappers                │
  │ ├─ whisper.ts                                            │
  │ ├─ macos.ts                                              │
  │ ├─ chrome.ts                                             │
  │ └─ yemreak.ts                                            │
  │                                                          │
  │ layers/hub/           → Hub adapters (PortAdapter)       │
  │ ├─ whisper.ts                                            │
  │ ├─ macos.ts                                              │
  │ ├─ chrome.ts                                             │
  │ └─ yemreak.ts                                            │
  └──────────────────────────────────────────────────────────┘
                          ↓ import
  ┌──────────────────────────────────────────────────────────┐
  │ FLOWS (Orchestration)                                    │
  ├──────────────────────────────────────────────────────────┤
  │ flows/transcribe.ts           → whisper + DB save        │
  │ flows/media-extract.ts        → download + compress      │
  └──────────────────────────────────────────────────────────┘
                          ↓ import
  ┌──────────────────────────────────────────────────────────┐
  │ CORE (Pure business logic)                               │
  ├──────────────────────────────────────────────────────────┤
  │ core/trading/price.ts     → Price calculations           │
  │ core/llm/compress.ts          → Text processing          │
  │ core/analytics/infer-tags.ts  → Tag inference            │
  └──────────────────────────────────────────────────────────┘
                          ↓ import
  ┌──────────────────────────────────────────────────────────┐
  │ INFRA (Database, cache, credentials)                     │
  ├──────────────────────────────────────────────────────────┤
  │ infra/database/               → Supabase clients         │
  │ infra/cache.ts                → Redis wrapper            │
  │ infra/credentials.ts          → Env management           │
  └──────────────────────────────────────────────────────────┘

  PROJECT STRUCTURE

  src/
  ├─ clients/
  │  ├─ telegram/
  │  │  ├─ yemreak/
  │  │  │  ├─ handlers/
  │  │  │  │  ├─ message.text.ts
  │  │  │  │  ├─ message.voice.ts
  │  │  │  │  └─ command.agent.ts
  │  │  │  ├─ client.ts          # Hub client instance
  │  │  │  ├─ bot.ts             # PM2 entry
  │  │  │  └─ config.ts
  │  │  └─ (ytrader separate if needed)
  │  │
  │  ├─ hammerspoon/
  │  │  ├─ modules/
  │  │  │  ├─ dictation.lua
  │  │  │  └─ activity-tracker.lua
  │  │  ├─ client.lua            # jsonrpc.lua
  │  │  └─ init.lua
  │  │
  │  ├─ cli/
  │  │  ├─ commands/
  │  │  │  ├─ gitc.ts
  │  │  │  ├─ stt.ts
  │  │  │  └─ fetch.ts
  │  │  └─ client.ts
  │  │
  │  └─ vscode/
  │     ├─ bridge/
  │     ├─ commands/
  │     └─ theme/
  │
  ├─ hub/
  │  ├─ server.ts                # HTTP :8772
  │  ├─ types.ts                 # JSON-RPC types
  │  ├─ ports/
  │  │  └─ registry.ts
  │  └─ tests/
  │     ├─ health.sh
  │     └─ whisper.sh
  │
  ├─ layers/
  │  ├─ api/
  │  │  ├─ whisper.ts            # :8770 WebSocket
  │  │  ├─ macos.ts              # :8766 HTTP
  │  │  ├─ chrome.ts             # Chrome CDP
  │  │  ├─ vscode.ts             # Extension API
  │  │  └─ yemreak.ts            # Telegram API
  │  │
  │  ├─ protocol/
  │  │  ├─ whisper.ts
  │  │  ├─ macos.ts
  │  │  ├─ chrome.ts
  │  │  ├─ vscode.ts
  │  │  └─ yemreak.ts
  │  │
  │  └─ hub/
  │     ├─ whisper.ts
  │     ├─ macos.ts
  │     ├─ chrome.ts
  │     ├─ vscode.ts
  │     └─ yemreak.ts
  │
  ├─ flows/
  │  ├─ transcribe.ts
  │  ├─ media-extract.ts
  │  └─ text-transform.ts
  │
  ├─ core/
  │  ├─ trading/
  │  │  └─ price.ts             # Price calculations
  │  ├─ llm/
  │  │  ├─ compress.ts
  │  │  └─ translate.ts
  │  └─ analytics/
  │     └─ infer-tags.ts
  │
  └─ infra/
     ├─ database/
     │  ├─ personal/
     │  └─ private/
     ├─ cache.ts
     └─ credentials.ts

  FLOW EXAMPLES

  1. Telegram voice → transcribe:
  User → Telegram voice
  clients/telegram/yemreak/handlers/message.voice.ts
  → hub.call("whisper.transcribe", {audio_path})
  → hub/server.ts
    → registry.call("whisper.transcribe")
      → layers/hub/whisper.ts
        → layers/protocol/whisper.ts
          → layers/api/whisper.ts
            → WebSocket :8770
  → result
  → hub.call("yemreak.sendMessage", {text})
  → layers/hub/yemreak.ts
    → Telegram API

TSCONFIG PATHS

  {
    "@clients/*": ["src/clients/*"],
    "@hub/*": ["src/hub/*"],
    "@layers/*": ["src/layers/*"],
    "@flows/*": ["src/flows/*"],
    "@core/*": ["src/core/*"],
    "@infra/*": ["src/infra/*"]
  }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/contents/5f559fac.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
