// SPDX-License-Identifier: GPL-3.0-only // Copyright (C) 2026 AlbiDR
This directory serves as the Single Source of Truth for the Clash-Manager backend infrastructure, leveraging a Binary Unitary Architecture to consolidate ingestion and scoring logic into a clinical, high-performance substrate.
The backend has transitioned from a distributed model (GAS/Node.js) into a streamlined Supabase-native environment.
- Structural Coherence: Database organization mirrors the CleanStack ADR (L0-L5) for perfect technical purity.
- Edge-Native Ingestion: Deno-powered Edge Functions (Supabase Functions) replace legacy workers.
- Realtime Orchestration: Native Postgres broadcasting for instant PWA dashboard updates.
| Path | Role | Description |
|---|---|---|
supabase/functions/ |
Edge Layer | Deno-native business logic and ingestion gates. |
supabase/migrations/ |
Substrate Layer | Relational DNA, triggers, and clinical schema definitions. |
supabase/config.toml |
Orchestration | Supabase project configuration and identity mapping. |
The project employs a strictly segmented schema strategy to maintain domain isolation:
- Role: Ingestion gatekeeper.
- Logic: Receives volatile raw state from Edge Functions. No processing logic.
- Privacy: Service-role internal only; strictly isolated from public access.
- Role: Persistence-ignorant domain objects and historical archives.
- Core Models:
drivers.members: The single authoritative source for active player telemetry.drivers.war_history: Infinite Career Ledger tracking every week since first sync (Unlimited History).drivers.player_battles: 100-Sample Rolling Window per resident for deep performance scoring.drivers.war_activity: Daily deck usage and participation logs.
- Role: Materialized views and API-ready logic for frontend consumption.
- Interfaces:
features.roster_view: Deeply sorted roster with dynamic tenure labeling.features.war_activity_view: Realtime participation tracking.features.war_loyalty_view: Career Fame Averaging (Infinite lookback for PeS calculation).
Ingestion is performed via a Tri-Engine Edge Architecture, supported by automated database shredders and the authoritative maintenance orchestrator.
- Gatekeeper (
ingest-royale-data): The primary Deno Edge Function responsible for the 6-stage clinical synchronization protocol:- S1 (Discovery): Harvests new recruits from high-fidelity tournament anchors.
- S2 (Profile): Synchronizes core clan metadata and settings.
- S3 (Members): Hydrates the active roster with realtime telemetry.
- S4 (Race): Captures current river race standing and deck availability.
- S5 (WarLog): Archives war performance into the infinite career ledger.
- S6 (Deep Depth): Extracts 100-sample battle logs for high-precision scoring.
- The Headhunter (
headhunter-scanner): A highly concurrent discovery engine featuring a 5-stage pipeline (Ghost Purge, Shadow Scout, Tournament Discovery, Profiler, Rescan). Relies on the Key Farm to handle concurrent batching without throttling. - User Proxy (
sync-player-cards): L5 Control Layer responsible for authenticated player profile and card synchronization. Implements rarity-relative normalization to the unified 1-16 absolute scale. - Shredder (
driverslayer): Automated SQL triggers and functions decompose raw JSON payloads into relational telemetry. - Nightly Orchestrator (
execute_nightly_maintenance): Authoritative system janitor responsible for pruning volatile state and maintaining substrate health.
The backend lifecycle is governed by the Supabase CLI and GitHub Actions.
The deploy-supabase.yml workflow automates the following sequence:
- Context Initialization: Changes within
Backend/**trigger the pipeline. - Secret Sync:
CLAN_TAGandPLAYER_TAGrepository variables are synced.ROYALE_API_KEYS(The Key Farm) is injected into the Supabase environment.
- Database DNA Sync: SQL migrations are pushed if
SUPABASE_DB_PASSWORDis present. - Edge Layer Deployment: The tri-engine cluster (
ingest-royale-data,headhunter-scanner, andsync-player-cards) is bundled and deployed.
# Start local development stack
supabase start
# Create a new migration file
supabase migration new <name>
# Local function testing
supabase functions serve ingest-royale-data --no-verify-jwt
# Deploy Edge Functions
supabase functions deploy ingest-royale-data --no-verify-jwt
supabase functions deploy headhunter-scanner --no-verify-jwt
supabase functions deploy sync-player-cards --no-verify-jwt| Constant | Source | Scope | Role |
|---|---|---|---|
ROYALE_API_KEYS |
GitHub Secret | Edge Function | The Key Farm (10 Supercell JWTs). |
CLAN_TAG |
GitHub Variable | Edge/Pipeline | The Targeted Clan Identifier (SSOT). |
PLAYER_TAG |
GitHub Variable | Edge/Pipeline | The Targeted Player Identifier (SSOT). |
| Secret | Role |
|---|---|
SUPABASE_ACCESS_TOKEN |
Authoritative CLI authentication. |
SUPABASE_PROJECT_ID |
Project Reference ID (hucktamloykszinwbtuh). |
SUPABASE_DB_PASSWORD |
Database DNA (Migration) synchronization password. |
- RLS Lockdown: Deny-by-default on all tables. Only specifically authorized
viewoperations are permitted for theanonrole. - Zero-Trust Boundary: High-fidelity validation of all inbound payloads at the Ingestion Gate level.
- Quota Guarding: Proactive management of free-tier storage (500MB) via the automated janitor cycle.
- Phase 1-6: Complete (Substrate, Domain Schema, Binary Heartbeat, Hardening, Deep Ingestion, Janitor).
- Phase 7 [PENDING]: Full PWA integration (migrating features to
features.*views).
Note
This README is a live document reflecting the evolving state of the Clash-Manager backend.
↴ Compiled: 2026-06-28 by Antigravity