rugmuncher-backend / backend /SUPABASE_ARCHITECTURE.md
Netcup Server
ops: commit netcup-specific docs, config, and M3 Bayesian reputation on netcup mainline
846b6be
|
Raw
History Blame Contribute Delete
4.92 kB

RMI Supabase Integration β€” AI-First, Web3-Forward

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    RMI Backend (FastAPI)                 β”‚
β”‚                                                         β”‚
β”‚  supabase_router.py     supabase_oauth_router.py        β”‚
β”‚  supabase_auth_router.py  supabase_service.py           β”‚
β”‚  supabase_rag.py        db_client.py                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ httpx + service_role key
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Supabase                              β”‚
β”‚                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Auth    β”‚  β”‚  Postgres β”‚  β”‚  Row Level         β”‚  β”‚
β”‚  β”‚ (JWT+OAuth)β”‚  β”‚ (Database)β”‚  β”‚  Security (RLS)    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Storage  β”‚  β”‚  Edge     β”‚  β”‚  Real-time         β”‚  β”‚
β”‚  β”‚ (Files)   β”‚  β”‚ Functions β”‚  β”‚  Subscriptions     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Integration Points

1. Authentication (Web3 + Traditional)

  • JWT auth via supabase-auth skill + auth.py
  • OAuth providers: GitHub, Google (configured in supabase_oauth_router.py)
  • Wallet auth: EVM + Solana wallet connection (non-custodial)
  • x402 trial tracking: Device fingerprint + wallet-based quotas

2. Database (Postgres via Supabase)

  • User profiles: users table with premium tiers, notification prefs
  • Intelligence data: whale_movements, market_trending_tokens, scam_alerts
  • Content: content posts, comments, upvotes, gamification events
  • x402 payments: transaction logs, tool usage, trial tracking
  • Retention: 90-day auto-cleanup for non-security data

3. RAG / Vector Store

  • Redis-based vector store for crypto intelligence (rag_service.py)
  • Lightweight SQLite+TF-IDF fallback (rag_lightweight.py)
  • Collections: wallet_profiles, token_analysis, scam_patterns, forensic_reports, market_intel
  • n8n workflow ingests news articles into RAG

4. Env Vars Required

SUPABASE_URL=https://<project>.supabase.co
SUPABASE_ANON_KEY=eyJh...
SUPABASE_SERVICE_KEY=eyJh...
SUPABASE_JWT_SECRET=...

MCP (Model Context Protocol) Integration

  • /api/v1/x402/tools-catalog β€” Full MCP catalog of 51 (44 MCP + 7 bundles) tools
  • app/mcp/x402_mcp_server.py β€” MCP server implementation
  • app/mcp_router.py β€” Routes MCP tool calls to backend functions
  • GitHub repo: Rug-Munch-Media-LLC/rug-munch-intelligence-mcp (public)

x402 Payment Protocol

  • /.well-known/x402 β€” Protocol discovery document
  • 7 chains: Solana (Facilitator), Base (Facilitator), ETH/BSC/ARB/OPT/POL (Self-verify)
  • Trial: 1 free call (no wallet), 3 free calls (with wallet)
  • Payment: USDC micropayments via HTTP 402
  • Repos: x402-gateway-solana, x402-gateway-base, x402-twitter-view

AI-Forward Architecture

User Request β†’ Backend API β†’ Orchestrator (9 agents)
                    β”‚               β”‚
                    β”œβ”€β”€ Supabase    β”œβ”€β”€ Wallet clustering
                    β”œβ”€β”€ Redis RAG   β”œβ”€β”€ Scam detection
                    β”œβ”€β”€ News Agg    β”œβ”€β”€ Threat intel
                    └── x402 Gate   └── Cross-chain analysis

Web3 Best Practices Applied

  • Non-custodial: No private keys stored server-side
  • RLS: Row Level Security on all Supabase tables
  • Device fingerprinting: Anti-abuse for trial system
  • On-chain verification: Self-verify mode for 5 chains
  • Facilitator mode: Cloudflare Workers for Base/Solana