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

@@ -237,6 +237,11 @@ LogWhispererAI/
├── tests/
│ ├── __init__.py
│ └── test_logwhisperer.py # Test suite Python
├── tools/
│ └── fake-backend/ # Mock API server per sviluppo frontend
│ ├── server.js # Server Express mock
│ ├── Dockerfile # Containerizzazione
│ └── README.md # Documentazione tool
└── .opencode/
├── opencode.json # Configurazione MCP servers
├── agents/ # Configurazioni agenti individuali
@@ -256,6 +261,31 @@ LogWhispererAI/
└── context7_documentation_retrivial/
```
## 🛠️ Tools di Sviluppo
### Fake Backend (Mock API)
Per sviluppare e testare il frontend senza dipendere dal backend reale:
```bash
# Avvia il mock API server
cd tools/fake-backend
npm install
node server.js
# Oppure con Docker
docker compose up fake-backend -d
```
**Endpoint:** `http://localhost:3000/api/analyze`
Simula le risposte AI con delay di 1.5s. Utile per:
- Sviluppo UI offline
- Testing senza costi API
- Demo senza dipendenze esterne
Vedi `docs/tools_fake_backend.md` per documentazione completa.
## ⚖️ Licenza e Note Legali
Questo software è **proprietà riservata** di Luca Sacchi Ricciardi.