← Zpět na hlavní stránku

Gateway - Přístup a použití

🚪 PŘÍSTUP A POUŽITÍ - CzechAI Unified Gateway

Datum: 2026-01-25 Port: 9090 Status: ✅ PRODUKČNÍ


🎯 CO TO JE?

Unified Gateway je centrální vstupní bod pro všechny CzechAI agent servery. Namísto volání 11 různých portů (9100-9116), voláš JEDEN port (9090) a gateway ti směruje requesty na správnou službu.


📍 JAK SE K TOMU PŘISTUPUJE?

1. LOKÁLNĚ (na serveru 46.224.121.179)

# Základní info
curl http://localhost:9090/

# Health check všech služeb
curl http://localhost:9090/health

# Seznam služeb
curl http://localhost:9090/api/services

# Seznam všech agentů
curl http://localhost:9090/api/agents

# Swagger UI dokumentace
http://localhost:9090/docs

# Prometheus metrics
curl http://localhost:9090/metrics

2. VZDÁLENĚ (z Windows přes SSH tunnel)

# Vytvoř SSH tunnel
ssh -L 9090:localhost:9090 root@46.224.121.179

# Pak v jiném terminálu
curl http://localhost:9090/health

3. PŘÍMO (pokud je firewall otevřen)

curl http://46.224.121.179:9090/health

🚀 JAK SE TO SPOUŠTÍ?

START/STOP/RESTART

# 1. Přihlásit se na server
ssh root@46.224.121.179

# 2. Přejít do složky
cd /root/.claude-code/unified_gateway

# 3. Spustit/Restartovat/Zastavit
docker compose up -d      # Spustit
docker compose restart    # Restartovat
docker compose down       # Zastavit

# 4. Logování
docker compose logs -f    # Real-time logy

REBUILD (po změnách kódu)

# 1. Zastavit
docker compose down

# 2. Rebuild (BEZ cache!)
docker compose build --no-cache

# 3. Spustit
docker compose up -d

# 4. Ověřit
curl http://localhost:9090/health

PM2 ALTERNATIVE (není doporučeno, používej Docker)

Gateway běží v Dockeru, NE přes PM2. Pokud chceš PM2:

# NE! Gateway je Docker service
pm2 list | grep gateway  # Nic nenajdeš

🔧 JAK CO FUNGUJE?

ARCHITEKTURA

[Klient]
   
[Nginx] (api.czechai.io) - budoucí TODO
   
[Gateway:9090] ←──────────── Unified vstup
   
   ├─→ Banking (9100)         6 agentů
   ├─→ Legal-AML (9101)       5 agentů
   ├─→ Real Estate (9102)     9 agentů
   ├─→ Insurance (9103)       4 agenty
   ├─→ Compliance (9104)      5 agentů
   ├─→ Risk (9105)            5 agentů
   ├─→ AML (9106)             7 agentů
   ├─→ Legal (9107)           3 agenty
   ├─→ Data (9108)           14 agentů
   ├─→ Contact (9109)        12 agentů
   └─→ Orchestrator (9116)    2 agenty

ROUTING LOGIKA

  1. Request přijde: POST http://localhost:9090/api/banking/loan-assessment
  2. Gateway parsuje: service = "banking", path = "loan-assessment"
  3. Gateway najde URL: http://localhost:9100 (banking service)
  4. Gateway proxuje: POST http://localhost:9100/loan-assessment
  5. Response vrátí: Přes gateway zpátky klientovi

PŘÍKLAD POUŽITÍ

# BANKING - Loan Assessment
curl -X POST http://localhost:9090/api/banking/loan-assessment \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5000000,
    "monthly_income": 80000,
    "property_value": 8000000,
    "monthly_expenses": 30000
  }'

# LEGAL-AML - Company Screening
curl -X POST http://localhost:9090/api/legal-aml/company-screening \
  -H "Content-Type: application/json" \
  -d '{
    "ico": "12345678",
    "company_name": "Example s.r.o."
  }'

# REAL ESTATE - Due Diligence
curl -X POST http://localhost:9090/api/real-estate/due-diligence \
  -H "Content-Type: application/json" \
  -d '{
    "property_id": "ABC123",
    "address": "Praha 1, Václavské náměstí 1"
  }'

📊 MONITORING & METRICS

Health Check

# Zkontroluj všechny služby
curl http://localhost:9090/health | jq

# Response:
# {
#   "gateway": "healthy",
#   "overall": "healthy",
#   "services": {
#     "banking": {"status": "healthy", "url": "http://localhost:9100"},
#     "legal-aml": {"status": "healthy", "url": "http://localhost:9101"},
#     ...
#   }
# }

Prometheus Metrics

# Prometheus metrics endpoint
curl http://localhost:9090/metrics

# Metriky:
# - gateway_requests_total (celkový počet requestů)
# - gateway_request_duration_seconds (doba trvání)
# - gateway_active_requests (aktivní requesty)
# - gateway_service_health (zdraví služeb - 1=healthy, 0=unhealthy)
# - gateway_proxy_requests_total (proxy requesty)
# - gateway_proxy_errors_total (proxy errors)

