# RateRight — System Overview

## Architecture at a Glance

```
┌─────────────────────────────────────────────────────────┐
│                    PUBLIC FACING                         │
│                                                         │
│  rivet.rateright.com.au    — The App (Next.js)          │
│  rateright.com.au          — Landing Page (Flask/Fly)   │
│  Growth Engine             — CRM API (Railway)          │
│  Phone AI                  — Voice Receptionist (VAPI)  │
│                                                         │
├─────────────────────────────────────────────────────────┤
│                    BACKEND                               │
│                                                         │
│  Supabase      — Database, Auth, RLS, Edge Functions    │
│  Stripe        — Payments ($50/hire)                    │
│  nginx         — Reverse proxy, SSL termination         │
│                                                         │
├─────────────────────────────────────────────────────────┤
│                    AI AGENT FLEET (OpsMan Prototype)     │
│                                                         │
│  8 Clawdbot gateways, each a specialist agent           │
│  Coordinated via fleet-state.json + JSONL inboxes       │
│  This fleet IS the OpsMan product demonstration         │
│                                                         │
└─────────────────────────────────────────────────────────┘
```

---

## 1. The App — RateRight Marketplace

**Stack:** Next.js 15 (App Router) + TypeScript + Tailwind CSS + shadcn/ui
**Database:** Supabase (PostgreSQL + Row Level Security)
**Auth:** Supabase Auth (email/password + OAuth)
**Payments:** Stripe ($50 AUD flat fee per hire)
**Hosting:** DigitalOcean VPS (syd1, 2 vCPU, 8GB RAM) via systemd
**Domain:** rivet.rateright.com.au (production) — planned move to rateright.com.au
**Build:** `npm run build` → systemd service `rateright-app` on port 3000

### Key Features
- **Contractor flow:** Sign up → Post job (voice or form) → Browse matches → Hire → Pay $50
- **Worker flow:** Sign up → Build profile (voice or form) → Get matched → Accept work → Build ratings
- **AI matching:** Workers ranked by relevance to job requirements
- **Voice-to-job:** Contractors speak job descriptions, AI fills the structured form
- **Voice profiles:** Workers fill out profiles by speaking naturally
- **Onboarding packs:** Client-side PDF generation for contractor compliance docs
- **Browse Workers:** Contractors can discover workers directly
- **CEO Dashboard:** `/ceo` — business metrics and admin overview

### Database Schema (Supabase)
- Users (auth) → Profiles (contractor or worker type)
- Jobs (posted by contractors)
- Applications / Matches
- Ratings & Reviews
- Payments (Stripe integration)
- Phone numbers + names required on all signup paths (DB trigger writes from auth metadata)
- RLS enforced across all tables

### Tech Details
- **Port:** 3000 (behind nginx)
- **Service:** `systemd: rateright-app`
- **Deploy:** `cd /home/ccuser/the-50-dollar-app && npm run build && systemctl restart rateright-app`
- **Workspace:** `/home/ccuser/the-50-dollar-app`

---

## 2. Growth Engine — CRM & Sales Intelligence

**Stack:** Node.js + Express
**Database:** Supabase (separate project from the app)
**Hosting:** Railway (rateright-growth-production.up.railway.app)
**Workspace:** `/home/ccuser/rateright-growth`

### API Endpoints (15+)
- Leads CRUD (30+ fields per lead including AI analysis, contact history, pipeline tracking)
- SMS sending and sequences (via Twilio — currently all deactivated)
- Call logging with post-call AI analysis
- Intel briefs (AI-generated business intelligence per lead)
- Dashboard stats
- Notion sync
- Team management

### Integrations
- Notion (business ops, planning)
- Slack (team coordination)
- Gmail (email)
- Google Sheets (reporting)
- Twilio (SMS + voice)
- Pushover (notifications)
- Apollo (contact enrichment)

### Key Feature
Post-call AI analysis that splits intel into personal vs business files — automatically enriches lead profiles after every call.

---

## 3. Phone AI — Voice Receptionist

**Platform:** VAPI
**Model:** GPT-4o with custom RateRight personality
**Assistant ID:** 63ac4ff9-e562-4c8e-9c19-c1f1c87ed034
**Purpose:** Qualify inbound leads, log to Growth Engine CRM
**Phone:** Business line (+61 468 087 171)

---

## 4. Landing Page — rateright.com.au

**Stack:** Flask (Python)
**Hosting:** Fly.io (rateright-au)
**Purpose:** Current public-facing landing page (will be replaced by Next.js app)

---

## 5. AI Agent Fleet — The OpsMan Prototype

The 8-agent fleet runs the business AND demonstrates what OpsMan would be for contractors.

### The Fleet

