Architecture

darkreach is a five-layer system: a high-performance Rust engine for number theory computation, an AI engine for autonomous strategy, an Axum server for coordination, a PostgreSQL database for persistence, and two Next.js frontends for public and operational interfaces.

System Overview

┌─────────────────────────────────────────────────────────┐
│                    darkreach.ai                          │
│               (Next.js static export)                   │
│        Landing · Docs · Status · Blog · Leaderboard      │
└─────────────────────────────────────────────────────────┘

┌────────────────────┐      ┌────────────────────────────────┐
│  app.darkreach.ai  │─────▶│      api.darkreach.ai          │
│  (Next.js + SPA)   │ WS   │    (Axum web server)           │
│                    │◀─────│                                │
│  Browse · Searches │      │  REST API (15 route modules)   │
│  Network · Agents  │      │  WebSocket (2s push)           │
│  Projects · Logs   │      │  AI Engine (OODA loop)         │
│  Strategy · Verify │      │  Project Orchestrator          │
└────────────────────┘      └───────────┬────────────────────┘
                                        │
                             ┌──────────▼─────────────────┐
                             │       PostgreSQL            │
                             │   (Supabase / self-hosted)  │
                             │                             │
                             │  primes · workers · jobs    │
                             │  projects · agents · ai     │
                             │  operators · releases       │
                             │  24 migrations              │
                             └──────────┬─────────────────┘
                                        │
           ┌────────────────────────────┼─────────────────────────┐
           │                            │                         │
  ┌────────▼────────┐      ┌────────────▼──────┐     ┌───────────▼────────┐
  │  Operator Alice  │      │  Operator Bob     │     │  Operator Charlie  │
  │  ┌─────┐┌─────┐ │      │  ┌─────┐┌─────┐  │     │  ┌─────┐           │
  │  │Node1││Node2│ │      │  │Node1││Node2│  │     │  │Node1│           │
  │  │8cor ││8cor │ │      │  │16cor││4cor │  │     │  │32cor│           │
  │  └─────┘└─────┘ │      │  └─────┘└─────┘  │     │  └─────┘           │
  └──────────────────┘      └──────────────────┘     └────────────────────┘

Engine

The engine is the core Rust library implementing 12 prime search algorithms. Each form follows the same pipeline:

  1. Sieve — Eliminate composites using form-specific sieves (wheel factorization, BSGS, Montgomery multiplication)
  2. Filter — Deep composite elimination via adaptive Pollard P-1 (Stage 1 + Stage 2)
  3. Test — Miller-Rabin pre-screening (25 rounds), then specialized tests (Proth, LLR, Pepin). Frobenius RQFT for >10K-bit candidates
  4. Prove — Generate deterministic primality certificates (Pocklington, Morrison, BLS, Proth, LLR)
  5. Report — Log results to PostgreSQL with certificate data, update project progress

Key engine modules

ModulePurpose
src/sieve.rsEratosthenes sieve, Montgomery multiplication, BitSieve (packed u64), wheel factorization, BSGS
src/lib.rsTrial division, MR pre-screening, Frobenius RQFT, small primes table
src/proof.rsPocklington (N-1), Morrison (N+1), BLS deterministic proofs
src/verify.rs3-tier verification pipeline (deterministic → BPSW+MR → PFGW)
src/p1.rsPollard P-1 factoring with adaptive B1/B2 tuning
src/certificate.rsPrimalityCertificate enum (7 variants) for witness serialization
src/pfgw.rsPFGW subprocess integration (50-100x acceleration)
src/prst.rsPRST subprocess for k*b^n forms

12 search form modules

ModuleForm
factorial.rsn! ± 1
primorial.rsp# ± 1
kbn.rsk·b^n ± 1 (Proth/Riesel)
cullen_woodall.rsn·2^n ± 1
gen_fermat.rsb^(2^n) + 1
wagstaff.rs(2^p + 1) / 3
carol_kynea.rs(2^n ± 1)² − 2
twin.rsTwin primes (p, p+2)
sophie_germain.rsSophie Germain (p, 2p+1)
palindromic.rsPalindromic primes
near_repdigit.rsNear-repdigit palindromic
repunit.rsR(b,n) = (b^n − 1) / (b − 1)

AI Engine