Grafana Dashboard (TODO - Batch 9)

# Budoucí setup:
# 1. Prometheus scraping z /metrics
# 2. Grafana vizualizace
# 3. Alerting (Slack notifications)

🗂️ STRUKTURA SLOŽKY

unified_gateway/
├── app.py                  # Hlavní FastAPI aplikace (494 řádků)
├── generate_openapi.py     # OpenAPI schema generator (548 řádků)
├── openapi.json            # OpenAPI 3.0 schema (1057 řádků, 27KB)
├── openapi.yaml            # YAML verze (optional)
├── requirements.txt        # Python dependencies
├── Dockerfile              # Docker build
├── docker-compose.yml      # Docker orchestrace
├── deploy.sh               # Deployment script
├── README.md               # Původní dokumentace
└── PRISTUP_A_POUZITI.md   # TENTO SOUBOR - vstupní dokumentace

🔐 KONFIGURACE

ENV proměnné (žádné zatím)

Gateway momentálně nepotřebuje ENV proměnné. Všechny URL jsou hardcodované v app.py:

AGENT_SERVICES = {
    "banking": {"url": "http://localhost:9100", ...},
    "legal-aml": {"url": "http://localhost:9101", ...},
    ...
}

Ports

Port Použití
9090 Gateway hlavní port
9100-9116 Backend agent servery (11 služeb)

🚨 TROUBLESHOOTING

Problém: Gateway neběží

# 1. Zkontroluj Docker status
docker ps | grep unified-gateway

# 2. Podívej se na logy
cd /root/.claude-code/unified_gateway
docker compose logs -f

# 3. Restart
docker compose restart

# 4. Pokud nepomohlo - rebuild
docker compose down
docker compose build --no-cache
docker compose up -d

Problém: Služba "unhealthy"

# 1. Zkontroluj který agent server neběží
curl http://localhost:9090/health | jq '.services'

# 2. Test konkrétního serveru (např. banking)
curl http://localhost:9100/health

# 3. Pokud 9100 neběží - restart banking serveru
cd /opt/agents/banking  # (nebo kde je banking implementace)
# ...restart podle implementace (PM2/Docker/systemd)

Problém: Prometheus metrics nefungují

# 1. Test /metrics endpointu
curl http://localhost:9090/metrics | head -20

# 2. Pokud error "ModuleNotFoundError: No module named 'prometheus_client'"
#    - Rebuild Docker image BEZ cache:
docker compose down
docker system prune -af
docker compose build --no-cache
docker compose up -d

Problém: Port 9090 obsazený

# 1. Zjisti co běží na 9090
netstat -tlnp | grep 9090

# 2. Pokud MinIO nebo jiná služba - změň port v docker-compose.yml:
# ports:
#   - "9091:9090"  # Místo 9090:9090

# 3. Restart
docker compose down && docker compose up -d

📚 DALŠÍ DOKUMENTACE

Soubor Popis
README.md Původní dokumentace gateway (230 řádků)
BATCH_8_COMPLETE_SUMMARY.md Kompletní summary Batch 8 (453 řádků)
PRAKTICKE_PRIKLADY_POUZITI.md 9 praktických příkladů použití
AGENT_IMPLEMENTATION_STATUS.md Status všech 111 agentů

⚙️ ADMINISTRACE

Přidání nové služby

  1. Přidej do app.py v sekci AGENT_SERVICES:
AGENT_SERVICES = {
    ...
    "nova-sluzba": {
        "url": "http://localhost:9117",
        "name": "Nová Služba",
        "description": "Popis nové služby",
        "tag": "Nova Sluzba"
    }
}
  1. Rebuild Docker:
docker compose down
docker compose build --no-cache
docker compose up -d
  1. Ověř:
curl http://localhost:9090/health | jq '.services."nova-sluzba"'

Update OpenAPI dokumentace

# 1. Update generate_openapi.py (přidej nové endpointy)
# 2. Regeneruj schema
python generate_openapi.py

# 3. Zkopíruj do Docker
docker cp openapi.json czechai-unified-gateway:/app/openapi.json

# 4. Restart
docker compose restart

# 5. Ověř
curl http://localhost:9090/docs  # Swagger UI

🎯 RYCHLÝ START (pro nové členy týmu)

# 1. SSH na server
ssh root@46.224.121.179

# 2. Test gateway
curl http://localhost:9090/health

# 3. Pokud neběží - start
cd /root/.claude-code/unified_gateway
docker compose up -d

# 4. Swagger UI
# → Otevři v browseru: http://46.224.121.179:9090/docs
#    (nebo přes SSH tunnel)

# 5. Test endpoint
curl -X POST http://localhost:9090/api/banking/loan-assessment \
  -H "Content-Type: application/json" \
  -d '{"amount": 5000000, "monthly_income": 80000}'

# 6. Hotovo! ✅

Vytvořeno: 2026-01-25 Autor: CzechAI Status: ✅ PRODUCTION READY


© 2026 CzechAI | router.czechai.io | API Docs