commit dbe08b48145b0943977990f476cd44d18239bc4d Author: Christian Mueller Date: Thu Mar 19 22:07:32 2026 +0100 chore: initial setup KI-Agenten Toolkit 10 wiederverwendbare Claude Code Skills für React + Node.js Webprojekte: - code-gen, security, git-push, ssh-deploy, test-runner - docker-build, project-init, log-analyzer, dep-check, workflow Co-Authored-By: Claude Opus 4.6 (1M context) diff --git a/.claude/skills/code-gen.md b/.claude/skills/code-gen.md new file mode 100644 index 0000000..89a0cfc --- /dev/null +++ b/.claude/skills/code-gen.md @@ -0,0 +1,56 @@ +--- +name: code-gen +description: Generiert React Frontend und Node.js/Express Backend Code nach Best Practices +user_invocable: true +--- + +Du bist ein Code-Generator für React + Node.js Webprojekte. + +## FRONTEND-REGELN (React) +- TypeScript mit strikten Types +- Functional Components mit Hooks +- Props-Interface immer definieren +- Error Boundaries für kritische Komponenten +- Loading/Error States berücksichtigen +- Responsive Design (Mobile-First) +- Styling: Tailwind CSS oder CSS Modules + +## BACKEND-REGELN (Node.js/Express) +- Express mit TypeScript +- Controller/Service/Repository Pattern +- Input-Validierung auf allen Endpoints (Zod) +- Async/Await mit try/catch +- Strukturierte Error-Responses mit HTTP Status Codes +- Environment-Variables für Konfiguration (.env) + +## DATEISTRUKTUR + +Frontend: +``` +src/ + components/ # React-Komponenten + hooks/ # Custom Hooks + services/ # API-Calls + types/ # TypeScript Interfaces + utils/ # Hilfsfunktionen + pages/ # Seiten/Routes +``` + +Backend: +``` +src/ + controllers/ # Route-Handler + services/ # Business-Logik + models/ # Datenbank-Models + middleware/ # Express Middleware + routes/ # Route-Definitionen + utils/ # Hilfsfunktionen + types/ # TypeScript Interfaces +``` + +## REGELN +- Keine hardcoded Credentials +- Kommentare nur wo nötig +- DRY-Prinzip +- SOLID-Prinzipien +- Jede Komponente/Service in eigener Datei diff --git a/.claude/skills/dep-check.md b/.claude/skills/dep-check.md new file mode 100644 index 0000000..ceadc18 --- /dev/null +++ b/.claude/skills/dep-check.md @@ -0,0 +1,74 @@ +--- +name: dep-check +description: Dependency-Check - veraltete und unsichere npm Packages erkennen und updaten +user_invocable: true +--- + +Du bist ein Dependency-Manager für Node.js Projekte. + +## ANALYSE + +### Vulnerabilities finden +```bash +npm audit --json +npm audit --audit-level=moderate +``` + +### Veraltete Packages +```bash +npm outdated +``` + +### Package-Größe prüfen +```bash +npx cost-of-modules # (falls installiert) +du -sh node_modules/ # Grobe Größe +``` + +## BEWERTUNG + +### Severity-Klassifizierung +- **Critical/High**: Sofort updaten - bekannte Exploits +- **Moderate**: Im nächsten Sprint updaten +- **Low**: Bei nächstem Major-Update berücksichtigen + +### Update-Strategie +1. `npm audit fix` - Automatische sichere Updates (Patch/Minor) +2. `npm audit fix --force` - NUR nach Review (kann Breaking Changes haben) +3. Manuell: Package-by-Package bei Major Updates + +## VORGEHEN + +1. `npm audit --json` ausführen und analysieren +2. `npm outdated` ausführen +3. Ergebnisse nach Schweregrad sortieren +4. Für jedes kritische Package: + - Changelog prüfen + - Breaking Changes identifizieren + - Update-Empfehlung geben +5. Sichere Updates durchführen +6. Tests ausführen nach Update + +## OUTPUT-FORMAT +``` +## Dependency-Check Ergebnis + +### Vulnerabilities +| Package | Aktuell | Fix-Version | Severity | CVE | +|---------|---------|-------------|----------|-----| + +### Veraltete Packages +| Package | Aktuell | Wanted | Latest | Typ | +|---------|---------|--------|--------|-----| + +### Empfehlung +1. Sofort: ... +2. Bald: ... +3. Beobachten: ... +``` + +## REGELN +- Vor Updates immer `package-lock.json` committen (Rollback-Möglichkeit) +- Nach Updates: `npm test` ausführen +- Major-Version Updates einzeln durchführen, nicht gebündelt +- `node_modules` nie committen diff --git a/.claude/skills/docker-build.md b/.claude/skills/docker-build.md new file mode 100644 index 0000000..bbfca09 --- /dev/null +++ b/.claude/skills/docker-build.md @@ -0,0 +1,133 @@ +--- +name: docker-build +description: Dockerfile und docker-compose.yml generieren und optimieren für React + Node.js +user_invocable: true +--- + +Du bist ein Docker-Agent für React + Node.js Webprojekte. + +## DOCKERFILE BEST PRACTICES + +### Backend (Node.js/Express) +```dockerfile +FROM node:20-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci --only=production +COPY . . +RUN npm run build + +FROM node:20-alpine +WORKDIR /app +RUN addgroup -g 1001 appgroup && adduser -u 1001 -G appgroup -s /bin/sh -D appuser +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./ +USER appuser +EXPOSE 4000 +HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:4000/health || exit 1 +CMD ["node", "dist/index.js"] +``` + +### Frontend (React) +```dockerfile +FROM node:20-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM nginx:alpine +COPY --from=builder /app/build /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost/ || exit 1 +``` + +## DOCKER-COMPOSE TEMPLATE +```yaml +version: '3.8' + +services: + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + ports: + - "${FRONTEND_PORT:-3000}:80" + depends_on: + backend: + condition: service_healthy + restart: unless-stopped + + backend: + build: + context: ./backend + dockerfile: Dockerfile + ports: + - "${BACKEND_PORT:-4000}:4000" + env_file: + - .env + depends_on: + db: + condition: service_healthy + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "-qO-", "http://localhost:4000/health"] + interval: 30s + timeout: 3s + retries: 3 + + db: + image: postgres:16-alpine + volumes: + - pgdata:/var/lib/postgresql/data + environment: + POSTGRES_DB: ${DB_NAME:-myapp} + POSTGRES_USER: ${DB_USER:-app} + POSTGRES_PASSWORD: ${DB_PASSWORD} + ports: + - "${DB_PORT:-5432}:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-app}"] + interval: 10s + timeout: 5s + retries: 5 + restart: unless-stopped + +volumes: + pgdata: +``` + +## REGELN +- Multi-Stage Builds für kleinere Images +- Non-root User im Container +- Healthchecks immer definieren +- `.dockerignore` erstellen (node_modules, .git, .env, logs) +- Secrets NIEMALS im Image - nur via env_file oder Docker Secrets +- Alpine-basierte Images bevorzugen +- `npm ci` statt `npm install` im Build +- Layer-Caching optimieren (package.json vor Source kopieren) + +## .DOCKERIGNORE +``` +node_modules +.git +.env +*.log +dist +.DS_Store +coverage +.nyc_output +``` + +## NÜTZLICHE BEFEHLE +```bash +docker compose up -d --build # Build und Start +docker compose logs -f # Logs folgen +docker compose ps # Status +docker compose down # Stop und Remove +docker compose exec backend sh # Shell im Container +docker system prune -f # Cleanup +``` diff --git a/.claude/skills/git-push.md b/.claude/skills/git-push.md new file mode 100644 index 0000000..725c354 --- /dev/null +++ b/.claude/skills/git-push.md @@ -0,0 +1,61 @@ +--- +name: git-push +description: Git-Operationen für Gitea (git.cynfo.net) - Commit, Push, Branch, PR +user_invocable: true +--- + +Du bist ein Git-Agent für Gitea (git.cynfo.net). + +## KONFIGURATION +- Gitea URL: `$GITEA_URL` (default: https://git.cynfo.net) +- Gitea API: `$GITEA_URL/api/v1` +- Auth: Token aus `$GITEA_TOKEN` +- User: `$GITEA_USER` + +## COMMIT-KONVENTIONEN +Format: `(): ` + +Types: +- `feat`: Neue Features +- `fix`: Bugfixes +- `docs`: Dokumentation +- `style`: Formatierung +- `refactor`: Code-Refactoring +- `test`: Tests +- `chore`: Maintenance +- `security`: Sicherheitsfixes + +## BRANCH-NAMING +- `feature/` +- `bugfix/` +- `hotfix/` +- `release/` + +## WORKFLOW + +### Vor jedem Commit +1. `git status` prüfen +2. Prüfe: Keine `.env`, Credentials oder API-Keys im Commit +3. `.gitignore` muss enthalten: `node_modules/`, `.env`, `*.log`, `dist/` +4. Staged Files reviewen + +### Commit & Push +```bash +git add # NICHT git add -A ohne Review +git commit -m "" +git push origin +``` + +### PR erstellen (Gitea API) +```bash +curl -X POST -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{"title":"","body":"","head":"","base":"main"}' \ + "$GITEA_URL/api/v1/repos/$GITEA_USER/$REPO/pulls" +``` + +## SICHERHEIT +- NIEMALS Credentials committen +- Token nur aus Environment-Variablen +- Vor Push: `git diff --cached` prüfen +- Kein `--force` ohne explizite Bestätigung diff --git a/.claude/skills/log-analyzer.md b/.claude/skills/log-analyzer.md new file mode 100644 index 0000000..d25f602 --- /dev/null +++ b/.claude/skills/log-analyzer.md @@ -0,0 +1,88 @@ +--- +name: log-analyzer +description: Remote-Logs per SSH holen, parsen und Fehlerursachen identifizieren +user_invocable: true +--- + +Du bist ein Log-Analyzer. Du holst Logs von Remote-Servern, analysierst sie und identifizierst Fehlerursachen. + +## LOG-QUELLEN + +### Application Logs +```bash +# PM2 +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST "pm2 logs --lines 200 --nostream" +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST "pm2 logs --err --lines 200 --nostream" + +# Docker +ssh ... "docker logs --tail 200 " +ssh ... "docker compose logs --tail 200 backend" + +# Systemd +ssh ... "journalctl -u myapp --since '2 hours ago' --no-pager" + +# Log-Dateien +ssh ... "tail -200 /var/log/app/error.log" +ssh ... "tail -200 /var/log/app/access.log" +``` + +### System Logs +```bash +ssh ... "journalctl --since '1 hour ago' --priority err --no-pager" +ssh ... "dmesg | tail -50" +``` + +### Nginx/Reverse Proxy +```bash +ssh ... "tail -100 /var/log/nginx/error.log" +ssh ... "tail -100 /var/log/nginx/access.log" +``` + +## ANALYSE-PROZESS + +1. **Error-Pattern erkennen**: Stack Traces, Error Codes, Exceptions +2. **Zeitliche Korrelation**: Wann traten die Fehler auf? Häufung? +3. **Kategorisierung**: + - Application Error (Code-Bug) + - Infrastructure Error (Disk, Memory, Network) + - Configuration Error (Missing env vars, wrong ports) + - Dependency Error (DB down, External API timeout) +4. **Root Cause Analysis**: Was ist die eigentliche Ursache? +5. **Fix-Empfehlung**: Konkreten Lösungsvorschlag geben + +## HÄUFIGE PATTERNS + +| Pattern | Ursache | Fix | +|---------|---------|-----| +| `ECONNREFUSED` | Service nicht erreichbar | Port/Service prüfen | +| `ENOMEM` | Out of Memory | Memory-Limit erhöhen / Memory Leak finden | +| `ENOSPC` | Disk voll | Logs rotieren, alte Files löschen | +| `EACCES` | Permission Problem | Dateiberechtigungen prüfen | +| `JWT malformed` | Token-Problem | Token-Generierung prüfen | +| `ETIMEOUT` | DB/API Timeout | Connection Pool, Netzwerk prüfen | + +## SYSTEM-HEALTH CHECK +```bash +ssh ... "echo '=== DISK ===' && df -h && echo '=== MEMORY ===' && free -m && echo '=== LOAD ===' && uptime && echo '=== PROCESSES ===' && ps aux --sort=-%mem | head -10" +``` + +## OUTPUT-FORMAT +``` +## Log-Analyse Ergebnis + +### Zusammenfassung +- Zeitraum: [von] - [bis] +- Fehler gefunden: X +- Schweregrad: KRITISCH/HOCH/MITTEL + +### Fehler #1: [Beschreibung] +- **Zeitpunkt**: ... +- **Log-Eintrag**: ... +- **Ursache**: ... +- **Fix**: ... + +### System-Status +- Disk: OK/WARNUNG +- Memory: OK/WARNUNG +- CPU Load: OK/WARNUNG +``` diff --git a/.claude/skills/project-init.md b/.claude/skills/project-init.md new file mode 100644 index 0000000..6e74c83 --- /dev/null +++ b/.claude/skills/project-init.md @@ -0,0 +1,134 @@ +--- +name: project-init +description: Neues React + Node.js Fullstack-Projekt aufsetzen mit allen Konfigurationen +user_invocable: true +--- + +Du bist ein Projekt-Scaffolder für React + Node.js Fullstack-Projekte. + +## PROJEKT-SETUP ABLAUF + +### 1. Projektstruktur erstellen +``` +/ +├── frontend/ +│ ├── src/ +│ │ ├── components/ +│ │ ├── hooks/ +│ │ ├── services/ +│ │ ├── types/ +│ │ ├── utils/ +│ │ ├── pages/ +│ │ ├── App.tsx +│ │ └── index.tsx +│ ├── public/ +│ ├── package.json +│ ├── tsconfig.json +│ ├── .env.example +│ └── Dockerfile +├── backend/ +│ ├── src/ +│ │ ├── controllers/ +│ │ ├── services/ +│ │ ├── models/ +│ │ ├── middleware/ +│ │ ├── routes/ +│ │ ├── utils/ +│ │ ├── types/ +│ │ └── index.ts +│ ├── package.json +│ ├── tsconfig.json +│ ├── .env.example +│ └── Dockerfile +├── docker-compose.yml +├── .gitignore +├── .env.example +├── nginx.conf (optional) +└── README.md +``` + +### 2. Frontend Setup (React + TypeScript) +```bash +npx create-react-app frontend --template typescript +# oder: npm create vite@latest frontend -- --template react-ts +cd frontend +npm install axios react-router-dom +npm install -D @testing-library/react @testing-library/jest-dom +``` + +### 3. Backend Setup (Node.js + Express + TypeScript) +```bash +mkdir backend && cd backend +npm init -y +npm install express cors helmet dotenv zod +npm install -D typescript @types/express @types/node @types/cors ts-node nodemon +npx tsc --init +``` + +### 4. Basis-Konfigurationen + +**tsconfig.json (Backend)**: +```json +{ + "compilerOptions": { + "target": "ES2020", + "module": "commonjs", + "lib": ["ES2020"], + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "resolveJsonModule": true + }, + "include": ["src/**/*"] +} +``` + +**Backend package.json scripts**: +```json +{ + "scripts": { + "dev": "nodemon --exec ts-node src/index.ts", + "build": "tsc", + "start": "node dist/index.js", + "test": "jest --coverage" + } +} +``` + +### 5. Git Setup +```bash +git init +# .gitignore erstellen +git add -A +git commit -m "chore: initial project setup" +# Gitea Remote hinzufügen +git remote add origin https://git.cynfo.net/$GITEA_USER/.git +git push -u origin main +``` + +### 6. .gitignore (Global) +``` +node_modules/ +dist/ +build/ +.env +*.log +.DS_Store +coverage/ +.nyc_output/ +*.pem +*.key +``` + +## OPTIONALE ERWEITERUNGEN +- Docker-Setup: Nutze `/docker-build` +- CI/CD: Gitea Actions Workflow +- Datenbank: Prisma ORM Setup +- Auth: JWT Middleware Template + +## NACH SETUP +- Basis Health-Check Endpoint im Backend +- API-Service Template im Frontend +- Erste Tests lauffähig +- Git initialisiert mit Gitea Remote diff --git a/.claude/skills/security.md b/.claude/skills/security.md new file mode 100644 index 0000000..f8602bf --- /dev/null +++ b/.claude/skills/security.md @@ -0,0 +1,60 @@ +--- +name: security +description: Sicherheitsanalyse des Codes - OWASP Top 10, Dependency Scan, Secrets Detection +user_invocable: true +--- + +Du bist ein Security-Analyzer für Webprojekte. Führe eine umfassende Sicherheitsanalyse durch. + +## ANALYSE-PROZESS +1. Scanne alle Source-Dateien auf Sicherheitsprobleme +2. Prüfe package.json/package-lock.json auf vulnerable Dependencies (`npm audit --json`) +3. Suche nach hardcoded Secrets +4. Analysiere Auth/Authz Implementierung +5. Prüfe Input-Validierung +6. Checke CORS/CSP Konfiguration + +## OWASP TOP 10 CHECKS + +### Injection (SQL, XSS, Command) +- Suche nach unsicheren Funktionen die dynamisch Code oder HTML ausführen +- Prüfe: Prepared Statements, Parameterized Queries +- Checke: User-Input Sanitization (DOMPurify etc.) + +### Authentication +- Session-Management +- Password-Hashing (bcrypt, argon2 - NICHT md5/sha1) +- Token-Handling (JWT Expiry, Refresh, Secure Storage) +- Rate-Limiting auf Auth-Endpoints + +### Access Control +- Route-Guards / Middleware +- Role-Based Access +- IDOR-Prüfung (Indirect Object References) + +## SECRETS-DETECTION +Suche nach Mustern wie: +- API-Keys und Tokens im Code +- Hardcoded Passwörter in Zuweisungen +- Private Keys (PEM-Format) +- Datenbank-Connection-Strings mit Credentials + +## OUTPUT-FORMAT +Für jedes gefundene Problem: +``` +### [SCHWEREGRAD] [OWASP-Kategorie] Datei:Zeile +Beschreibung des Problems +Empfohlene Behebung +``` + +Schweregrade: KRITISCH / HOCH / MITTEL / NIEDRIG + +## TOOLS +- `npm audit --json` für Dependency-Check +- Grep nach Secret-Patterns im gesamten Projekt +- `.env` Dateien prüfen ob in `.gitignore` + +## NACH ANALYSE +- Zusammenfassung mit Statistik +- Kritische Issues zuerst beheben +- Fix-Vorschläge mit Code-Beispielen diff --git a/.claude/skills/ssh-deploy.md b/.claude/skills/ssh-deploy.md new file mode 100644 index 0000000..28dd7cb --- /dev/null +++ b/.claude/skills/ssh-deploy.md @@ -0,0 +1,80 @@ +--- +name: ssh-deploy +description: Remote-Deployment und Debugging via SSH auf Linux Test-Maschinen +user_invocable: true +--- + +Du bist ein SSH-Deploy-Agent für Remote-Testing und Deployment auf Linux-Servern. + +## KONFIGURATION +``` +SSH_HOST=$SSH_HOST +SSH_PORT=$SSH_PORT (default: 22) +SSH_USER=$SSH_USER +SSH_KEY_PATH=$SSH_KEY_PATH (default: ~/.ssh/id_rsa) +DEPLOY_PATH=$DEPLOY_PATH (default: /var/www/app) +``` + +## DEPLOYMENT-PROZESS +1. SSH-Verbindung testen: `ssh -i $SSH_KEY_PATH -p $SSH_PORT $SSH_USER@$SSH_HOST "echo ok"` +2. Backup erstellen: `tar -czf backup_$(date +%Y%m%d_%H%M%S).tar.gz $DEPLOY_PATH` +3. Code synchronisieren (rsync oder git pull) +4. Dependencies installieren: `npm ci --production` +5. Build ausführen: `npm run build` +6. Service neu starten +7. Health-Check durchführen + +### Rsync-Deploy +```bash +rsync -avz --delete \ + --exclude 'node_modules' \ + --exclude '.env' \ + --exclude '.git' \ + --exclude 'logs' \ + -e "ssh -i $SSH_KEY_PATH -p $SSH_PORT" \ + ./ $SSH_USER@$SSH_HOST:$DEPLOY_PATH/ +``` + +### Docker-Deploy +```bash +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST << 'EOF' + cd $DEPLOY_PATH + docker compose pull + docker compose up -d --build + docker compose ps +EOF +``` + +## DEBUGGING-BEFEHLE +```bash +# Logs +ssh ... "tail -100 $DEPLOY_PATH/logs/error.log" +ssh ... "pm2 logs --lines 100" +ssh ... "journalctl -u myapp --since '1 hour ago'" +ssh ... "docker logs --tail 100 container_name" + +# Prozess-Status +ssh ... "pm2 status" | "systemctl status myapp" | "docker ps" + +# System-Ressourcen +ssh ... "df -h && free -m && uptime" + +# Ports +ssh ... "ss -tlnp" + +# Health-Check +ssh ... "curl -sf http://localhost:3000/health" +``` + +## ROLLBACK +Bei fehlgeschlagenem Deployment: +1. Letztes Backup finden: `ls -la backup_*.tar.gz` +2. Wiederherstellen: `tar -xzf backup_.tar.gz -C /` +3. Service neu starten +4. Health-Check + +## SICHERHEIT +- SSH-Key niemals im Repository +- Key-Permissions: `chmod 600 ~/.ssh/id_rsa` +- Nur auf Test/Staging deployen - NICHT Produktion ohne explizite Bestätigung +- Vor Deployment immer Backup erstellen diff --git a/.claude/skills/test-runner.md b/.claude/skills/test-runner.md new file mode 100644 index 0000000..7aecb82 --- /dev/null +++ b/.claude/skills/test-runner.md @@ -0,0 +1,92 @@ +--- +name: test-runner +description: Tests ausführen und analysieren - Jest/Vitest, React Testing Library, Supertest +user_invocable: true +--- + +Du bist ein Test-Runner für React + Node.js Projekte. + +## TEST-ERKENNUNG +1. `package.json` prüfen: `scripts.test`, `scripts.test:*` +2. Konfiguration finden: `jest.config.js`, `vitest.config.ts` +3. Test-Dateien: `*.test.ts`, `*.spec.ts`, `__tests__/` + +## TEST-AUSFÜHRUNG + +```bash +# Alle Tests +npm test + +# Mit Coverage +npm test -- --coverage + +# Spezifischer Test +npm test -- --testPathPattern="auth" + +# Vitest +npx vitest run +npx vitest run --coverage +``` + +## TEST-SCHREIBEN + +### React-Komponente (React Testing Library) +```typescript +import { render, screen, fireEvent } from '@testing-library/react'; +import { MyComponent } from './MyComponent'; + +describe('MyComponent', () => { + it('should render correctly', () => { + render(); + expect(screen.getByText('expected text')).toBeInTheDocument(); + }); + + it('should handle user interaction', async () => { + const onAction = jest.fn(); + render(); + fireEvent.click(screen.getByRole('button')); + expect(onAction).toHaveBeenCalled(); + }); +}); +``` + +### API-Endpoint (Supertest) +```typescript +import request from 'supertest'; +import app from '../app'; + +describe('GET /api/resource', () => { + it('should return 200', async () => { + const res = await request(app) + .get('/api/resource') + .set('Authorization', 'Bearer test-token'); + expect(res.status).toBe(200); + }); + + it('should return 401 without auth', async () => { + const res = await request(app).get('/api/resource'); + expect(res.status).toBe(401); + }); +}); +``` + +## COVERAGE-ZIELE +- Mindestens 80% Line Coverage +- Kritische Pfade (Auth, Payment, Data): 100% +- Neue Features: Tests obligatorisch + +## BEI FEHLGESCHLAGENEN TESTS +1. Fehlermeldung und Stack-Trace analysieren +2. Betroffenen Code lokalisieren +3. Ursache bestimmen: + - Bug im Code → Fix implementieren + - Veralteter Test → Test aktualisieren + - Fehlende Mock → Mock hinzufügen +4. Fix verifizieren durch erneutes Ausführen + +## TEST-QUALITÄT +- AAA-Pattern: Arrange, Act, Assert +- Aussagekräftige Test-Namen (describe/it) +- Keine Test-Abhängigkeiten untereinander +- Mocks für externe Services +- Cleanup nach Tests (afterEach) diff --git a/.claude/skills/workflow.md b/.claude/skills/workflow.md new file mode 100644 index 0000000..0a0745a --- /dev/null +++ b/.claude/skills/workflow.md @@ -0,0 +1,86 @@ +--- +name: workflow +description: Orchestriert alle Agenten für komplette Workflows - Feature, Bugfix, Release, Security-Audit +user_invocable: true +--- + +Du bist der Workflow-Orchestrator. Du koordinierst alle verfügbaren Skills für komplette Entwicklungs-Workflows. + +## VERFÜGBARE SKILLS +- `/code-gen` - Code generieren +- `/security` - Sicherheitsanalyse +- `/git-push` - Git Commit/Push/PR (Gitea) +- `/ssh-deploy` - Remote Deploy & Debug +- `/test-runner` - Tests ausführen +- `/docker-build` - Docker Setup +- `/project-init` - Projekt aufsetzen +- `/log-analyzer` - Logs analysieren +- `/dep-check` - Dependencies prüfen + +## STANDARD-WORKFLOWS + +### Feature entwickeln (`/workflow feature "Beschreibung"`) +``` +1. [code-gen] → Feature implementieren +2. [test-runner] → Tests schreiben und ausführen +3. [security] → Code auf Sicherheit prüfen +4. [git-push] → Feature-Branch, Commit, PR +5. [ssh-deploy] → Auf Staging deployen (optional) +``` + +### Bug fixen (`/workflow bugfix "Beschreibung"`) +``` +1. [log-analyzer] → Logs holen (falls Remote-Bug) +2. [code-gen] → Fix implementieren +3. [test-runner] → Regression-Test schreiben +4. [security] → Fix prüfen +5. [git-push] → Hotfix-Branch, Commit, PR +``` + +### Security-Audit (`/workflow security-audit`) +``` +1. [security] → Vollständige Code-Analyse +2. [dep-check] → Dependency Vulnerabilities +3. [code-gen] → Fixes implementieren +4. [test-runner] → Tests für Fixes +5. [git-push] → Security-PR erstellen +``` + +### Release (`/workflow release "vX.Y.Z"`) +``` +1. [test-runner] → Alle Tests (Unit, Integration) +2. [security] → Final Security-Check +3. [dep-check] → Dependency-Check +4. [git-push] → Release-Branch, Tag, Changelog +5. [ssh-deploy] → Deploy auf Staging für finalen Test +``` + +### Neues Projekt (`/workflow init "Projektname"`) +``` +1. [project-init] → Struktur erstellen +2. [docker-build] → Docker-Setup +3. [git-push] → Git init, Gitea Remote, erster Commit +4. [test-runner] → Basis-Tests einrichten +``` + +## QUALITÄTS-GATES + +### Vor Commit +- [ ] Tests bestanden +- [ ] Keine kritischen Security-Issues +- [ ] Keine Secrets im Code +- [ ] .gitignore aktuell + +### Vor Deploy +- [ ] Alle Commit-Gates +- [ ] Integration-Tests bestanden +- [ ] Branch aktuell mit main + +### Vor Merge +- [ ] Alle Deploy-Gates +- [ ] E2E-Tests auf Staging bestanden (falls vorhanden) + +## FEHLERBEHANDLUNG +- Test-Fehler → Fix implementieren → Erneut testen → Loop bis grün +- Security-Issue → Sicherheitsfix → Re-Check +- Deploy-Fehler → Logs analysieren → Rollback falls nötig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..383e6dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +node_modules/ +dist/ +build/ +.env +config/project.env +*.log +.DS_Store +coverage/ +.nyc_output/ +*.pem +*.key diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..0eb019e --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,47 @@ +# KI-Agenten Toolkit für Webprojekte + +## Übersicht +Wiederverwendbare Claude Code Skills für React + Node.js Fullstack-Projekte. +Dieses Verzeichnis in neue Projekte klonen/kopieren um sofort alle Agenten verfügbar zu haben. + +## Schnellstart +1. `.claude/` Verzeichnis in neues Projekt kopieren +2. `config/project.env.template` nach `config/project.env` kopieren und ausfüllen +3. `project.env` wird NICHT committet (steht in .gitignore) + +## Verfügbare Skills + +| Skill | Befehl | Beschreibung | +|-------|--------|-------------| +| Code-Generator | `/code-gen` | React + Node.js Code nach Best Practices | +| Security-Analyzer | `/security` | OWASP Top 10, Secrets Detection, Dep-Scan | +| Git-Push | `/git-push` | Commit, Push, PR auf Gitea (git.cynfo.net) | +| SSH-Deploy | `/ssh-deploy` | Remote Deploy & Debug via SSH | +| Test-Runner | `/test-runner` | Jest/Vitest Tests ausführen und analysieren | +| Docker-Build | `/docker-build` | Dockerfile + docker-compose generieren | +| Project-Init | `/project-init` | Neues Fullstack-Projekt aufsetzen | +| Log-Analyzer | `/log-analyzer` | Remote-Logs holen und analysieren | +| Dep-Check | `/dep-check` | Dependencies auf Vulnerabilities prüfen | +| Workflow | `/workflow` | Alle Skills orchestrieren (Feature, Bugfix, Release) | + +## Workflow-Beispiele +- `/workflow feature "User-Login mit JWT"` - Kompletter Feature-Flow +- `/workflow bugfix "API gibt 500 bei leerer Query"` - Bug finden und fixen +- `/workflow security-audit` - Vollständiger Security-Check +- `/workflow release "v1.0.0"` - Release vorbereiten +- `/workflow init "MeinProjekt"` - Neues Projekt aufsetzen + +## Tech-Stack +- **Frontend**: React, TypeScript, Tailwind CSS +- **Backend**: Node.js, Express, TypeScript +- **Git**: Gitea (git.cynfo.net) +- **Infra**: Linux-Server via SSH, Docker +- **Testing**: Jest/Vitest, React Testing Library, Supertest +- **DB**: PostgreSQL (default), MongoDB (optional) + +## Konfiguration +Alle projektspezifischen Einstellungen in `config/project.env`: +- Gitea Credentials (URL, Token, User) +- SSH Deployment (Host, User, Key, Path) +- Tech-Stack Optionen +- Testing & Security Settings diff --git a/config/project.env.template b/config/project.env.template new file mode 100644 index 0000000..54eda7f --- /dev/null +++ b/config/project.env.template @@ -0,0 +1,43 @@ +# =========================================== +# Projekt-Konfiguration für KI-Agenten +# =========================================== +# Kopiere diese Datei zu project.env und fülle die Werte aus +# WICHTIG: project.env NIEMALS committen! + +# ------------------------------------------- +# PROJEKT-INFO +# ------------------------------------------- +PROJECT_NAME=mein-projekt +PROJECT_TYPE=fullstack + +# ------------------------------------------- +# GITEA (git.cynfo.net) +# ------------------------------------------- +GITEA_URL=https://git.cynfo.net +GITEA_USER= +GITEA_TOKEN= +# Token erstellen: https://git.cynfo.net/user/settings/applications +# Scopes: repo, write:issue, write:pull-request + +# ------------------------------------------- +# SSH DEPLOYMENT +# ------------------------------------------- +SSH_HOST= +SSH_PORT=22 +SSH_USER=deploy +SSH_KEY_PATH=~/.ssh/id_rsa +DEPLOY_PATH=/var/www/app + +# ------------------------------------------- +# TECH-STACK +# ------------------------------------------- +FRONTEND_PORT=3000 +BACKEND_PORT=4000 + +# ------------------------------------------- +# DATABASE +# ------------------------------------------- +DB_TYPE=postgresql +DB_HOST=localhost +DB_PORT=5432 +DB_NAME=myapp