Dokumentation » Contracts
Contracts
Contracts sind normative YAML-Dokumente, die verbindliche Regeln für Code, Architektur und Dokumentation definieren. Sie ermöglichen automatisierte Validierung und stellen Qualitätsstandards sicher.
Was sind Contracts?
Normativ: Verbindliche Regeln, keine Empfehlungen
Maschinenlesbar: YAML-Format für automatisierte Prüfung
Versioniert: Änderungen erfordern explizite Versionierung
Validierbar: Klare Pass/Fail-Kriterien
Wann werden Contracts geprüft?
Zeitpunkt Contract Aktion bei Violation
Vor Sync zu Prod Alle aktiven Sync blockiert
Nach Dateiänderung Betriebsdokumentation Warnung
Bei neuem Modul Layered Architecture Ablehnung
Contract-Management
Contracts werden in der Datenbank verwaltet und sind über Web-UI und MCP-API zugänglich.
Web-UI /contracts
Datenbank ki_protokoll.contracts
MCP-Server mcp-tasks (contracts_* Tools)
Legacy-Pfad /var/www/docs/contracts/ (migriert)
Web-UI Features
/contracts - Liste aller Contracts mit Filter
/contracts/new - Neuen Contract erstellen
/contracts/{id} - Contract-Details, YAML-Inhalt, Validierungshistorie
/contracts/{id}/edit - Contract bearbeiten (erzeugt neue Version)
Validierung direkt aus der UI auslösen
Versionshistorie mit Diff-Ansicht
MCP-Tools (mcp-tasks)
Tool Beschreibung
contracts_listAlle Contracts auflisten
contracts_getContract nach ID/Name abrufen
contracts_createNeuen Contract anlegen
contracts_updateContract aktualisieren (neue Version)
contracts_validateValidierung ausführen
contracts_historyÄnderungshistorie abrufen
contracts_violationsLetzte Violations abrufen
contracts_deprecateContract als deprecated markieren
Datenbankschema
-- Contracts mit YAML-Content und Versionierung
ki_protokoll.contracts
├── id, uuid, name, version, status
├── yaml_content, scope_description
└── created_at, created_by, updated_at
-- Änderungshistorie
ki_protokoll.contract_history
├── contract_id, previous_yaml, previous_version
└── change_description, changed_at, changed_by
-- Validierungsläufe
ki_protokoll.contract_validations
├── contract_id, result (passed/failed)
├── critical_count, major_count, minor_count
└── violations (JSON), triggered_by, duration_ms
Aktive Contracts
Betriebsdokumentation v1.1
Datei betriebsdokumentation-pruefung_v1.1.yaml
Status active
Scope /src/View/docs/**/*.php
Validiert Server- und Betriebsdokumentation:
Dateipfade müssen existieren
Befehle müssen syntaktisch korrekt sein
Ports/Versionen müssen aktuell sein
Struktur: Breadcrumb, h1, Intro, Tabelle, Commands
Layered Architecture v1.0
Datei layered-architecture-pruefung_v1.0.yaml
Status active
Scope /src/**/*.php, /app/**/*.php
Tool PHPStan
Validiert die Schichtenarchitektur:
/src (MVC): Framework, Controller, Domain, UseCases, Infrastructure, View
/app (MVP): Presenter, View
Dependency Rules zwischen Layern
Verbotene Imports und Platzierungen
HTML Tables Contract v1.0
Datei html-tables-contract_v1.0.yaml
Status active
Scope /src/View/**/*.php, /public/js/**/*.js
Tool HTMLHint
Validiert HTML-Tabellen nach DRY/KISS/SRP-Prinzipien:
Keine "Aktionen"-Spalte mit Details-Button - ID/Titel verlinken
Keine Modals - echte URLs verwenden
Alle Spalten sortierbar (data-sort Attribut)
Suchfeld für jede Tabelle
Wiederverwendbare DataTable-Komponente
CSS Contract v1.0
Datei css-contract_v1.0.yaml
Status active
Scope /src/View/**/*.php, /public/css/**/*.css
Tool Stylelint
Validiert CSS nach WCAG 2.1 AA Accessibility-Standards:
Farbkontrast min. 4.5:1 für Text (A11Y-001)
Vordergrundfarbe immer mit Hintergrundfarbe definieren (COL-001)
Focus-Styles niemals entfernen (A11Y-004)
Mindestschriftgröße 16px für Fließtext (TYP-001)
CSS-Variablen für Farben verwenden (COL-002)
Kein !important außer für Utility-Klassen (FRB-001)
JS Browser Architecture v2
Datei js-browser-architecture-contract_v2.yaml
Status active
Scope /public/js/**/*.js
Tool ESLint + Prettier
Validiert JavaScript für Browser-Anwendungen:
ES Modules ohne Build-Tools (ECMAScript 2024)
Strikte Gleichheit (===)
const/let statt var
Double Quotes, Semikolons, 2 Spaces
Keine eval(), no-implied-eval (Security)
Python Pipeline Contract v1.0
Datei python-pipeline-contract_v1.0.yaml
Status active
Scope /opt/scripts/pipeline/**/*.py
Tool Ruff + mypy
Validiert Python-Code in der KI-Pipeline:
Type Hints für alle Funktionen (Parameter + Return)
Docstrings für Module, Klassen, Public Functions
Keine bare except, keine silent failures
Security: Keine hardcoded Credentials, kein eval()
Imports sortiert, keine Wildcards
View Structure Contract v1.0
Datei view-structure-contract_v1.0.yaml
Status active
Scope CRUD-Ressourcen: /src/View/tasks/*, /src/View/content/*
Validiert die Struktur von CRUD-Views (index, show, new, edit):
RESTful URLs: /{resource}, /{resource}/new, /{resource}/{id}, /{resource}/{id}/edit
Seitenaufbau: Breadcrumb → h1 → Tabelle/Content → Actions
Keine page-container, Cards oder verschachtelte Strukturen
Formulare: class="form", max-width: 600px, flache form-group
Referenz: /src/View/tasks/* als Vorlage
Gilt nicht für: /docs (eigener Contract), /chat (interaktives Tool), /home (Landing Pages)
Neue CRUD-Ressource hinzufügen
Verzeichnis erstellen: /src/View/{resource}/
Views anlegen: index.php, show.php, new.php, edit.php
Contract-Scope erweitern: includes += "/src/View/{resource}/*.php"
Vorlage: /src/View/tasks/* kopieren und anpassen
Zukünftige Contracts
Geplante Contracts für zukünftige Erweiterungen:
API Contract - OpenAPI/Swagger Validierung
Severity Levels
Level Bedeutung Aktion
critical Faktisch falsch Dokument abgelehnt
major Unvollständig Überarbeitung nötig
minor Kosmetisch Nur protokolliert
Pass-Schwelle
0 critical violations (sonst: rejected)
max 2 major violations (sonst: revision required)
max 5 minor violations (sonst: approved with notes)
Automatische Validierung
Alle Contracts werden automatisch vor dem Sync zu Produktion geprüft.
Pre-Sync Hook
Script /opt/scripts/contract-check.sh
Aufruf /opt/scripts/contract-check.sh [path]
Integration /opt/scripts/sync-dev-prod.sh
Exit-Codes 0 = OK, 1 = Critical, 2 = Major
Geprüfte Contracts
Contract Prüfung Tool
View Structure v1.0 Struktur, verbotene Elemente Grep
HTML Tables v1.0 Modals, Aktionen-Spalte Grep
CSS Contract v1.0 Styling-Regeln Stylelint
Python Pipeline v1.0 Code-Qualität, Types Ruff, mypy
Layered Architecture v1.0 Layer-Grenzen Grep, find
Betriebsdokumentation v1.1 Struktur Grep
Manuell ausführen
# Alle Contracts prüfen
/opt/scripts/contract-check.sh
# Mit spezifischem Pfad
/opt/scripts/contract-check.sh /var/www/dev.campus.systemische-tools.de