| Agent | Port | Model | Role |
|-------|------|-------|------|
| **Rivet** 🔧 | 18789 | Claude Opus 4.6 | Chief of Staff — coordinates all agents, strategy, decision prep |
| **Builder** 🔨 | 18790 | Claude Opus 4.6 | Development — ALL code changes, testing, deployment |
| **Susan** 💼 | 18792 | DeepSeek | Sales & Marketing — leads, CRM, outreach, pipeline |
| **Harper** 📊 | 18796 | DeepSeek | Finance & Legal — grants, compliance, tax, BAS |
| **Sentinel** 🛡️ | 18800 | DeepSeek | DevSecOps — monitoring, infrastructure, security |
| **Radar** 🔭 | 18804 | DeepSeek | Intelligence — market research, competitor analysis, trends |
| **Herald** 📡 | 18808 | Claude Opus 4.6 | Communications — content creation, external comms review |
| **Cog** ⚙️ | 18812 | DeepSeek | Operations — routine tasks, health checks, data processing |

### How Agents Work
- Each agent is a **Clawdbot gateway** (Node.js process) with its own port, model, and workspace
- Managed via **systemd** (`clawdbot-{agent}` services)
- Communicate via:
  - **Shared inboxes** (JSONL files for async messaging)
  - **fleet-state.json** (centralized status tracking)
  - **queue.json** (per-agent task queues)
  - **Agent bridge** (`node scripts/agent-bridge.js <agent> <command>`)
  - **Gateway-to-gateway WebSocket** (direct RPC between gateways)
- **Telegram** integration for human communication (Rocky & Rivet group, topic-based)

### Fleet Coordination Infrastructure
- **Stall detector** (*/5 min) — detects unresponsive agents
- **Buddy check** (*/30 min) — cross-agent health monitoring
- **Work generator** (every 2h) — creates tasks for idle agents
- **Context monitor** (*/10 min) — tracks agent context window usage
- **Crash loop guard** (*/2 min) — catches and recovers crash-looping agents
- **Session archiver** (3 AM daily) — cleans stale sessions
- **Inbox curator** (*/30 min) — manages JSONL message flow

### Agent Workspaces
```
/home/ccuser/
├── the-50-dollar-app/     # Builder workspace (Next.js app + fleet scripts)
├── rateright-growth/
│   └── rivet/             # Rivet workspace (coordination, memory, plans)
├── susan/                 # Susan workspace (sales)
├── harper/                # Harper workspace (finance)
├── sentinel/              # Sentinel workspace (devops)
├── radar/                 # Radar workspace (intelligence)
├── herald/                # Herald workspace (comms)
├── cog/                   # Cog workspace (operations)
└── shared/                # Shared scripts and fleet state
    ├── fleet-state.json
    └── scripts/
        ├── fleet-cli.js
        ├── fleet-update.js
        ├── stall-detector.js
        ├── buddy-check.js
        ├── work-generator.js
        ├── context-monitor.js
        ├── inbox.js
        └── inbox-curator.js
```

---

## 6. Infrastructure

| Component | Details |
|-----------|---------|
| **VPS** | DigitalOcean syd1, 2 vCPU, 8GB RAM (134.199.153.159) |
| **OS** | Ubuntu Linux 6.8.0-100-generic (x64) |
| **Node** | v22.22.0 |
| **Reverse Proxy** | nginx (SSL termination, port routing) |
| **SSL** | Let's Encrypt (auto-renewed) |
| **Process Manager** | systemd (all services) |
| **DNS** | rivet.rateright.com.au → VPS, rateright.com.au → Fly.io |

### External Services

| Service | Purpose | Status |
|---------|---------|--------|
| Supabase | Database + Auth | ✅ Connected |
| Stripe | Payments | ✅ Configured ($50 AUD product) |
| Anthropic | Claude Opus 4.6 (Rivet, Builder, Herald) | ✅ Working |
| DeepSeek | Agent models (Susan, Sentinel, Radar, Cog) | ✅ Working |
| OpenAI | Various AI tasks | ✅ Configured |
| Twilio | SMS + Voice | ✅ Configured |
| Railway | Growth Engine hosting | ✅ Deployed |
| Fly.io | Landing page hosting | ✅ Deployed |
| VAPI | Phone AI | ✅ Active |
| Brave Search | Web search | ✅ Configured |
| Apollo | Contact enrichment | ✅ Working |
| Notion | Business ops | ✅ Connected |

---

## 7. Current System Health (Feb 18, 2026)

**Overall: 62%** (per Builder's system audit)

| Area | Score | Notes |
|------|-------|-------|
| Infrastructure | 95% | Rock solid — VPS, services, SSL all healthy |
| Agent Fleet | 85% | All alive but monitoring data lags |
| Communication | 45% | Inboxes exist but cross-agent coordination broken |
| Automation | 80% | All 12 cron jobs running, work generation low |
| External Services | 75% | MiniMax broken, Moonshot suspended |
| Memory | 40% | 4 agents barely maintaining context |
| Task Workflow | 35% | Tasks queued but none being claimed or worked |
| Model Strategy | 70% | Working but 2/4 providers down |

### Top 3 Gaps
1. **Task lifecycle broken** — tasks sit in queues, agents don't claim them
2. **Communication loop broken** — no cross-agent work handoffs happening
3. **Memory inequality** — 4 agents are practically amnesiac (1-3 memory files)

---

*System built by Michael (prompting) + Builder (coding) + Rivet (coordination).*
*The agent fleet itself IS the OpsMan product prototype — proving AI can run business operations.*
