// IT Nexus Dev Team — Lokaler KI-Entwickler-Agent // Start: node devteam.js // Dann: http://localhost:4242 const http = require('http'); const https = require('https'); const API_KEY = process.env.ANTHROPIC_API_KEY || ''; const PORT = 4242; // ─── IT Nexus Kontext für alle Agenten ──────────────────────────────────────── const IT_NEXUS_CONTEXT = ` # IT Nexus – Vollständiger Stack-Kontext ## Tech Stack - Backend: Node.js 18 + Express 4 + SQLite (better-sqlite3, SYNCHRON - kein await!) - Frontend: React 18 (Create React App) + Custom CSS (Glassmorphism) - Auth: JWT (jsonwebtoken) + bcryptjs - KI: @anthropic-ai/sdk (Claude claude-sonnet-4-6) - Deployment: Docker Compose + nginx auf LXC CT 102 (192.168.0.194) ## Dateistruktur Backend \`\`\` backend/src/ server.js – Express Setup, alle app.use() Registrierungen db/seed.js – Alle DB-Migrations (jede in try/catch, idempotent!) config/database.js – SQLite Verbindung via better-sqlite3 middleware/ auth.js – authenticateToken (JWT prüfen) roleCheck.js – requireAdmin, requireStaff Middleware errorHandler.js – asyncHandler(fn) Wrapper für alle Controller controllers/ – Business Logic, eine Datei pro Feature models/ – SQLite Queries, eine Datei pro Entity routes/ – Express Router, eine Datei pro Feature services/ – Externe APIs (Graph API, Proxmox, Anthropic) \`\`\` ## Dateistruktur Frontend \`\`\` frontend/src/ pages/ – Alle Seiten (NamingConvention: XxxPage.jsx) components/common/ AppLayout.jsx – Wrapper mit Sidebar + Topbar Sidebar.jsx – Navigation Topbar.jsx – Header context/AuthContext.jsx – Auth State, user Objekt services/api.js – Axios Instance mit Interceptors (IMMER verwenden!) \`\`\` ## Kritische Konventionen Backend 1. DB-Migration: Jedes ALTER TABLE / CREATE TABLE einzeln in try/catch in seed.js 2. Controller immer mit asyncHandler wrappen: const foo = asyncHandler(async (req, res) => {...}) 3. Statische Routen VOR /:id definieren (z.B. /statistics vor /:id) 4. better-sqlite3 ist SYNCHRON: db.prepare('...').get() – KEIN await! 5. Exports am Ende: module.exports = { foo, bar } ## Kritische Konventionen Frontend 1. IMMER import api from '../../services/api' – NIEMALS axios direkt importieren 2. IMMER user.role_name – NIEMALS user.role (falsches Feld!) 3. CSS Variablen verwenden: - Text: var(--text-primary), var(--text-secondary), var(--text-muted) - Hintergrund: var(--bg-card), var(--bg-secondary), var(--border-color) - Glassmorphism: backdrop-filter: blur(20px), rgba() Hintergründe 4. Rollen: super_admin, admin, support, bearbeiter, benutzer, hr_personal, buchhaltung 5. Neue Seite in AppLayout einbinden (Route in App.jsx) ## Deploy-Workflow \`\`\` scp datei.js root@192.168.0.194:/opt/it-nexus/backend/src/... docker cp /opt/it-nexus/backend/src/.../datei.js fido-backend:/app/src/.../ docker restart fido-backend # Frontend rebuild nur nötig wenn neue Seite/Komponente: docker compose build frontend && docker compose up -d frontend \`\`\` ## Beispiel: Neue Feature-Struktur Backend: controller + model + route + seed.js Migration + server.js Route registrieren Frontend: XxxPage.jsx + xxxService.js + Route in App.jsx + Link in Sidebar.jsx `; // ─── Agenten Definitionen ────────────────────────────────────────────────────── const AGENTS = { pm: { name: 'Project Manager', emoji: '📋', color: '#6366f1', system: `Du bist der Project Manager des IT Nexus Entwicklerteams. Du koordinierst alle anderen Agenten. ${IT_NEXUS_CONTEXT} Deine Aufgabe: 1. Analysiere die Anfrage des Benutzers 2. Erstelle einen klaren Implementierungsplan 3. Bestimme welche Spezialisten benötigt werden 4. Fasse am Ende alles zusammen Antworte auf Deutsch. Sei konkret und strukturiert. Nutze Markdown. Erkläre kurz was getan werden muss, dann liste die benötigten Schritte auf.` }, architect: { name: 'Architect', emoji: '🏗️', color: '#f59e0b', system: `Du bist der System-Architekt des IT Nexus Entwicklerteams. ${IT_NEXUS_CONTEXT} Deine Aufgabe: - Entscheide über DB-Schema (SQLite Spalten, Typen, Constraints) - Entscheide über API-Struktur (Endpoints, HTTP-Methoden, Auth-Level) - Entscheide über Datenfluss zwischen Frontend und Backend - Identifiziere Abhängigkeiten zu bestehenden Features Antworte auf Deutsch. Gib konkrete technische Entscheidungen. Format: DB-Schema → API-Endpoints → Abhängigkeiten → Besonderheiten` }, backend: { name: 'Backend Dev', emoji: '⚙️', color: '#10b981', system: `Du bist der Backend-Entwickler des IT Nexus Entwicklerteams. Du schreibst den kompletten Backend-Code. ${IT_NEXUS_CONTEXT} Deine Aufgabe: - Schreibe vollständige, lauffähige Node.js Dateien - Folge exakt den Konventionen (asyncHandler, better-sqlite3 synchron, etc.) - Jede Datei vollständig mit korrekten Imports und Exports - DB-Migrations in seed.js Format Format pro Datei: ### Datei: \`backend/src/pfad/dateiname.js\` \`\`\`javascript // kompletter Code \`\`\` Antworte auf Deutsch für Erklärungen, Code auf Englisch.` }, frontend: { name: 'Frontend Dev', emoji: '🎨', color: '#3b82f6', system: `Du bist der Frontend-Entwickler des IT Nexus Entwicklerteams. Du schreibst den kompletten Frontend-Code. ${IT_NEXUS_CONTEXT} Deine Aufgabe: - Schreibe vollständige React Komponenten (.jsx Dateien) - Glassmorphism Design (konsistent mit bestehendem IT Nexus Style) - IMMER api.get/post aus services/api.js verwenden - IMMER user.role_name verwenden - CSS inline mit var(--*) Variablen Format pro Datei: ### Datei: \`frontend/src/pfad/DateiName.jsx\` \`\`\`jsx // kompletter Code \`\`\` Antworte auf Deutsch für Erklärungen, Code auf Englisch.` }, senior: { name: 'Senior Dev', emoji: '🔍', color: '#ef4444', system: `Du bist der Senior Developer und Code Reviewer des IT Nexus Entwicklerteams. ${IT_NEXUS_CONTEXT} Deine Aufgabe: - Reviewe den generierten Code auf Bugs, Sicherheitsprobleme, Konventionsverletzungen - Prüfe ob alle Konventionen eingehalten wurden (user.role_name, api.js, asyncHandler, etc.) - Prüfe auf fehlende Error Handling - Prüfe auf fehlende Route-Registrierungen in server.js - Prüfe auf fehlende Sidebar-Links - Gib konkrete Fixes wenn nötig Format: ✅ Was gut ist ⚠️ Was fehlt / falsch ist + Fix 📝 Deploy-Befehl am Ende Antworte auf Deutsch.` }, qa: { name: 'QA Engineer', emoji: '🧪', color: '#8b5cf6', system: `Du bist der QA Engineer des IT Nexus Entwicklerteams. ${IT_NEXUS_CONTEXT} Deine Aufgabe: - Identifiziere potenzielle Edge Cases - Schreibe manuelle Testschritte die der Entwickler ausführen soll - Prüfe ob alle API-Endpoints abgesichert sind (Auth) - Prüfe Fehlerszenarien (leere Daten, falscher Input, fehlende Rechte) - Schreibe wenn möglich einen Playwright-Test Format: 📋 Manuelle Tests (nummeriert) 🔒 Security-Checks ⚡ Edge Cases (Optional) Playwright Test Code Antworte auf Deutsch.` } }; // ─── Anthropic API Aufruf ────────────────────────────────────────────────────── function callClaude(systemPrompt, messages, onChunk) { return new Promise((resolve, reject) => { const body = JSON.stringify({ model: 'claude-sonnet-4-6', max_tokens: 8096, system: systemPrompt, messages, stream: true }); const req = https.request({ hostname: 'api.anthropic.com', path: '/v1/messages', method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': API_KEY, 'anthropic-version': '2023-06-01', 'Content-Length': Buffer.byteLength(body) } }, (res) => { let full = ''; res.on('data', chunk => { const lines = chunk.toString().split('\n'); for (const line of lines) { if (line.startsWith('data: ')) { try { const d = JSON.parse(line.slice(6)); if (d.type === 'content_block_delta' && d.delta?.text) { full += d.delta.text; onChunk(d.delta.text); } } catch {} } } }); res.on('end', () => resolve(full)); res.on('error', reject); }); req.on('error', reject); req.write(body); req.end(); }); } // ─── Orchestrierung ──────────────────────────────────────────────────────────── async function runTeam(task, send) { const context = []; const runAgent = async (agentId, userMsg) => { const agent = AGENTS[agentId]; send({ type: 'agent_start', agent: agentId, name: agent.name, emoji: agent.emoji, color: agent.color }); const msgs = [...context, { role: 'user', content: userMsg }]; let full = ''; await callClaude(agent.system, msgs, chunk => { full += chunk; send({ type: 'chunk', agent: agentId, text: chunk }); }); send({ type: 'agent_done', agent: agentId }); context.push({ role: 'user', content: userMsg }); context.push({ role: 'assistant', content: full }); return full; }; // 1. PM analysiert const pmResult = await runAgent('pm', `Neue Aufgabe für das IT Nexus Entwicklerteam:\n\n"${task}"\n\nErstelle einen kurzen Implementierungsplan.` ); // 2. Architect entscheidet await runAgent('architect', `Aufgabe: "${task}"\n\nPM-Plan:\n${pmResult}\n\nGib deine technischen Entscheidungen für DB-Schema und API-Struktur.` ); // 3. Backend Dev schreibt Code const backendResult = await runAgent('backend', `Aufgabe: "${task}"\n\nSchreibe den vollständigen Backend-Code (Controller, Model, Route, seed.js Migration). Alle Dateien komplett.` ); // 4. Frontend Dev schreibt Code const frontendResult = await runAgent('frontend', `Aufgabe: "${task}"\n\nSchreibe den vollständigen Frontend-Code (Page, Service). Alle Dateien komplett.` ); // 5. Senior Dev reviewt await runAgent('senior', `Reviewe diesen Code:\n\n**Backend:**\n${backendResult}\n\n**Frontend:**\n${frontendResult}\n\nFinde Bugs, Konventionsverletzungen, fehlende Teile.` ); // 6. QA testet await runAgent('qa', `Aufgabe: "${task}"\n\nErstelle Testschritte und prüfe Edge Cases für die implementierte Funktion.` ); send({ type: 'done' }); } // ─── HTTP Server ─────────────────────────────────────────────────────────────── const HTML = ` IT Nexus Dev Team

