Sequence Diagrams
Chat Conversation Flow with Supabase
This sequence diagram shows the actual chat flow using Supabase backend with multi-model AI support.
Timing Details
Performance Specifications:
Operation | Target Latency | Max Latency | Notes |
---|---|---|---|
Message Submit | 10ms | 20ms | Browser to Edge |
Input Validation | 5-10ms | 20ms | Edge Function |
Context Load | 10-20ms | 50ms | Redis + DB |
Claude 3 Opus | 200-400ms | 800ms | First token |
Tool Execution | 100-300ms | 500ms | Credit operations |
Response Stream | 50-100ms | 200ms | SSE streaming |
Total E2E | 400-600ms | 1200ms | Message 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.
Token Details
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.
Analysis Steps
Credit Analysis Steps:
Step | Duration | Description | Output |
---|---|---|---|
Authentication | 50ms | Verify user session | User context |
Cache Check | 10ms | Check for recent data | Cached score or miss |
Bureau Pull | 2-3s | Equifax/TransUnion API | Raw credit data |
Data Merge | 100ms | Combine bureau reports | Unified profile |
Factor Analysis | 200ms | Calculate score factors | Factor breakdown |
Issue Detection | 150ms | Identify problems | Issue list |
Score Simulation | 300ms | What-if scenarios | Simulated scores |
AI Recommendations | 500ms | Generate advice | Personalized 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.
Query Processing
REST API Processing:
-
Request Validation
- JWT token verification
- Rate limit checking
- Input sanitization
- Permission validation
-
Claude 4 Integration
- Tool selection based on endpoint
- Context preparation
- Tool execution orchestration
- Response formatting
-
Caching Strategy
- Key generation by user + endpoint
- TTL based on data type
- Cache invalidation on updates
- Stale-while-revalidate pattern
-
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