Skip to Content
ConsoleSystem ModelingSequence Diagrams

Sequence Diagrams

Chat Conversation Flow with Supabase

This sequence diagram shows the actual chat flow using Supabase backend with multi-model AI support.

Performance Specifications:

OperationTarget LatencyMax LatencyNotes
Message Submit10ms20msBrowser to Edge
Input Validation5-10ms20msEdge Function
Context Load10-20ms50msRedis + DB
Claude 3 Opus200-400ms800msFirst token
Tool Execution100-300ms500msCredit operations
Response Stream50-100ms200msSSE streaming
Total E2E400-600ms1200msMessage to response

Optimization Strategies:

  • Stream responses as generated
  • Cache frequent queries
  • Preload user context
  • Batch tool executions
  • Use connection pooling

Authentication Sequence

This sequence diagram shows the complete authentication and authorization flow using Firebase Auth with JWT tokens.

JWT Token Structure:

{ "header": { "alg": "RS256", "typ": "JWT", "kid": "key_id_2024" }, "payload": { "sub": "user_uuid", "email": "user@example.com", "role": "user", "permissions": ["read:credit", "write:preferences"], "iat": 1705320000, "exp": 1705323600, "iss": "earna.ai", "aud": "earna-api" }, "signature": "..." }

Token Lifetimes:

  • Access Token: 1 hour
  • Refresh Token: 30 days
  • Session Cache: 1 hour (sliding window)

Token Storage:

  • Client: Secure storage (HttpOnly cookies or secure local storage)
  • Server: Redis for session caching
  • Keys: Cloud KMS for signing keys

Credit Analysis Flow

This sequence shows how credit score analysis and AI-powered recommendations are generated using Claude 4.

Credit Analysis Steps:

StepDurationDescriptionOutput
Authentication50msVerify user sessionUser context
Cache Check10msCheck for recent dataCached score or miss
Bureau Pull2-3sEquifax/TransUnion APIRaw credit data
Data Merge100msCombine bureau reportsUnified profile
Factor Analysis200msCalculate score factorsFactor breakdown
Issue Detection150msIdentify problemsIssue list
Score Simulation300msWhat-if scenariosSimulated scores
AI Recommendations500msGenerate advicePersonalized tips

Analysis Types:

  • Full credit report review
  • Quick score check
  • Simulation analysis
  • Improvement planning
  • Dispute assistance

REST API Sequence

This sequence diagram shows how REST API requests are handled for credit operations, including caching and tool execution.

REST API Processing:

  1. Request Validation

    • JWT token verification
    • Rate limit checking
    • Input sanitization
    • Permission validation
  2. Claude 4 Integration

    • Tool selection based on endpoint
    • Context preparation
    • Tool execution orchestration
    • Response formatting
  3. Caching Strategy

    • Key generation by user + endpoint
    • TTL based on data type
    • Cache invalidation on updates
    • Stale-while-revalidate pattern
  4. Response Handling

    • Consistent error format
    • Partial success support
    • Metadata inclusion
    • CORS headers
// Example API endpoint with Claude 4 export async function GET(request: Request) { const session = await getSession(request); const claude = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }); const response = await claude.messages.create({ model: 'claude-4-1-20250805', max_tokens: 1024, tools: creditTools, messages: [{ role: 'user', content: `Get credit score for user ${session.userId}` }] }); // Process tool calls const results = await executeToolCalls(response.tool_calls); return NextResponse.json({ score: results.score, factors: results.factors, recommendations: results.recommendations }); }
Last updated on