INSIGHT-MVP/Summarize.md
Thomas Reitz 10f291cdda feat: implement Sprint 1 Alpha - full stack with Docker, NestJS, React
Docker Infrastructure:
- docker-compose.yml with Traefik 3, PostgreSQL 16, PgBouncer, Redis 7, step-ca
- docker-compose.observability.yml with Prometheus, Grafana, Loki, Tempo, Promtail
- Traefik dynamic config (TLS, security headers, CORS, compression)
- PostgreSQL init script (uuid-ossp, pgcrypto, pg_trgm extensions)
- Grafana auto-provisioned datasources (Prometheus, Loki, Tempo)

NestJS Core-Service:
- Auth module: Login (email/password), TOTP 2FA, JWT RS256, token refresh/revocation
- Users module: CRUD, bcrypt cost 12, pagination, role-based access
- Tenants module: CRUD, member management, slug validation
- Prisma schemas: core (Users, AuthProviders, Tenants, Modules, AuditLog)
                  tenant (Contacts, Activities - CRM reference for Sprint 2)
- TenantPrismaService: Dynamic per-tenant DB connections with caching
- RedisService: Token blocklist, refresh token families, generic cache
- Global JwtAuthGuard with @Public() decorator, RolesGuard, GlobalExceptionFilter
- Health endpoint with DB + Redis status checks
- Swagger API documentation (dev only)
- Multi-stage Dockerfile (dev + production)

React Frontend:
- Vite 6 + React 18 + TypeScript strict
- AuthContext with silent refresh (access token in memory, NOT localStorage)
- Login page with TOTP 2FA support
- App shell with sidebar navigation
- Admin pages: Users + Tenants management tables
- API client with automatic token refresh interceptor
- Multi-stage Dockerfile (dev + nginx production)

CI/CD Pipelines:
- ci.yml: Lint, type-check, test, build on all branches
- deploy.yml: Docker build, push to Forgejo registry, SSH deploy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 15:33:36 +01:00

9.2 KiB

INSIGHT MVP - Aenderungsprotokoll

Stand: 2026-03-08

Aktueller Sprint: Sprint 1 (Alpha)


Aenderungen in dieser Session

1. Projektinitialisierung & Infrastruktur-Definition

Was wurde gemacht:

  1. SSH Keys erstellt

    • Deploy-Key (.keys/deploy_ed25519) fuer Server-Zugriff
    • CI/CD-Key (.keys/cicd_ed25519) fuer Forgejo Actions Pipeline
  2. Infrastruktur-Definition erstellt (docs/INFRASTRUCTURE.md)

    • ProxmoxVE VM-Spezifikation: Ubuntu 24.04 LTS, 4 vCPU, 8 GB RAM, 60 GB SSD
    • Docker-Netzwerk-Architektur mit 3 isolierten Netzwerken
    • Komplette Service-Landschaft definiert
    • Schritt-fuer-Schritt VM-Setup Anleitung
  3. Zugangsdaten-Dokument erstellt (docs/ACCESS.md)

    • Server-IP: 172.20.10.59 (insight-dev-01)
    • Git-Server: 172.20.10.11 (GAIA-GIT)
    • Alle SSH-Keys, Ports, Befehle dokumentiert
  4. Projektstruktur aufgesetzt (packages/core-service, packages/frontend, config, .forgejo)

  5. Basis-Konfigurationsdateien (.gitignore, .env.example, README.md)

2. Forgejo Git-Server Konfiguration

