This document describes how to integrate the frontend with your real AI backend.
- Set environment variables:
# .env.local
NEXT_PUBLIC_USE_REAL_AI=true
NEXT_PUBLIC_API_URL=https://your-backend.com/api
NEXT_PUBLIC_MOCK_DELAY_MS=0 # Optional: remove simulated delays-
Restart the development server
-
All AI features will now call your real backend
Your backend must implement the following endpoints:
Endpoint: POST /tasks/generate-subtasks
Request Body:
{
title: string
description: string
context?: string // Optional: comma-separated tags
}Response:
{
subtasks: Array<{
id: string
title: string
description: string
status: "open" | "in_progress" | "completed"
assignedTo: User[]
createdAt: string // ISO 8601
updatedAt: string // ISO 8601
estimatedHours?: number
}>
}What it should do:
- Analyze the task title and description
- Generate 3-5 actionable subtasks
- Provide clear titles and descriptions
- Estimate hours if possible
Endpoint: POST /tasks/analyze-metrics
Request Body:
{
title: string
description: string
subtasks: Subtask[]
}Response:
{
metrics: Array<{
metric: string // e.g., "Impact", "Urgency", "Complexity"
value: number // 0-100
description: string
category: "impact" | "urgency" | "complexity" | "dependencies" | "risk"
}>
}What it should do:
- Analyze the task's importance and characteristics
- Return exactly 5 metrics with values 0-100
- Provide clear descriptions of why each metric has that value
- Cover: Impact, Urgency, Complexity, Dependencies, Risk
Endpoint: POST /matching/find-candidates
Request Body:
{
subtask: {
id: string
title: string
description: string
estimatedHours?: number
}
availableUserIds?: string[] // Optional: restrict to specific users
}Response:
{
matches: Array<{
user: User // Full user object
matchPercentage: number // 0-100
rank: 1 | 2 | 3 // Top 3 matches
reasoning: string // Explain why this match is good
skillMatches: string[] // Which skills matched
}>
}What it should do:
- Analyze subtask requirements
- Match against available users' skills
- Consider user availability (activeSubtasks count)
- Return top 3 matches ranked by fit
- Provide clear reasoning
Endpoint: POST /github/create-issues
Request Body:
{
taskTitle: string
subtasks: Array<{
subtaskId: string
assignedUserId: string
}>
repository?: string // e.g., "owner/repo"
projectBoard?: string // Optional project board
}Response:
{
issueUrls: string[] // One URL per subtask
projectUrl?: string // Project board URL if created
}What it should do:
- Create GitHub issue for each subtask
- Assign to the specified user (map userId to GitHub username)
- Add to project board if specified
- Return URLs to created issues
All endpoints should return appropriate HTTP status codes:
200- Success400- Bad request (invalid input)401- Unauthorized500- Server error
Error response format:
{
error: string
message: string
details?: any
}The frontend uses a service layer that abstracts API calls:
User Interaction
↓
UI Components
↓
Service Layer (services/ai-service.ts)
↓
API Client (services/api-client.ts)
↓
Your Backend API
Key Files:
services/ai-service.ts- Main AI service with mock implementationsservices/api-client.ts- HTTP client wrapperconfig/features.ts- Feature flags and configuration
-
Start with Mock Data:
- Set
NEXT_PUBLIC_USE_REAL_AI=false - Test UI flow with mock responses
- Set
-
Enable Real API:
- Set
NEXT_PUBLIC_USE_REAL_AI=true - Test each endpoint individually
- Set
-
Check Network Tab:
- Open browser DevTools
- Monitor API calls in Network tab
- Verify request/response formats
-
Error Scenarios:
- Test with invalid inputs
- Simulate API failures
- Check error messages display correctly
Default timeout is 30 seconds. Adjust in services/api-client.ts:
timeout: 30000 // millisecondsIf your API requires authentication, update api-client.ts:
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${YOUR_AUTH_TOKEN}`,
}Ensure your backend allows requests from your frontend domain.
| Feature | Mock (Current) | Real API (To Implement) |
|---|---|---|
| Subtask Generation | Template-based | AI-powered analysis |
| Metrics Analysis | Hash-based calculation | Real complexity analysis |
| User Matching | Simple keyword matching | ML-based recommendations |
| GitHub Integration | Fake URLs | Real issue creation |
| Response Time | ~1.5 seconds | Variable |
API calls not working?
- Check environment variables are set correctly
- Verify API URL is accessible
- Check browser console for errors
- Test API endpoints directly with curl/Postman
Seeing "Mock mode" errors?
USE_REAL_AIis still false- Restart dev server after changing env vars
Slow responses?
- Check
MOCK_DELAY_MSsetting - Monitor actual API response times
- Consider adding loading states
- Implement the 4 required endpoints
- Test each endpoint with curl/Postman
- Enable real API in frontend
- Test full flow end-to-end
- Monitor and optimize performance
For frontend issues or questions:
- Check
ARCHITECTURE.mdfor overall design - Review
IMPLEMENTATION_PLAN.mdfor details - Check service layer code for implementation examples