AETHEX Implementation Status & Roadmap Audit

Date: Current Build Scope: Cross-reference AETHEX Technical Roadmap (Phases 1-4) against current codebase Status: 60% Implemented, 30% Partially Implemented, 10% Not Yet Implemented


Executive Summary

The AETHEX project has made significant progress on Discord integration (Phase 2: Dual-Auth) and database schema (Phase 2/3). However, critical gaps exist in CSP configuration (Phase 1), RLS performance optimization (Phase 3), and CI/CD pipeline (Phase 4).

Key Findings:

  • ✅ Discord OAuth backend fully implemented

  • ✅ Database schema for Discord integration complete

  • ✅ Discord bot (Discord.js) deployed and operational

  • ⚠️ CSP for Discord Activity partially configured (frame-ancestors missing)

  • ⚠️ RLS policies use per-row auth.uid() calls (performance anti-pattern)

  • ❌ CI/CD pipeline not yet established (GitHub Actions missing)


PHASE 1: Vercel CSP Configuration for Discord Activity Embedding

Current State

File: code/vercel.json

What's Configured ✅

Critical Issues ⚠️

  1. frame-ancestors 'none' - BLOCKS Discord Activity iFrame

    • Current policy: frame-ancestors 'none'

    • Required policy: frame-ancestors 'self' https://*.discordsays.com

    • Impact: Discord Activity cannot embed the app

  2. Missing Supabase URL in connect-src

    • Current: connect-src 'self' https: wss: (too broad, catch-all)

    • Should be explicit: connect-src 'self' https://kmdeisowhtsalsekkzqd.supabase.co https://xakdofkmympbhxkbkxbh.supabase.co wss:

  3. style-src 'unsafe-inline' still present

    • Acceptable for now (React UI libraries need this)

    • Consider replacing with nonces in future

Recommendation

Priority: CRITICAL - Blocking Discord Activity

Replace the CSP header in vercel.json line 47:


PHASE 2: Discord SDK Dual-Authentication Flow

Current State

Backend Implementation ✅ FULLY COMPLETE

File: code/api/discord/oauth/callback.ts (196 lines)

What's Working:

  • ✅ Receives Discord OAuth code

  • ✅ Exchanges code for Discord access token

  • ✅ Fetches user profile via Discord API

  • ✅ Creates/links user in Supabase

  • ✅ Sets session cookies (sb-access-token, sb-refresh-token)

  • ✅ Redirects to /onboarding or /dashboard

Code Flow (lines 48-120):

Verified Working: OAuth button in Login.tsx redirects to /api/discord/oauth/start → Discord auth → callback → dashboard

Frontend Implementation ⚠️ PARTIALLY COMPLETE

Files:

  • code/client/contexts/DiscordActivityContext.tsx (137 lines)

  • code/client/pages/Activity.tsx (152 lines)

What's Working:

  • ✅ Discord SDK initialization in context

  • ✅ Detects iFrame context (frame_id query param)

  • ✅ Calls /api/discord/activity-auth endpoint

  • ✅ Sets Supabase session

  • ✅ Activity page with profile display

What's Missing:

  • ❌ Custom dual-auth flow (Phase 2 Section A step 10)

    • Current: Uses standard supabase.auth.setSession()

    • Needed: Call discordSdk.commands.authenticate() with Discord token

    • Impact: Discord SDK commands unavailable inside Activity

Code Gap (DiscordActivityContext.tsx line ~80):

Recommendation

Priority: HIGH - Enables Discord Activity commands

Update code/client/contexts/DiscordActivityContext.tsx to complete the dual-auth flow:

  1. In the activity-auth response, include discord_token (not just Supabase session)

  2. After setSession(), call:


PHASE 3: Supabase RLS Performance Optimization

Current State

Files:

  • code/supabase/migrations/20250107_add_discord_integration.sql (line 62)

  • code/supabase/migrations/20250107_add_web3_and_games.sql (lines 108-121)

  • code/supabase/migrations/20251018_fix_team_memberships_rls.sql (lines 15, 21, 34)

RLS Policy Audit

Anti-Pattern Policies Found ⚠️

Policy 1: Discord Links (20250107_add_discord_integration.sql:62)

Policy 2: Web3 Nonces (20250107_add_web3_and_games.sql:109)

Policy 3: Team Memberships (20251018_fix_team_memberships_rls.sql:15)

Impact Analysis

  • Current behavior: Database calls auth.uid() for EVERY row scanned

  • Performance cost: O(n) where n = number of rows

  • Real-world: Querying 10,000 rows = 10,000 function calls

  • Observed symptoms: High database CPU, query timeouts (likely from advisor warnings)

Recommendation

Priority: HIGH - Resolves performance bottleneck

Create new migration: code/supabase/migrations/20250120_optimize_rls_auth_calls.sql

Apply the optimization pattern to ALL auth.uid() calls:

Complete Fix:

Verification: After applying migration, Supabase advisors should report resolved performance warnings.


PHASE 4: Establishing Supabase CI/CD Pipeline

Current State

Files: None found for .github/workflows/

What's Missing ❌

  1. GitHub Actions workflow file: .github/workflows/supabase-deploy.yml

    • Not created

    • Would handle automated schema deployments

  2. GitHub Environments:

    • No staging environment configured

    • No production environment configured

    • No repository secrets configured

  3. Local Development Setup:

    • No evidence of supabase start usage

    • No migration generation workflow documented

    • Migrations likely created manually or directly in dashboard

Recommendation

Priority: MEDIUM - Improves maintainability

Step 1: Create GitHub Actions Workflow

Create file: .github/workflows/supabase-deploy.yml

Step 2: Configure GitHub Environments

In repository settings (Settings → Environments):

Staging Environment:

  • Branch: develop

  • Secrets:

    • SUPABASE_ACCESS_TOKEN: Personal token from supabase.com/account/tokens

    • SUPABASE_PROJECT_ID: Project ID for aethex-staging

    • SUPABASE_DB_PASSWORD: Staging database password

Production Environment:

  • Branch: main

  • Secrets:

    • SUPABASE_ACCESS_TOKEN: (same as above)

    • SUPABASE_PROJECT_ID: Project ID for aethex-production

    • SUPABASE_DB_PASSWORD: Production database password

Step 3: Document Migration Workflow

Create: code/docs/SUPABASE_MIGRATION_WORKFLOW.md

  1. Edit migration in supabase/migrations/

  2. Test locally:

  3. Commit and push to feature branch

  4. Create PR against develop

  5. On merge to develop: Staging deployment triggered automatically

  6. After verification, merge developmain

  7. Production deployment triggered automatically

Last updated