Claude-skill-registry cliftonsites-backend
Use this skill when working with the CliftonSites Supabase backend for any task including understanding database schemas, debugging issues, adding features, querying data, managing RPC functions, reviewing triggers/policies, working with the automation pipeline, security architecture (MFA authentication, RLS, SECURITY DEFINER functions, API route protection), or any database operation. Provides complete expertise on all 12 tables, 25 RPC functions, 5 triggers, RLS policies, SECURITY DEFINER functions, admin MFA authentication, internal API token validation, views, indexes, data flows, and Supabase MCP server operations.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/cliftonsites-backend" ~/.claude/skills/majiayu000-claude-skill-registry-cliftonsites-backend && rm -rf "$T"
skills/data/cliftonsites-backend/SKILL.mdCliftonSites Backend Expert Skill
This skill provides complete, comprehensive expertise on the entire CliftonSites Supabase backend. Use this skill for ANY backend-related task - from simple queries to complex debugging to adding new features.
What This Skill Covers
- 12 Database Tables: Complete schemas, columns, constraints, relationships
- 25 RPC Functions: Full documentation, parameters, usage patterns, what they do
- 5 Database Triggers: What fires when, why, and how they integrate
- Security Architecture: MFA authentication, RLS policies, SECURITY DEFINER functions, API route protection
- RLS Policies: Row-level security for each table, who can access what (RLS enabled on ALL tables)
- 2 Views: v_queue_status, v_identification_progress
- Indexes: All performance optimizations
- Data Flows: How data moves through the system
- Automation Pipeline: VM integration, identification, implementation flows
- Admin Authentication: MFA-protected admin dashboard with TOTP
- API Route Protection: Internal API tokens, session validation
- Supabase MCP Server: Complete operations guide for any database task
Navigation Guide
This skill uses progressive disclosure - start here, then dive into detailed references as needed:
Core References (Read These for Deep Understanding)
-
- Complete schemas for all 12 tables./database-tables-reference.md- Full column definitions with types and constraints
- Relationships between tables
- Usage patterns and common queries
-
- All 25 RPC functions documented./rpc-functions-reference.md- Function signatures and parameters
- What each function does and when to use it
- Who can execute (permissions) - includes SECURITY DEFINER functions
- Internal logic and table dependencies
-
- Triggers, RLS, views, indexes./triggers-policies-views.md- All 5 active triggers: what fires when and why
- Complete RLS policies for each table (RLS enabled on ALL tables)
- 2 views with their definitions
- All indexes for performance
-
- System architecture and integration./data-flows-architecture.md- Complete data flow diagrams
- Automation pipeline architecture
- VM integration details
- User journey flows (including authentication)
- Admin dashboard authentication flow
- How everything connects
-
- Complete security documentation./security-architecture.md- MFA authentication (TOTP) for admin dashboard
- RLS policies and SECURITY DEFINER functions
- API route protection (internal tokens, session validation)
- Function permission matrix (anon vs service_role)
- Security verification queries
-
- Supabase MCP Server operations./supabase-mcp-guide.md- How to query tables
- How to call RPC functions
- How to check policies, triggers, schemas
- How to execute any SQL
- Complete MCP tool reference
-
- Common operations cheat sheet./quick-reference.md- Frequently used queries
- Common debugging commands
- Security verification queries
- Quick lookup for routine tasks
When to Use This Skill
Use this skill immediately when you need to:
Understanding the Backend
- "What tables exist in the database?"
- "How does the pipeline_businesses table work?"
- "What's the schema for qualified_businesses?"
- "What RPC functions are available?"
- "How does the automation system work?"
Debugging Issues
- "Why isn't a business showing in the queue?"
- "The outreach trigger isn't firing - why?"
- "What RLS policies affect this query?"
- "Why can't anon role access this table?"
- "What functions query pipeline_businesses?"
Adding Features
- "I need to add a new column to track X"
- "How do I create a new RPC function?"
- "Where should I store this new data?"
- "What's the pattern for adding automation commands?"
- "How do I trigger outreach for a business?"
Working with Data
- "Get all businesses in the queue"
- "Check automation status"
- "Query recent logs"
- "Find businesses by status"
- "Get current identification target"
Reviewing Configurations
- "What triggers exist on qualified_businesses?"
- "What are the RLS policies for automation tables?"
- "What indexes are on pipeline_businesses?"
- "Show me all SECURITY DEFINER functions"
- "What views are available?"
Security Operations
- "How does admin authentication work?"
- "What functions can anon role execute?"
- "Which tables have RLS enabled?"
- "How do internal API tokens work?"
- "What's protected by MFA?"
- "Verify the security configuration"
How to Use This Skill Effectively
Step 1: Identify Your Use Case
Ask yourself: "What am I trying to accomplish?"
- Quick lookup? → Use
./quick-reference.md - Understanding a table? → Use
./database-tables-reference.md - Working with functions? → Use
./rpc-functions-reference.md - Understanding data flow? → Use
./data-flows-architecture.md - Need to query? → Use
./supabase-mcp-guide.md
Step 2: Use the Right Tool
For Querying Data:
Use Supabase MCP server tools: - mcp__supabase__execute_sql - Run any SQL query - mcp__supabase__list_tables - See all tables
For Understanding Schema:
Read ./database-tables-reference.md for complete table schemas OR use: mcp__supabase__list_tables with project_id
For Calling Functions:
Use: mcp__supabase__execute_sql with SELECT function_name(params) Reference: ./rpc-functions-reference.md for function signatures
Step 3: Apply the Knowledge
Example Workflow: Adding a New Feature
- Read
to understand where data should go./database-tables-reference.md - Read
to see what functions already exist./rpc-functions-reference.md - Read
to understand integration points./data-flows-architecture.md - Use
to execute changes./supabase-mcp-guide.md - Check
to ensure triggers/policies are correct./triggers-policies-views.md
Example Workflow: Debugging an Issue
- Use
for common debugging queries./quick-reference.md - Use Supabase MCP to execute diagnostic queries
- Check
if issue relates to permissions or triggers./triggers-policies-views.md - Review
to understand expected behavior./data-flows-architecture.md - Use
to verify function logic./rpc-functions-reference.md
Common Operations Quick Start
Check Current Automation Status
// Use Supabase MCP mcp__supabase__execute_sql({ project_id: "anmmqjpsahrtmavdzotu", query: "SELECT * FROM automation_status" })
Get Queue Statistics
// Call RPC function mcp__supabase__execute_sql({ project_id: "anmmqjpsahrtmavdzotu", query: "SELECT * FROM get_queue_statistics()" })
Find a Business by UUID
mcp__supabase__execute_sql({ project_id: "anmmqjpsahrtmavdzotu", query: "SELECT * FROM qualified_businesses WHERE uuid = 'abc12345'" })
Check What Triggers Exist
mcp__supabase__execute_sql({ project_id: "anmmqjpsahrtmavdzotu", query: ` SELECT tgname, tgrelid::regclass, pg_get_triggerdef(oid) FROM pg_trigger WHERE tgisinternal = false ` })
See All RPC Functions
mcp__supabase__execute_sql({ project_id: "anmmqjpsahrtmavdzotu", query: ` SELECT proname, pg_get_function_arguments(oid) FROM pg_proc WHERE pronamespace = 'public'::regnamespace ORDER BY proname ` })
Key Architectural Concepts
Project ID
All Supabase operations use:
anmmqjpsahrtmavdzotu
Database Roles
- anon: Public access (used by admin dashboard via browser)
- authenticated: Logged-in users (future state after security hardening)
- service_role: Full access (used by API routes and VM)
Table Relationships
Pipeline Flow: pipeline_businesses → (VM implementation) → qualified_businesses → (outreach trigger) → Smartlead Automation Management: automation_config ← controls → automation_status automation_commands → processed by VM automation_runs ← logs runs automation_logs ← logs details Payment Flow: qualified_businesses ← stripe_webhook → stripe_events → stripe_idempotency
Security Architecture (Fully Implemented)
The system has comprehensive security hardening:
Admin Authentication (MFA Required)
- All
routes require authenticated session with MFA (AAL2)/admin/* - Login page:
(email/password + TOTP)/admin/login - MFA setup page:
(QR code enrollment)/admin/setup-mfa - Logout button in admin header
- Middleware redirects unauthenticated users to login
Database Security
- RLS enabled on ALL 12 tables
- Dangerous RPC functions revoked from
andanon
rolesPUBLIC - Dashboard functions use SECURITY DEFINER to bypass RLS safely
- All functions have
set to prevent SQL injectionsearch_path
API Route Protection
- Admin API routes validate session with MFA
- Internal routes (activate-site, stop-campaign) require
INTERNAL_API_SECRET - Stripe webhook validates signature
- Supabase trigger uses Bearer token for start-campaign
Function Permissions
- anon CAN execute:
,get_queue_statistics()
,get_current_identification_target()
(SECURITY DEFINER)get_automation_status() - anon CANNOT execute:
,claim_next_business()
,send_automation_command()
,update_automation_config()
,advance_identification_position()
,mark_business_deployed()reset_stale_started_businesses() - service_role: Can execute ALL functions (used by VM and API routes)
Integration Points
VM Automation (DigitalOcean 161.35.11.226)
Identification Process:
- Uses
keyservice_role - Calls:
,advance_identification_position()get_existing_businesses_for_target() - Inserts to:
pipeline_businesses - Logs to:
,automation_logsautomation_runs
Implementation Process:
- Uses
keyservice_role - Calls:
,claim_next_business()mark_business_deployed() - Reads from:
pipeline_businesses - Inserts to:
qualified_businesses
Admin Dashboard (cliftonsites.com/admin)
Authentication Required: MFA (TOTP) verified session
- Login Flow:
→ email/password → TOTP code → dashboard/admin/login - First-time MFA:
→ scan QR code → verify → dashboard/admin/setup-mfa - Uses
key in browser for Realtime subscriptionsanon - RPC calls via SECURITY DEFINER functions:
,get_queue_statistics()get_current_identification_target() - API routes for commands (require session):
,/api/admin/automation/command/api/admin/automation/config - Direct table queries via anon RLS policies:
,automation_config
,automation_status
,automation_logsautomation_runs
Outreach System (Smartlead)
- Trigger:
fires onoutreach_on_deployed
INSERT/UPDATEqualified_businesses - Calls:
with Bearer tokenPOST /api/outreach/start-campaign - Webhook:
receives events from SmartleadPOST /api/outreach/webhook-events - Updates:
columns inoutreach_*qualified_businesses
Payment System (Stripe)
- Webhook:
with signature verificationPOST /api/stripe-webhook - Logs to:
,stripe_eventsstripe_idempotency - Updates:
(claimed, stripe_payment_id, customer_email)qualified_businesses - Triggers: Site activation flow
Best Practices for Using This Skill
-
Start with the Right Reference
- Don't guess - look it up in the appropriate reference file
- The references are comprehensive - use them
-
Use Supabase MCP for All Database Operations
- Don't try to use psql or other tools
- The MCP server is your interface to Supabase
- See
for complete examples./supabase-mcp-guide.md
-
Understand the Data Flow
- Before changing anything, review
./data-flows-architecture.md - Understand how your change affects the pipeline
- Check if triggers will fire
- Before changing anything, review
-
Check Permissions
- Review
for RLS policies./triggers-policies-views.md - Understand which role is being used
- Verify access before querying
- Review
-
Reference Function Logic
- Don't assume - check
./rpc-functions-reference.md - Functions may have SECURITY DEFINER or INVOKER modes
- Some functions query tables that are RLS protected
- Don't assume - check
Troubleshooting Guide
"Permission denied" errors
- Check
for RLS policies on that table./triggers-policies-views.md - Verify which role you're using (anon vs service_role)
- Check if RLS is enabled on the table
"Function does not exist" errors
- Verify function name in
./rpc-functions-reference.md - Check schema (should be
)public - Ensure correct parameter types
"Trigger not firing" issues
- Review
for trigger definition./triggers-policies-views.md - Check if condition is met (INSERT vs UPDATE)
- Verify trigger is enabled
"Empty query results" issues
- Check if RLS is blocking access
- Verify data exists in table (use service_role if needed)
- Review WHERE clause conditions
Next Steps
Now that you understand how to use this skill:
- Read the reference that matches your task (see Navigation Guide above)
- Use the Supabase MCP guide to execute operations
- Refer back to this SKILL.md if you need to navigate
Remember: This skill contains COMPLETE documentation of the entire backend. Everything you need is here - just navigate to the right reference file.