The AI engine is an autonomous decision system that replaces manual tuning with a unified OODA (Observe → Orient → Decide → Act) loop running every 30 seconds:

  • WorldSnapshot — Consistent view of fleet, costs, records (~50ms via parallel DB queries)
  • 7-component scoring — record_gap, yield_rate, cost_efficiency, opportunity_density, fleet_fit, momentum, competition
  • Online learning — Weights updated via gradient descent on actual outcomes
  • Power-law cost model — OLS-fitted coefficients for compute time prediction
  • Drift detection — Automatic response to fleet changes, stalls, and discoveries

Server

The server is a modular Axum web application with 15 route modules:

Dashboard modules (src/dashboard/)

ModulePathPurpose
routes_health.rs/api/healthHealth check, readiness probes
routes_status.rs/api/statusCoordinator status summary
routes_workers.rs/api/workersWorker/node registration, heartbeat, pruning
routes_operator.rs/api/v1/operators, /api/v1/nodesOperator accounts, node management
routes_fleet.rs/api/fleetFleet overview (all nodes + searches)
routes_jobs.rs/api/search_jobsJob CRUD, work blocks, claiming
routes_searches.rs/api/searchesSearch management
routes_agents.rs/api/agentsAI agent tasks, budgets, memory, schedules
routes_projects.rs/api/projectsMulti-phase project campaigns
routes_verify.rs/api/verifyPrime re-verification
routes_docs.rs/api/docsDocumentation search and serving
routes_releases.rs/api/releasesWorker release channels, canary rollout
routes_observability.rs/api/observabilityMetrics, logs, performance charts
routes_notifications.rs/api/notificationsPush notification management
websocket.rs/wsReal-time push (2s interval)

Database modules (src/db/)

PostgreSQL access is split into 13 domain-specific submodules:

ModuleTables
primes.rsprimes (insert, query, filter, verify)
workers.rsworkers (heartbeat, registration, pruning)
jobs.rssearch_jobs, work_blocks (lifecycle, claiming)
agents.rsagent_tasks, agent_events, agent_budgets
memory.rsagent_memory (key-value store)
projects.rsprojects, project_phases, project_events
operators.rsoperators, operator_nodes
records.rsworld_records (t5k.org tracking)
calibrations.rscost_calibrations (power-law coefficients)
releases.rsworker_releases, rollout_events
observability.rsmetrics, worker_rates, logs
roles.rsagent_roles (configuration)
schedules.rsagent_schedules (automation)

Project orchestration (src/project/)

Campaign management is a separate module with its own submodules:

  • config.rs — TOML configuration parsing and validation
  • cost.rs — Power-law cost estimation model
  • orchestration.rs — Phase state machine, 30s tick loop
  • records.rs — World record tracking via t5k.org scraping
  • types.rs — Database row types for projects, phases, events

Frontends

Two separate Next.js 16 applications:

  • Website (website/) — Public-facing site at darkreach.ai. Landing page, documentation, blog, status, and leaderboard. Static export deployed to Vercel.
  • Dashboard (frontend/) — Operational dashboard at app.darkreach.ai. 17 pages including prime browser, search management, network monitoring, AI agent control, project campaigns, performance metrics, and system logs. React 19 + Tailwind 4 + shadcn/ui + Recharts. Supabase Auth for login. WebSocket for real-time coordination. PWA-enabled with offline support.

Data Flow

  1. AI engine scores forms and decides which searches to run
  2. Coordinator generates work blocks and inserts them into PostgreSQL
  3. Nodes claim blocks using FOR UPDATE SKIP LOCKED
  4. Nodes run the sieve → filter → test → prove pipeline
  5. Results (primes + certificates) are written back to PostgreSQL
  6. AI engine observes outcomes and updates scoring weights
  7. Project orchestrator tracks phase progress and manages budgets
  8. Dashboard queries PostgreSQL via Supabase for display
  9. WebSocket pushes real-time notifications for new primes and fleet status

Deployment

The production deployment runs on Hetzner Cloud:

  • Coordinator — CX22 instance running the Axum server, AI engine, and project orchestrator
  • Nodes — CCX23 instances (4+ cores) running darkreach in worker mode
  • Database — Supabase-hosted PostgreSQL (24 migrations)
  • Website — Vercel static deployment
  • Dashboard — Static export served by the coordinator
  • Monitoring — Prometheus metrics + Grafana dashboards

See the coordinator setup and worker deployment guides for detailed instructions.