Files
LogWhispererAI/docs/tools_fake_backend.md
Luca Sacchi Ricciardi 92217897ca fix: standardize project name to LogWhispererAI (no space)
- Replace all occurrences of 'LogWhisperer AI' with 'LogWhispererAI'
- Fix 47 instances across 30 files including:
  - Documentation (README, PRD, specs, docs)
  - Frontend components (Footer, Navbar, Hero, etc.)
  - Backend files (Dockerfile, server.js)
  - Workflow files (n8n, bash scripts)
  - Configuration files (AGENTS.md, LICENSE)

Ensures consistent branding across the entire codebase.
2026-04-03 17:07:35 +02:00

3.9 KiB

Fake Backend Tool

Strumento di sviluppo per simulare risposte API AI

Scopo: Permettere lo sviluppo e il testing del frontend senza dipendere dal backend reale o dalle API di OpenRouter.


📋 Descrizione

Il fake-backend è un server Node.js/Express che simula le risposte dell'API di LogWhispererAI. È progettato per:

  • Sviluppo UI: Testare l'interfaccia utente con risposte realistiche
  • Demo offline: Mostrare il prodotto senza connessione internet
  • Testing: Validare il flusso frontend senza costi API
  • Onboarding: Permettere ai nuovi sviluppatori di lavorare subito

🚀 Endpoint API

POST /api/analyze

Analizza un log e restituisce una risposta AI simulata.

Request:

POST http://localhost:3000/api/analyze
Content-Type: application/json

{
  "log": "FATAL: database system is out of memory"
}

Response (dopo 1.5s delay):

{
  "success": true,
  "analysis": {
    "title": "PostgreSQL Out of Memory",
    "description": "Il database ha esaurito la memoria disponibile...",
    "command": "ps aux | grep postgres | head -5 && free -h",
    "isSafe": true,
    "note": "Verifica processi Postgres e memoria disponibile."
  },
  "timestamp": "2026-04-03T10:30:00.000Z"
}

Errori gestiti:

  • 400 Bad Request: Payload vuoto o malformato
  • 500 Internal Error: Errore server generico

🛠️ Setup

Prerequisiti

  • Node.js 18+
  • npm 9+

Installazione

# Entra nella directory
cd tools/fake-backend

# Installa dipendenze
npm install

# Avvia il server
node server.js

Il server sarà disponibile su http://localhost:3000


🐳 Docker

Per avviare il fake backend con Docker:

# Dalla root del progetto
docker compose up fake-backend -d

Il servizio sarà esposto sulla porta 3000.


🔧 Configurazione

Variabili ambiente (opzionali):

PORT=3000              # Porta server (default: 3000)
DELAY_MS=1500          # Delay simulazione AI (default: 1500ms)

📁 Struttura

tools/fake-backend/
├── server.js          # Server Express principale
├── package.json       # Dipendenze npm
├── Dockerfile         # Containerizzazione
└── README.md          # Questo file

🔒 Sicurezza

⚠️ ATTENZIONE: Questo è uno strumento di sviluppo. NON usarlo in produzione:

  • Nessuna autenticazione implementata
  • Risposte statiche predefinite
  • Nessuna validazione input avanzata
  • CORS abilitato per tutte le origini

🧪 Test Manuale

# Test endpoint analyze
curl -X POST http://localhost:3000/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"log": "Error: Connection refused"}'

📝 Note per Sviluppatori

Aggiungere nuove risposte mock

Modifica l'oggetto MOCK_RESPONSES in server.js:

const MOCK_RESPONSES = {
  'errore-specifico': {
    title: 'Titolo Problema',
    description: 'Descrizione...',
    command: 'comando-da-eseguire',
    isSafe: true,
    note: 'Nota aggiuntiva'
  }
};

Pattern matching

Il server cerca keyword nel log e restituisce la risposta appropriata:

  • "memory" / "oom" → PostgreSQL OOM
  • "connection refused" / "502" → Nginx/Connection error
  • Default → Risposta generica

🤝 Integrazione Frontend

Per usare il fake backend dal frontend React:

const analyzeLog = async (log: string) => {
  const response = await fetch('http://localhost:3000/api/analyze', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ log })
  });
  return response.json();
};

🔄 Passaggio a Backend Reale

Quando il backend reale è pronto:

  1. Aggiorna l'URL in InteractiveDemo.tsx
  2. Aggiungi autenticazione (JWT/API Key)
  3. Rimuovi CORS permissivo
  4. Implementa rate limiting

Strumento creato seguendo il principio "Safety First" del Metodo Sacchi