Was wurde auf dem Git-Server (172.20.10.11) gemacht:

  1. Docker Engine 29.3 installiert (fuer Forgejo Actions Runner)
  2. Forgejo Actions aktiviert ([actions] ENABLED = true in app.ini)
  3. Container Registry aktiviert ([packages] ENABLED = true in app.ini)
  4. Forgejo Runner v6.3.1 installiert und registriert
    • Runner-Name: insight-runner
    • Labels: ubuntu-latest (docker://node:20)
    • Laeuft als Systemd-Service (forgejo-runner.service)
  5. Repository Secrets angelegt:
    • SSH_DEPLOY_KEY - CI/CD Private Key
    • DEPLOY_HOST - 172.20.10.59
    • DEPLOY_USER - deploy
    • REGISTRY_USER - gitadmin
    • REGISTRY_PASSWORD - Forgejo Access Token
  6. Branch Protection eingerichtet:
    • main: Kein direkter Push, 1 Approval erforderlich
    • develop: Kein direkter Push, 1 Approval erforderlich
  7. Forgejo Setup-Anleitung erstellt (docs/FORGEJO_SETUP.md)

3. Server-Setup (insight-dev-01)

Was wurde auf dem Entwicklungsserver (172.20.10.59) gemacht:

  1. SSH Public Keys hinterlegt in /home/deploy/.ssh/authorized_keys
    • Deploy-Key (insight-deploy@xinion.lan) - fuer manuellen Zugriff
    • CI/CD-Key (insight-cicd@xinion.lan) - fuer Forgejo Actions Pipeline
  2. SSH-Zugang getestet - Key-basierter Login als deploy funktioniert

4. Docker Compose & Service-Konfiguration

Erstellte Dateien:

  1. docker-compose.yml - Alle Basis-Services:

    • Traefik 3 (API Gateway, Reverse Proxy, TLS, Rate Limiting)
    • PostgreSQL 16-alpine (mit Performance-Tuning fuer 8GB RAM)
    • PgBouncer (Connection Pooling, Transaction Mode)
    • Redis 7-alpine (Cache, Sessions, Token-Revocation)
    • step-ca (Interne Certificate Authority fuer mTLS)
    • Core-Service (NestJS) mit Traefik-Labels
    • Frontend (React) mit Traefik-Labels
    • 3 isolierte Docker-Netzwerke (insight-web, insight-db, insight-cache)
    • Health-Checks fuer alle Services
  2. docker-compose.observability.yml - Monitoring-Stack:

    • Prometheus (Metrics-Sammlung, 30 Tage Retention)
    • Grafana (Dashboards, automatisch provisionierte Datenquellen)
    • Loki (Log-Aggregation)
    • Promtail (Docker Log-Collector)
    • Tempo (Distributed Tracing, OTLP gRPC)
    • cAdvisor (Container-Metriken)
    • PostgreSQL Exporter (DB-Metriken)
  3. Konfigurationsdateien:

    • config/traefik/dynamic/tls.yml - TLS-Konfiguration
    • config/traefik/dynamic/middlewares.yml - Security-Headers, CORS, Compression
    • config/prometheus/prometheus.yml - Scrape-Konfiguration
    • config/loki/loki.yml - Log-Storage-Konfiguration
    • config/promtail/promtail.yml - Docker-Log-Collector
    • config/tempo/tempo.yml - Tracing-Backend
    • config/grafana/provisioning/datasources/datasources.yml - Auto-Provisioning
    • config/postgres/init/01-init-extensions.sql - DB-Extensions (uuid-ossp, pgcrypto, pg_trgm)

5. NestJS Core-Service Implementierung

Projekt-Setup:

  • package.json mit allen Dependencies (NestJS 10, Prisma 6, Passport, JWT, bcrypt, TOTP)
  • tsconfig.json mit strict: true, noImplicitAny, strictNullChecks
  • Dockerfile (Multi-Stage: base, deps, development, build, production)
  • nest-cli.json Konfiguration

Implementierte Module:

  1. Auth-Modul (src/core/auth/)

    • AuthService: Login (E-Mail/Passwort), Token-Refresh, Logout, Token-Revocation
    • AuthController: POST /login, /refresh, /logout
    • JwtStrategy: RS256 Passport-Strategy
    • TotpService: TOTP 2FA (Google Authenticator kompatibel)
    • LoginDto: Validierung mit class-validator
    • Account-Lockout nach 5 Fehlversuchen (15 Min Sperre)
    • Refresh-Token als HttpOnly/Secure/SameSite=Strict Cookie
    • Token-Rotation mit Redis-basierter Familien-Erkennung
  2. Users-Modul (src/core/users/)

    • UsersService: CRUD, Bcrypt Cost 12, Passwort-Hashing
    • UsersController: GET /me, GET /users, POST /users, PATCH /users/:id
    • DTOs: CreateUserDto, UpdateUserDto
    • Paginierung mit Meta-Informationen
  3. Tenants-Modul (src/core/tenants/)

    • TenantsService: CRUD, Member-Management
    • TenantsController: CRUD + POST /:id/members, DELETE /:id/members/:userId
    • DTOs: CreateTenantDto, UpdateTenantDto, AddMemberDto
    • Slug-Validierung (URL-freundlich)
  4. Infrastruktur-Module:

    • PrismaService: PostgreSQL-Verbindung (platform_core)
    • TenantPrismaService: Dynamische Tenant-DB-Verbindungen mit Caching
    • RedisService: Token-Blocklist, Refresh-Token-Familien, generischer Cache
    • HealthController: GET /health (DB + Redis Status)
  5. Common (Guards, Decorators, Filter):

    • @Public() Decorator fuer oeffentliche Routen
    • @Roles() Decorator fuer rollenbasierte Zugriffskontrolle
    • @CurrentUser() Decorator fuer User-Extraktion aus JWT
    • JwtAuthGuard (global) mit Token-Revocation-Check
    • RolesGuard fuer Rollen-Pruefung
    • GlobalExceptionFilter fuer strukturierte Fehlerantworten
  6. Config:

    • validateConfig() mit class-validator fuer Umgebungsvariablen

6. Prisma-Schemas

  1. core.schema.prisma (platform_core Datenbank):

    • User - Plattform-Benutzer (mit Login-Tracking, 2FA)
    • AuthProvider - Multi-Provider Auth (LOCAL, MS_SSO, M2M)
    • Tenant - Mandanten mit JSON-Settings
    • TenantMembership - User-Tenant-Zuordnung (M:N)
    • Module - Verfuegbare Plattform-Module
    • TenantModule - Module pro Tenant
    • AuditLog - Plattform-weites Audit-Log
  2. tenant.schema.prisma (tenant_{slug} Datenbanken):

    • Contact - CRM-Kontakte (Person/Organisation)
    • Activity - CRM-Aktivitaeten (Notiz, Anruf, E-Mail, Meeting, Task)
    • Referenz-Schema fuer Sprint 2 (CRM-Modul)

7. React Frontend-Shell

Projekt-Setup:

  • package.json mit React 18, Vite 6, React Router 6, TanStack Query 5, Axios
  • tsconfig.json mit strict TypeScript
  • vite.config.ts mit API-Proxy und Path-Aliases
  • Dockerfile (Multi-Stage: development mit Vite, production mit Nginx)
  • nginx.conf (SPA-Routing, Security-Headers, Caching)

Implementierte Komponenten:

  1. Auth-System (src/auth/)

    • AuthContext + useAuth() Hook: Login, Logout, Silent Refresh
    • LoginPage: E-Mail/Passwort + optionaler TOTP 2FA-Code
    • Access-Token NUR im Memory (kein localStorage!)
    • Automatischer Silent Refresh via HttpOnly Cookie
  2. API-Client (src/api/client.ts)

    • Axios-Instanz mit automatischem Token-Handling
    • Request-Interceptor fuer Authorization-Header
    • Response-Interceptor fuer automatisches Token-Refresh bei 401
  3. App-Shell (src/shell/)

    • App: React Router mit PrivateRoute-Guard
    • AppLayout: Sidebar-Navigation + Outlet
    • DashboardPage: Willkommens-Seite
  4. Admin-Bereich (src/admin/)

    • AdminUsersPage: Benutzer-Tabelle mit Paginierung
    • AdminTenantsPage: Mandanten-Tabelle mit Member-Count
  5. Styling:

    • CSS Custom Properties (Farben, Layout, Schatten, Radien)
    • CSS Modules fuer komponentenspezifische Styles
    • Responsive Sidebar-Layout

8. CI/CD Pipelines

  1. .forgejo/workflows/ci.yml - Continuous Integration:

    • Trigger: Push auf alle Branches + Pull Requests
    • Core-Service: npm ci, Prisma Generate, Lint, Type-Check, Test, Build
    • Frontend: npm ci, Lint, Type-Check, Build
  2. .forgejo/workflows/deploy.yml - Deployment:

    • Trigger: Push auf main/develop
    • Build Docker-Images (Core + Frontend)
    • Push in Forgejo Container Registry
    • SSH-Deploy auf insight-dev-01
    • Health-Check Verifizierung

Naechste Schritte

  • SSH Deploy Keys auf insight-dev-01 Server hinterlegen
  • docker-compose.yml erstellen (alle Basis-Services)
  • docker-compose.observability.yml erstellen
  • NestJS Core-Service implementieren (Auth, Users, Tenants)
  • Prisma-Schemas erstellen (core + tenant)
  • React Frontend-Shell implementieren
  • CI/CD Pipelines (.forgejo/workflows/) definieren
  • Docker + Docker Compose auf insight-dev-01 installieren
  • .env-Datei auf Server anlegen (echte Passwoerter)
  • JWT RS256 Schluessel generieren (fuer Token-Signierung)
  • Erste Prisma-Migration ausfuehren
  • Platform-Admin User anlegen (Seed)
  • Erster End-to-End Test (Login -> Dashboard)

Offene Fragen / Abhaengigkeiten

  • DNS-Eintrag insight-dev.xinion.lan muss auf 172.20.10.59 zeigen