# Arquitetura - OPHION ## Visão Geral da Arquitetura ``` ┌─────────────────────────────────────────────────────────────────────────────┐ │ APLICAÇÕES INSTRUMENTADAS │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ Node.js │ │ Python │ │ Java │ │ .NET │ │ │ │ App │ │ App │ │ App │ │ App │ │ │ │ (OTEL SDK) │ │ (OTEL SDK) │ │ (OTEL Agent)│ │ (OTEL SDK) │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ │ │ │ │ │ └────────────────┴────────────────┴────────────────┘ │ │ │ │ │ OTLP (gRPC/HTTP) │ │ │ │ └───────────────────────────────────┼─────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────────────┐ │ OPHION PLATFORM │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ OTLP RECEIVER (Go) │ │ │ │ Port 4317 (gRPC) / 4318 (HTTP) │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ Traces │ │ Metrics │ │ Logs │ │ │ │ │ │ Receiver │ │ Receiver │ │ Receiver │ │ │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ └─────────┼────────────────┼────────────────┼──────────────────────────┘ │ │ │ │ │ │ │ └────────────────┼────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ API SERVER (Go) — Port 8080 │ │ │ │ ┌─────────────────────────────────────────────────────────────┐ │ │ │ │ │ MODULES │ │ │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───────┐ │ │ │ │ │ │ │ Auth │ │ API │ │ AI │ │ OTEL │ │Security│ │ │ │ │ │ │ │ Handlers│ │Handlers │ │Handlers │ │Processor│ │ Module │ │ │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └───────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────┐ │ │ │ │ │ AI ENGINE │ │ │ │ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │ │ │ │ │ │ Insights │ │Auto-Healing│ │Smart Alerts│ │ Copilot │ │ │ │ │ │ │ └───────────┘ └───────────┘ └───────────┘ └───────────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ DASHBOARD (Next.js) — Port 3000 │ │ │ │ ┌─────────────────────────────────────────────────────────────┐ │ │ │ │ │ FEATURES │ │ │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───────┐ │ │ │ │ │ │ │ Metrics │ │ Traces │ │ Logs │ │ Alerts │ │Copilot│ │ │ │ │ │ │ │Dashboard│ │ Viewer │ │Explorer │ │ Manager │ │ Chat │ │ │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └───────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └────────────────────────────────────┬────────────────────────────────────────┘ │ ┌───────────────────────────┼───────────────────────────┐ │ │ │ ▼ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────────┐ │ Database │ │ Time Series │ │ OpenAI API │ │ (PostgreSQL) │ │ (InfluxDB/ │ │ │ │ │ │ ClickHouse) │ │ ┌─────────────────┐ │ │ • Users │ │ │ │ │ GPT-4 │ │ │ • Alerts │ │ • Metrics │ │ │ (Insights, │ │ │ • Configs │ │ • Traces │ │ │ Copilot) │ │ │ • Audit Logs │ │ • Logs │ │ └─────────────────┘ │ └─────────────────┘ └─────────────────┘ └─────────────────────────┘ ``` ## Fluxo de Dados ``` ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ Application │────▶│ OTEL SDK │────▶│OTLP Receiver│────▶│ Processor │ │ (Source) │ │ (Client) │ │ (4317/4318) │ │ Pipeline │ └─────────────┘ └─────────────┘ └─────────────┘ └──────┬──────┘ │ ┌────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ Storage │────▶│ AI Engine │────▶│ Insights │────▶│ Alert │ │ (TimeSeries)│ │ (Analysis) │ │ (Generated) │ │ (Trigger) │ └─────────────┘ └─────────────┘ └─────────────┘ └──────┬──────┘ │ ┌────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────┐ ┌─────────────┐ │ Notification│────▶│ Auto-Heal │ │ (Slack, │ │ (Execute │ │ etc.) │ │ Playbook) │ └─────────────┘ └─────────────┘ ``` ## Módulos de IA ``` ┌─────────────────────────────────────────────────────────────────────────────┐ │ AI ENGINE │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌───────────────────────────┐ ┌───────────────────────────┐ │ │ │ 🔮 INSIGHTS │ │ 🔧 AUTO-HEALING │ │ │ │ │ │ │ │ │ │ • Anomaly detection │ │ • Problem detection │ │ │ │ • Pattern recognition │ │ • Playbook matching │ │ │ │ • Capacity forecasting │ │ • Action execution │ │ │ │ • Root cause analysis │ │ • Verification │ │ │ │ • Optimization tips │ │ • Rollback support │ │ │ │ │ │ │ │ │ │ Input: Metrics, Traces │ │ Input: Alerts, Metrics │ │ │ │ Output: Recommendations │ │ Output: Actions │ │ │ └───────────────────────────┘ └───────────────────────────┘ │ │ │ │ ┌───────────────────────────┐ ┌───────────────────────────┐ │ │ │ 🚨 SMART ALERTS │ │ 💬 COPILOT │ │ │ │ │ │ │ │ │ │ • Alert correlation │ │ • Natural language query │ │ │ │ • Noise reduction │ │ • Context-aware answers │ │ │ │ • Priority scoring │ │ • Dashboard generation │ │ │ │ • Impact analysis │ │ • Query building │ │ │ │ • Grouping/dedup │ │ • Troubleshooting guide │ │ │ │ │ │ │ │ │ │ Input: Raw alerts │ │ Input: User question │ │ │ │ Output: Prioritized list │ │ Output: Answer + actions │ │ │ └───────────────────────────┘ └───────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ## Arquitetura do Backend (Go) ``` ┌─────────────────────────────────────────────────────────────────────┐ │ GO SERVER │ │ (cmd/server) │ │ │ │ ┌───────────────────────────────────────────────────────────────┐ │ │ │ INTERNAL │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ │ │ internal/api │ │ │ │ │ │ ┌───────────────┐ ┌───────────────┐ │ │ │ │ │ │ │ ai_handlers │ │ ratelimit │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ • /ai/insights│ │ • Token bucket│ │ │ │ │ │ │ │ • /ai/chat │ │ • Per-IP limit│ │ │ │ │ │ │ │ • /ai/analyze │ │ • Sliding win │ │ │ │ │ │ │ └───────────────┘ └───────────────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ │ │ internal/ai │ │ │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │ │ │ │ │ │ │ engine │ │insights │ │autohealing│ │smart_alerts│ │ │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────────┘ │ │ │ │ │ │ ┌─────────┐ │ │ │ │ │ │ │ copilot │ │ │ │ │ │ │ └─────────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ │ │ internal/auth │ │ │ │ │ │ ┌───────────────┐ ┌───────────────┐ │ │ │ │ │ │ │ handlers │ │ middleware │ │ │ │ │ │ │ │ • login │ │ • JWT verify │ │ │ │ │ │ │ │ • logout │ │ • RBAC check │ │ │ │ │ │ │ └───────────────┘ └───────────────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ │ │ internal/otel │ │ │ │ │ │ ┌───────────────────────────────────────────────────┐ │ │ │ │ │ │ │ otlp_receiver │ │ │ │ │ │ │ │ • gRPC server (4317) │ │ │ │ │ │ │ │ • HTTP server (4318) │ │ │ │ │ │ │ │ • Trace/Metric/Log processors │ │ │ │ │ │ │ └───────────────────────────────────────────────────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ └───────────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘ ``` ## Stack Tecnológico ``` ┌─────────────────────────────────────────────────────────────────┐ │ STACK TECNOLÓGICO │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ BACKEND │ │ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │ │ │ │ Go │ │ OpenAI │ │ OTEL │ │ │ │ │ │ 1.22+ │ │ GPT-4 │ │ Protocol │ │ │ │ │ └───────────┘ └───────────┘ └───────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ FRONTEND │ │ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌─────────┐ │ │ │ │ │ Next.js │ │ React │ │ Tailwind │ │Recharts │ │ │ │ │ │ 14.1 │ │ 18 │ │ │ │ D3.js │ │ │ │ │ └───────────┘ └───────────┘ └───────────┘ └─────────┘ │ │ │ │ ┌───────────┐ ┌───────────┐ │ │ │ │ │ Radix UI │ │ TanStack │ │ │ │ │ │ │ │ Query │ │ │ │ │ └───────────┘ └───────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ INFRASTRUCTURE │ │ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌─────────┐ │ │ │ │ │ Docker │ │PostgreSQL │ │InfluxDB/ │ │ Nginx │ │ │ │ │ │ Compose │ │ │ │ClickHouse │ │(reverse)│ │ │ │ │ └───────────┘ └───────────┘ └───────────┘ └─────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────┘ ``` ## Deploy Architecture ``` ┌─────────────────────────────────────────────────────────────────────────────┐ │ DOCKER COMPOSE DEPLOYMENT │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ CONTAINERS │ │ │ │ │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │ │ │ │ ophion-server │ │ophion-dashboard │ │ ophion-agent │ │ │ │ │ │ (Go API) │ │ (Next.js) │ │ (Collector) │ │ │ │ │ │ Port 8080 │ │ Port 3000 │ │ 4317/4318 │ │ │ │ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ │ │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ │ │ postgresql │ │ influxdb │ │ │ │ │ │ Port 5432 │ │ Port 8086 │ │ │ │ │ └─────────────────┘ └─────────────────┘ │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ VOLUMES │ │ │ │ • postgres_data — Database persistence │ │ │ │ • influx_data — Time series data │ │ │ │ • ophion_config — Configuration files │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ NETWORKS │ │ │ │ • ophion_net — Internal communication │ │ │ │ • External ports: 3000 (UI), 8080 (API), 4317/4318 (OTLP) │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ## Fluxo de Auto-Instrumentação ``` ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ Run │────▶│ Detect │────▶│ Inject │────▶│ Config │ │ instrument.sh│ │ Language │ │ OTEL SDK │ │ Exporter │ └─────────────┘ └─────────────┘ └─────────────┘ └──────┬──────┘ │ ┌────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ Restart │────▶│ Verify │────▶│ Ready │ │ Container │ │ Telemetry │ │ ✓ │ └─────────────┘ └─────────────┘ └─────────────┘ ``` --- *Diagrama de arquitetura gerado em 2026-02-09*