import React, { useState } from 'react'; import { ChevronDown, ChevronUp, Zap, Database, Brain, Cpu, Server } from 'lucide-react'; const LAYERS = [ { name: 'Data Ingestion Layer', badges: ['Kafka', 'Redpanda', 'AWS Kinesis'], status: '500K events/sec capacity', color: 'var(--amber)', icon: Zap, content: `Apache Kafka handles bulk data ingestion from external sources. Redpanda sits on the critical write path for <2ms p99 latency. Kafka consumers batch-write to PostgreSQL every 100ms to reduce INSERT overhead.\n\nKey config:\n producer.acks = all (durability)\n compression.type = lz4 (throughput)\n batch.size = 16384 (throughput vs latency)\n linger.ms = 5 (batch window)`, }, { name: 'PostgreSQL 17 Core', badges: ['pgvector 0.8', 'HNSW', 'GIN', 'Partitioning', 'Apache AGE'], status: '50M+ rows, sub-100ms', color: '#569CD6', icon: Database, content: `The database is the AI brain. All intelligence lives here.\n\nKEY CONFIGURATION (postgresql.conf):\n max_parallel_workers_per_gather = 8\n max_parallel_workers = 16\n work_mem = 256MB (critical for HNSW)\n maintenance_work_mem = 2GB\n effective_cache_size = 24GB\n wal_compression = on\n jit = off (hurts pgvector performance)\n\nINDEXES:\n reviews.embedding → HNSW (m=16, ef_construction=64)\n reviews.text → GIN tsvector (full-text)\n transactions → RANGE partition by created_at (monthly)`, }, { name: 'AI Trigger Functions', badges: ['DistilBERT', 'OpenAI embeddings', 'XGBoost', 'pg_background'], status: '3 models · 0.48ms avg', color: 'var(--purple-l)', icon: Brain, content: `Trigger functions call AI models through plpython3u extensions. Models are loaded once into shared memory via pg_background workers.\n\nTRIGGER EXECUTION ORDER (AFTER INSERT, FOR EACH ROW):\n 1. ai_sentiment_analyzer (priority 10) — ONNX DistilBERT\n 2. ai_embedder (priority 20) — OpenAI API (async via pg_net)\n 3. xgboost_fraud_scorer (priority 30) — in-process XGBoost\n 4. tsvector_updater (priority 40) — native PostgreSQL\n\nCRITICAL: Embedding calls use pg_net for async HTTP — they do NOT block the INSERT transaction.`, }, { name: 'LangGraph AI Analyst Agent', badges: ['LangGraph', 'LangSmith', 'Gemini 2.0', 'SQLGlot validator'], status: '94% accuracy · 6% fallback', color: 'var(--teal)', icon: Cpu, content: `The agent follows a 5-node LangGraph StateGraph:\n\n Node 1: TABLE SELECTOR → selects relevant tables\n Node 2: SQL GENERATOR → generates SQL from exact DDL\n Node 3: SQL VALIDATOR (SQLGlot) → catches syntax errors\n Node 4: SQL EXECUTOR (read-only connection)\n Node 5: RETRY LOOP → max 3 retries, temp 0.3 on retry\n\nCritical: must inject EXACT CREATE TABLE DDL — paraphrased schemas cause column name hallucination. LangSmith traces every run.`, }, { name: 'Cache & Orchestration', badges: ['Redis', 'Airflow', 'MLflow', 'Grafana'], status: '15min DAG refresh', color: 'var(--text3)', icon: Server, content: `Redis caches hot query results (TTL 5 min, 30s for fraud alerts). Cache hit rate target: >70%.\n\nAirflow DAG: ai_views_refresh (schedule: */15 * * * *)\n Task 1: REFRESH MATERIALIZED VIEW CONCURRENTLY mv_sentiment_daily\n Task 2: REFRESH MATERIALIZED VIEW CONCURRENTLY mv_cohort_clusters\n Task 3: REFRESH MATERIALIZED VIEW CONCURRENTLY mv_fraud_scores\n Task 4: REFRESH MATERIALIZED VIEW CONCURRENTLY mv_anomaly_scores\n Task 5: Invalidate Redis keys\n Task 6: Publish metrics to Prometheus\n\nMLflow tracks model versions, trigger inference time, SQL agent accuracy.`, }, ]; export default function Architecture() { const [expanded, setExpanded] = useState(null); const toggle = (i) => setExpanded(expanded === i ? null : i); return (
Click each layer to see implementation details, configuration, and design decisions.