Skip to main content

⚙️ Backend Development Strategy

Backend architecture should be chosen based on discovery phase findings about scale, real-time needs, and team expertise

Supabase

Best for: Rapid development, real-time features, built-in auth

FastAPI

Best for: Python teams, ML integration, high performance

LangGraph

Best for: AI workflows, stateful processes, agent systems

Pre-Implementation Research Process

Always research before implementing. Use this two-step process for optimal results
1

Research Phase with Codex/Sonnet

I need to implement [FEATURE] with these requirements:
- [Requirement from discovery]
- Scale: [Expected load from discovery]
- Real-time: [Yes/No from discovery]

Current stack: [Your chosen stack]

Please suggest:
1. Database schema design
2. API structure
3. Caching strategy
4. Security considerations
5. Performance optimizations
6. Edge cases to handle
2

Implementation with Claude Code

Based on this architecture review from [Codex/Sonnet]:
[Paste research findings]

And these discovery requirements:
- [Specific requirement]
- [Performance target]
- [Security requirement]

Now implement:
1. Database migrations
2. RLS policies (if Supabase)
3. API endpoints with validation
4. Error handling
5. Client-side hooks
6. Tests

Follow our established patterns from [reference files]

Backend Architecture Patterns

  • Supabase Architecture
  • FastAPI Architecture
  • LangGraph Workflows

Complete Supabase Setup

Ideal for most SaaS applications with real-time needs
1

Database Design

-- From discovery data requirements

-- Users and profiles
CREATE TABLE profiles (
  id UUID PRIMARY KEY REFERENCES auth.users(id),
  email TEXT UNIQUE NOT NULL,
  full_name TEXT,
  avatar_url TEXT,
  role user_role NOT NULL DEFAULT 'user',
  metadata JSONB DEFAULT '{}',
  created_at TIMESTAMPTZ DEFAULT NOW(),
  updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Enable RLS
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;

-- Policies based on discovery requirements
CREATE POLICY "Users can view own profile"
  ON profiles FOR SELECT
  USING (auth.uid() = id);

CREATE POLICY "Users can update own profile"
  ON profiles FOR UPDATE
  USING (auth.uid() = id);

-- Indexes for performance
CREATE INDEX idx_profiles_email ON profiles(email);
CREATE INDEX idx_profiles_role ON profiles(role);
2

Edge Functions

// supabase/functions/process-payment/index.ts
import { serve } from 'https://deno.land/[email protected]/http/server.ts'
import { createClient } from '@supabase/supabase-js'

serve(async (req) => {
  try {
    const supabase = createClient(
      Deno.env.get('SUPABASE_URL')!,
      Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
    )

    const { amount, userId } = await req.json()

    // Process payment logic
    const result = await processPayment(amount)

    // Update database
    await supabase
      .from('payments')
      .insert({ user_id: userId, amount, status: 'completed' })

    return new Response(JSON.stringify(result), {
      headers: { 'Content-Type': 'application/json' },
    })
  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
      status: 400,
      headers: { 'Content-Type': 'application/json' },
    })
  }
})
3

Real-time Subscriptions

// Real-time features from discovery
const channel = supabase
  .channel('room-1')
  .on('postgres_changes', {
    event: '*',
    schema: 'public',
    table: 'messages'
  }, (payload) => {
    handleNewMessage(payload.new)
  })
  .on('presence', { event: 'sync' }, () => {
    const state = channel.presenceState()
    updateOnlineUsers(state)
  })
  .subscribe()

Next Step

With backend architecture defined, proceed to testing strategies →