Files
opantoantro/docs/wiki/Index.md
T
Beyhan Ogur a408821410 first commit
2026-05-11 15:08:50 +03:00

87 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LLM Gateway — Mimari Haritası
**Özet:** Bu proje, birden fazla LLM sağlayıcısını (OpenAI-compatible, Anthropic) tek bir gateway üzerinden proxy'leyen, istekleri dönüştüren ve loglayan bir Go hizmetidir. Go 1.26 + Fiber v3 + GORM + PostgreSQL / SQLite (`DB_MODE` ile seçimli) teknolojileriyle inşa edilmiştir.
**Kütüphaneler:** Go 1.26, Fiber v3, GORM, PostgreSQL, SQLite, godotenv, swaggo
**Bağlantılar:** [[Main]], [[Config]], [[HealthHandler]], [[OpenAIHandler]], [[AnthropicHandler]], [[ProxyEngine]], [[BifrostTransform]], [[RequestLog]], [[SwaggerUI]], [[Testing]], [[DockerSetup]], [[OpenAI_Flow]], [[Anthropic_Flow]], [[ClaudeCode_Setup]]
---
## Katman Mimarisi
| Katman | Dosya | Açıklama |
|--------|-------|----------|
| **Giriş** | `main.go:38` | Fiber v3 app başlatma, DB bağlantısı, route tanımları |
| **Konfigürasyon** | `config/config.go:9` | `.env` tabanlı runtime config (port, backend, DSN) |
| **Handler** | `handlers/*.go` | HTTP handler fonksiyonları (health, openai, anthropic) |
| **Proxy** | `internal/proxy/proxy.go:14` | Generic HTTP forward motoru |
| **Transform** | `internal/transform/anthropic_bifrost.go:10` | Anthropic ↔ OpenAI format dönüştürücü |
| **Model** | `models/request_log.go:13` | GORM veritabanı modeli |
## API Endpoint'leri
| Method | Path | Handler | Açıklama |
|--------|------|---------|----------|
| `GET` | `/health` | [[HealthHandler]] | Servis durumu, DB sağlığı, config bilgisi |
| `ALL` | `/v1/*` | [[OpenAIHandler]] | OpenAI-compatible direct passthrough proxy |
| `ALL` | `/anthropic`, `/anthropic/*` | [[AnthropicHandler]] | Anthropic Messages API → OpenAI dönüşüm proxy |
| `GET` | `/swagger`, `/swagger/*` | Inline Fiber | CDN'den yüklenen Swagger UI |
## Veri Akışları
- [[OpenAI Flow]] — `/v1/*` isteklerinin upstream'e direkt iletilmesi
- [[Anthropic Flow]] — `/anthropic/*` isteklerinin Bifrost dönüşümüyle upstream'e iletilmesi
## Claude Code Entegrasyonu
- [[ClaudeCode_Setup]] — Claude Code CLI'ı gateway üzerinden kullanma
## Altyapı ve Geliştirme
- [[DockerSetup]] — Multi-stage Docker build + docker-compose (app + postgres)
- [[SwaggerUI]] — `/swagger/` adresinde OpenAPI dokümantasyonu
- [[Testing]] — `httptest.Server` ile mock upstream testleri
- `.air.toml` — Air hot-reload (geliştirme)
- `build.sh` — Production binary derleme scripti
- [[RequestLog]] — GORM + PostgreSQL/SQLite istek loglama
## Veritabanı Şeması
| Tablo | Model | Amaç |
|-------|-------|------|
| `request_logs` | [[RequestLog]] | Tüm proxy isteklerinin log kaydı |
## Dönüşüm Katmanı
| Yön | Fonksiyon | Açıklama |
|-----|-----------|----------|
| Anthropic → OpenAI | `AnthropicToBifrost()` | Mesaj API → Chat Completions dönüşümü |
| OpenAI → Anthropic | `BifrostToAnthropic()` | Chat Completions → Mesaj API dönüşümü |
Desteklenen model prefix'leri: `DeepSeek/`, `OpenAI/`, `Anthropic/`, `Google/`
## Proje Haritası
```
.
├── main.go # Giriş noktası
├── config/config.go # Konfigürasyon
├── models/request_log.go # Veritabanı modeli
├── handlers/
│ ├── health.go # Health check
│ ├── openai.go # OpenAI proxy
│ └── anthropic.go # Anthropic proxy
├── internal/
│ ├── proxy/proxy.go # Forward motoru
│ └── transform/anthropic_bifrost.go # Format dönüştürücü
├── tests/openai_test.go # Unit testler
├── docker/
│ ├── Dockerfile # Multi-stage build
│ └── docker-compose.yml # Orchestration
├── build.sh # Derleme scripti
└── docs/
├── swagger.json/yaml # Swagger spec
└── wiki/ # Bu wiki (Obsidian Knowledge Graph)
```