Axiom Model: Phase 1 Code Migration Scope
Moving Identity from aethex.dev (Vercel) to aethex.foundation (Replit)
Status: CRITICAL P0 (Blocks NEXUS & FOUNDATION work) Date: 2025-11-16 Objective: Copy all auth/identity code from Corp (aethex.dev) to Guardian (aethex.foundation)
1. PAGES TO COPY
Authentication & Onboarding Pages
code/client/pages/Login.tsx
Login UI + Discord OAuth button
Copy as-is; validate Discord button routing
code/client/pages/Signup.tsx
(if exists) User registration
Copy if present
code/client/pages/Onboarding.tsx
Realm/arm selection, profile setup
Copy all onboarding flow
code/client/pages/DiscordVerify.tsx
Verification code entry for linking
Copy verification flow
Profile & Settings Pages
code/client/pages/Profile.tsx
(or Dashboard) User profile view
Copy public profile viewing
code/client/pages/Dashboard.tsx
User dashboard + OAuthConnections
Copy OAuth linking UI
code/client/pages/settings/*
Profile settings, password reset, etc.
Copy all settings pages
Passport Pages
code/client/pages/SubdomainPassport.tsx
Creator passport for *.aethex.me
Copy; will fetch from Foundation API
2. CONTEXTS & STATE MANAGEMENT
code/client/contexts/AuthContext.tsx
Central auth state, loginProvider, linkProvider
Depends on Supabase client
code/client/contexts/DiscordActivityContext.tsx
Discord Activity SDK state
Optional; copy if Activity is needed
code/client/contexts/ThemeContext.tsx
Theme switching
Dependency; copy
3. COMPONENTS TO COPY
Auth & OAuth Components
code/client/components/settings/OAuthConnections.tsx
OAuth provider cards (Discord, etc.)
code/client/components/admin/AdminDiscordManagement.tsx
Admin UI for role mappings (optional for Phase 1)
Profile & Passport Components
code/client/components/passport/PassportSummary.tsx
Renders creator passport
code/client/components/ErrorBoundary.tsx
Error handling
code/client/components/LoadingScreen.tsx
Loading UI
code/client/components/Layout.tsx
App layout & header
Shared UI Components
code/client/components/ui/*
All Radix UI & design system components
4. API ENDPOINTS & SERVERLESS FUNCTIONS TO COPY
Discord OAuth Endpoints
code/api/discord/oauth/start.ts
GET /api/discord/oauth/start
Redirect to Discord authorization
code/api/discord/oauth/callback.ts
GET /api/discord/oauth/callback
Handle Discord callback, link user
code/api/discord/verify-code.ts
POST /api/discord/verify-code
Verify 6-digit code for linking
code/api/discord/link.ts
POST /api/discord/link
Link Discord account by code
code/api/discord/sync-roles.ts
POST /api/discord/sync-roles
Assign Discord roles after linking
Profile & Auth Endpoints
code/api/profile/ensure.ts
POST /api/profile/ensure
Create or ensure user profile exists
code/api/user/*
Various
User data endpoints (review for auth deps)
Passport Endpoints
code/api/passport/subdomain/[username].ts
GET /api/passport/subdomain/:username
Creator passport JSON API
code/api/passport/project/[slug].ts
GET /api/passport/project/:slug
Project passport JSON API
5. DATABASE MIGRATIONS TO COPY
code/supabase/migrations/20250107_add_discord_integration.sql
Discord tables (discord_links, discord_verifications, discord_role_mappings)
All other user/auth-related migrations
Copy all identity-related schema
Supabase Tables Required:
user_profilesuser_auth_identitiesdiscord_linksdiscord_verificationsdiscord_role_mappings
6. LIBRARIES & DEPENDENCIES
Required npm packages (verify in aethex.dev package.json)
Environment Variables Needed
7. CRITICAL ADAPTATIONS FOR REPLIT TARGET
Vercel serverless functions (code/api/*)
Express or Remix server endpoints on Replit
VITE_API_BASE=https://aethex.dev
VITE_API_BASE=https://aethex.foundation
Vite + React on Vercel
Vite + React on Replit (same)
Uses Vercel environment variables
Use Replit Secrets or .env
Key Refactoring Points
API Endpoints: Vercel's
/api/*files may need conversion to Express routes incode/server/index.tsor equivalent Replit server.Base URLs: Update all
VITE_API_BASEreferences to point toaethex.foundationinstead ofaethex.dev.OAuth Redirect URIs: Update Discord OAuth app to use
aethex.foundationcallback URL.CORS: Ensure Foundation server allows requests from Corp domain (
aethex.dev).
8. NEW SSO ENDPOINTS TO BUILD (Foundation)
After copying existing code, build 3 new OAuth 2.0 endpoints on aethex.foundation:
1. /authorize (Foundation SSO Authorization)
/authorize (Foundation SSO Authorization)Purpose: Initiate login flow for external apps (aethex.dev)
Response: Redirect user to /login with state preserved
2. /token (Foundation SSO Token Exchange)
/token (Foundation SSO Token Exchange)Purpose: Exchange auth code for JWT token
3. /userinfo (Foundation SSO User Info)
/userinfo (Foundation SSO User Info)Purpose: Fetch current logged-in user info (used by aethex.dev after login)
9. MIGRATION CHECKLIST
Before Starting Phase 1
During Phase 1
Testing Phase 1
10. SUCCESS CRITERIA FOR PHASE 1
✅ All auth pages render correctly on aethex.foundation ✅ Users can log in via Discord on aethex.foundation ✅ Users can link additional accounts (Google, etc.) ✅ Passports display correctly ✅ All OAuth callbacks complete without errors ✅ Supabase access is working (read/write to user_profiles) ✅ Code is ready for Phase 2 (permission migration)
11. ESTIMATED EFFORT
Audit & document auth code
2-3 hours
Copy & adapt page files
4-6 hours
Copy & adapt API endpoints
3-4 hours
Fix imports & dependencies
2-3 hours
Test login flow
2-3 hours
Build SSO endpoints
4-6 hours
Total Phase 1
17-25 hours
12. BLOCKERS & RISKS
Risk 1: API endpoints on Vercel may not work on Replit without refactoring → Mitigation: Convert to Express routes on Replit server
Risk 2: Environment variable names differ between Vercel and Replit → Mitigation: Use consistent naming convention
Risk 3: Supabase RLS policies may prevent new app from writing to tables → Mitigation: Phase 2 handles permission migration
Risk 4: Discord OAuth app may not accept aethex.foundation as redirect URI → Mitigation: Update Discord app settings before testing
Next Steps
Review & Approve Scope: Confirm this list is complete
Set up Replit Structure: Create mirrored directories on aethex.foundation
Start Code Copy: Begin with pages, then contexts, then components
Adapt & Test: Fix imports, test each piece as copied
Proceed to Phase 2: Once Phase 1 is solid, move to database permission migration
Last updated