IT Nexus Dev Team

6 KI-Agenten · Lokal · Nur für dich

🚀

Dein persönliches Dev Team

Beschreibe was du bauen möchtest. Das Team analysiert, plant, schreibt Code und reviewt alles automatisch.

⚡ PM → Architect → Backend Dev → Frontend Dev → Senior Dev → QA Engineer
`; const server = http.createServer((req, res) => { const url = new URL(req.url, `http://localhost:${PORT}`); // HTML if (req.method === 'GET' && url.pathname === '/') { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.end(HTML); return; } // Task API if (req.method === 'POST' && url.pathname === '/api/task') { let body = ''; req.on('data', c => body += c); req.on('end', async () => { try { const { task, apiKey } = JSON.parse(body); // API Key aus Request oder Umgebungsvariable const key = apiKey || API_KEY; if (!key) { res.writeHead(400, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Kein API Key' })); return; } res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*' }); const send = (data) => res.write(`data: ${JSON.stringify(data)}\n\n`); // Agenten mit aktuellem Key aufrufen const callAgent = (systemPrompt, messages) => new Promise((resolve, reject) => { const reqBody = JSON.stringify({ model: 'claude-sonnet-4-6', max_tokens: 8096, system: systemPrompt, messages, stream: true }); const apiReq = https.request({ hostname: 'api.anthropic.com', path: '/v1/messages', method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': key, 'anthropic-version': '2023-06-01', 'Content-Length': Buffer.byteLength(reqBody) } }, (apiRes) => { let full = ''; let buf = ''; apiRes.on('data', chunk => { buf += chunk.toString(); const lines = buf.split('\n'); buf = lines.pop(); for (const line of lines) { if (line.startsWith('data: ')) { try { const d = JSON.parse(line.slice(6)); if (d.type === 'content_block_delta' && d.delta?.text) { full += d.delta.text; send({ type: 'chunk', agent: currentAgent, text: d.delta.text }); } } catch {} } } }); apiRes.on('end', () => resolve(full)); apiRes.on('error', reject); }); apiReq.on('error', reject); apiReq.write(reqBody); apiReq.end(); }); let currentAgent = ''; const context = []; const runAgent = async (agentId, userMsg) => { currentAgent = agentId; send({ type: 'agent_start', agent: agentId }); const msgs = [...context, { role: 'user', content: userMsg }]; const full = await callAgent(AGENTS[agentId].system, msgs); send({ type: 'agent_done', agent: agentId }); context.push({ role: 'user', content: userMsg }); context.push({ role: 'assistant', content: full }); return full; }; // Team ausführen const pmResult = await runAgent('pm', `Neue Aufgabe:\n\n"${task}"\n\nErstelle einen kurzen klaren Implementierungsplan für das IT Nexus Entwicklerteam.` ); await runAgent('architect', `Aufgabe: "${task}"\n\nPM-Plan:\n${pmResult}\n\nEntscheide über DB-Schema, API-Endpoints und technische Architektur.` ); const backendResult = await runAgent('backend', `Aufgabe: "${task}"\n\nSchreibe jetzt den vollständigen Backend-Code. Alle Dateien komplett und lauffähig. Folge exakt den IT Nexus Konventionen.` ); const frontendResult = await runAgent('frontend', `Aufgabe: "${task}"\n\nSchreibe jetzt den vollständigen Frontend-Code. Alle Dateien komplett. Folge exakt den IT Nexus Konventionen.` ); await runAgent('senior', `Reviewe diesen Code:\n\nBACKEND:\n${backendResult}\n\nFRONTEND:\n${frontendResult}\n\nFinde alle Bugs, Konventionsverletzungen und fehlende Teile. Gib Fixes.` ); await runAgent('qa', `Aufgabe: "${task}"\n\nErstelle konkrete Testschritte, Security-Checks und Edge Cases.` ); send({ type: 'done' }); res.end(); } catch (e) { try { res.write(`data: ${JSON.stringify({ type: 'error', text: e.message })}\n\n`); res.end(); } catch {} } }); return; } res.writeHead(404); res.end(); }); server.listen(PORT, '127.0.0.1', () => { console.log(''); console.log('╔═══════════════════════════════════════╗'); console.log('║ IT Nexus Dev Team — Bereit! ║'); console.log('╠═══════════════════════════════════════╣'); console.log(`║ → http://localhost:${PORT} ║`); console.log('║ ║'); console.log('║ 6 Agenten: PM, Architect, ║'); console.log('║ Backend, Frontend, Senior, QA ║'); console.log('╚═══════════════════════════════════════╝'); console.log(''); if (!API_KEY) { console.log('⚠️ Kein ANTHROPIC_API_KEY gesetzt — im Browser eingeben'); console.log(' Oder: set ANTHROPIC_API_KEY=sk-ant-... && node devteam.js'); } console.log(''); });