feat: add fake-backend mock API server for frontend development

Create mock backend to simulate AI responses for UI development:

Backend Implementation:
- tools/fake-backend/server.js: Express server with CORS
- POST /api/analyze: Accepts log, returns mock AI analysis with 1.5s delay
- GET /health: Health check endpoint
- Pattern matching for different log types (PostgreSQL, Nginx, Node.js, Disk)
- Error handling: 400 for empty payload, 500 for server errors
- Mock responses for common errors (OOM, 502, connection refused, disk full)

Container Setup:
- Dockerfile: Node.js 20 Alpine container
- docker-compose.yml: Added fake-backend service on port 3000
- Health checks for both frontend and backend services
- Environment variable VITE_API_URL for frontend

Frontend Integration:
- InteractiveDemo.tsx: Replaced static data with real fetch() calls
- API_URL configurable via env var (default: http://localhost:3000)
- Error handling with user-friendly messages
- Shows backend URL in demo section
- Maintains loading states and UI feedback

Documentation:
- docs/tools_fake_backend.md: Complete usage guide
- README.md: Updated with tools/fake-backend structure and usage

Development Workflow:
1. docker compose up -d (starts both frontend and backend)
2. Frontend calls http://fake-backend:3000/api/analyze
3. Backend returns realistic mock responses
4. No OpenRouter API costs during development

Safety First:
- No real API calls during development
- Isolated mock logic in dedicated tool
- Easy switch to real backend by changing URL
- CORS enabled only for development

Refs: Sprint 4 preparation, API development workflow
This commit is contained in:
Luca Sacchi Ricciardi
2026-04-03 16:57:14 +02:00
parent eb24b86308
commit 8eb7dfb00e
9 changed files with 1490 additions and 84 deletions

View File

@@ -1,6 +1,7 @@
# Docker Compose - LogWhisperer AI Development Environment
# Usage: docker compose up -d
# Access: http://localhost:5173
# Access Frontend: http://localhost:5173
# Access Fake Backend API: http://localhost:3000
services:
frontend:
@@ -18,8 +19,11 @@ services:
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
- VITE_API_URL=http://fake-backend:3000
# Ensure container restarts on failure
restart: unless-stopped
depends_on:
- fake-backend
# Health check to verify the service is running
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:5173"]
@@ -28,6 +32,25 @@ services:
retries: 3
start_period: 40s
fake-backend:
build:
context: ./tools/fake-backend
dockerfile: Dockerfile
container_name: logwhisperer-fake-backend
ports:
- "3000:3000"
environment:
- PORT=3000
- DELAY_MS=1500
- NODE_ENV=production
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5s
volumes:
node_modules:
driver: local