layered-architecture-pruefung_v1.0

ID 5
UUID d5b5cd24-8128-41b7-8d93-f94710a8ea9d
Version 1.0
Status active
Scope
Erstellt 2025-12-20 10:59:58 von migration
Aktualisiert 2025-12-20 10:59:58

YAML-Inhalt

# =============================================================================
# LAYERED ARCHITECTURE VALIDATION CONTRACT
# =============================================================================
# Validierung der Schichtenarchitektur (MVC in /src, MVP in /app)
# Version: 1.0.0
# Erstellt: 2025-12-20
# =============================================================================

meta:
  document_type: architecture_validation_contract
  normative: true
  binding: mandatory
  created: 2025-12-20
  author: system_generated_under_supervision
  based_on: layered_architecture_mvc_mvp_v1.2.0

identity:
  name: layered_architecture_validation
  version: 1.0.0
  status: active
  migration_plan: /var/www/docs/architecture/migration-plan_mvc-to-layered.md
  migrated_on: 2025-12-20

# =============================================================================
# SCOPE (technisch definiert)
# =============================================================================
scope:
  applies_to_paths:
    - /var/www/dev.campus.systemische-tools.de/src/**/*.php
    - /var/www/dev.campus.systemische-tools.de/app/**/*.php

  excludes_paths:
    - /var/www/dev.campus.systemische-tools.de/tests/**
    - /var/www/dev.campus.systemische-tools.de/scripts/**
    - /var/www/dev.campus.systemische-tools.de/public/**
    - /var/www/dev.campus.systemische-tools.de/config/**
    - /var/www/dev.campus.systemische-tools.de/src/View/docs/**

  file_types:
    - .php

  platform:
    language: PHP
    version_min: 8.4

# =============================================================================
# ARCHITEKTUR-DEFINITION
# =============================================================================
architecture:
  style: layered_architecture

  patterns:
    src: mvc
    app: mvp

  expected_directories:
    src:
      - /src/Domain
      - /src/UseCases
      - /src/Infrastructure
      - /src/Controller
      - /src/View
    app:
      - /app/Presenter
      - /app/View

# =============================================================================
# LAYER-DEFINITIONEN
# =============================================================================
layers:
  # === SRC (MVC) ===
  src_domain:
    path_pattern: "/src/Domain/**/*.php"
    role: domain_logic
    allowed:
      - Fachliche Regeln
      - Entities
      - Value Objects
      - Domain Events
    forbidden:
      - UI-Logik
      - Interaktions-Logik
      - Infrastructure-Zugriff
      - use-Statements zu /app
      - use-Statements zu /src/Infrastructure

  src_use_cases:
    path_pattern: "/src/UseCases/**/*.php"
    role: domain_coordination
    allowed:
      - Orchestrierung von Domain-Operationen
      - Interface-Definitionen für Infrastructure
    forbidden:
      - Eigene Fachlogik (gehört in Domain)
      - UI-Logik
      - Direkte Infrastructure-Implementierung

  src_infrastructure:
    path_pattern: "/src/Infrastructure/**/*.php"
    role: infrastructure_implementation
    allowed:
      - Repository-Implementierungen
      - External Service Adapter
      - Database Access
    forbidden:
      - Domain-Logik
      - UI-Logik
    must_implement: Interfaces aus /src/UseCases oder /src/Domain

  src_controller:
    path_pattern: "/src/Controller/**/*.php"
    role: request_handling
    allowed:
      - Use Case Orchestrierung
      - Request/Response Transformation
    forbidden:
      - Domain-Logik
      - Infrastructure-Implementierung
      - UI State Management

  src_view:
    path_pattern: "/src/View/**/*.php"
    role: output_templates
    allowed:
      - Statische HTML-Struktur
      - Daten-Ausgabe
    forbidden:
      - UI-Logik
      - Interaktions-Logik
      - State Management

  # === APP (MVP) ===
  app_presenter:
    path_pattern: "/app/Presenter/**/*.php"
    role: interaction_logic
    allowed:
      - Interaktions-Logik
      - UI State Management
      - UI Validation (syntaktisch)
      - Aufrufe zu /src/UseCases
    forbidden:
      - Domain-Logik
      - Semantische Validierung
      - Direkter Infrastructure-Zugriff

  app_view:
    path_pattern: "/app/View/**/*.php"
    role: passive_view
    allowed:
      - Raw Event Forwarding
      - Data Display
    forbidden:
      - Event Mapping
      - Conditional Logic (außer Anzeige)
      - State Management
      - Aufrufe zu /src

# =============================================================================
# DEPENDENCY RULES
# =============================================================================
dependency_rules:
  allowed_imports:
    - from: "/app/Presenter/**"
      to: "/src/UseCases/**"
      reason: "Presenter darf Use Cases aufrufen"

    - from: "/src/Controller/**"
      to: "/src/UseCases/**"
      reason: "Controller orchestriert Use Cases"

    - from: "/src/UseCases/**"
      to: "/src/Domain/**"
      reason: "Use Cases nutzen Domain"

    - from: "/src/Infrastructure/**"
      to: "/src/Domain/**"
      reason: "Infrastructure implementiert Domain-Interfaces"

  forbidden_imports:
    - from: "/src/**"
      to: "/app/**"
      severity: critical
      reason: "src darf nicht von app abhängen"

    - from: "/app/**"
      to: "/src/Infrastructure/**"
      severity: critical
      reason: "app darf nicht direkt auf Infrastructure zugreifen"

    - from: "/app/View/**"
      to: "/app/Presenter/**"
      severity: critical
      reason: "View darf Presenter nicht importieren (passive view)"

    - from: "/src/Domain/**"
      to: "/src/Infrastructure/**"
      severity: critical
      reason: "Domain darf nicht von Infrastructure abhängen"

  cycles:
    forbidden: true
    severity: critical

# =============================================================================
# VALIDATION FACTORS
# =============================================================================
validation_factors:

  directory_structure:
    priority: 1
    severity: critical
    description: Erwartete Verzeichnisstruktur muss existieren
    validation:
      method: directory_existence_check
      required_directories:
        - /src/Domain
        - /src/UseCases
        - /src/Infrastructure
        - /app/Presenter

  file_placement:
    priority: 2
    severity: critical
    description: Dateien müssen im korrekten Layer liegen
    validation:
      method: path_role_validation
      rules:
        - "*Presenter.php muss in /app/Presenter liegen"
        - "*Controller.php muss in /src/Controller liegen"
        - "*Repository.php muss in /src/Infrastructure liegen"
        - "Entity/*.php muss in /src/Domain liegen"

  import_compliance:
    priority: 3
    severity: critical
    description: Import-Statements müssen Dependency Rules einhalten
    validation:
      method: static_import_analysis
      checks:
        - Extrahiere alle use-Statements
        - Mappe auf Layer
        - Prüfe gegen allowed_imports
        - Prüfe gegen forbidden_imports

  layer_logic_compliance:
    priority: 4
    severity: major
    description: Code-Inhalte müssen Layer-Rolle entsprechen
    validation:
      method: code_pattern_analysis
      checks:
        - Domain enthält keine $_GET, $_POST, $_SESSION
        - View enthält keine new-Statements für Services
        - Presenter enthält keine SQL-Queries

  cycle_detection:
    priority: 5
    severity: critical
    description: Keine zyklischen Abhängigkeiten zwischen Layern
    validation:
      method: dependency_graph_analysis

# =============================================================================
# PROHIBITIONS (explizite Verbote)
# =============================================================================
prohibitions:
  - name: presenter_in_src
    pattern: "/src/**/Presenter*.php"
    severity: critical
    message: "Presenter gehören nach /app/Presenter, nicht nach /src"

  - name: controller_in_app
    pattern: "/app/**/Controller*.php"
    severity: critical
    message: "Controller gehören nach /src/Controller, nicht nach /app"

  - name: domain_logic_in_app
    indicators:
      - "Business rule implementations"
      - "Entity definitions"
      - "Value object definitions"
    severity: critical
    message: "Domain-Logik gehört nach /src/Domain"

  - name: infrastructure_in_presenter
    indicators:
      - "PDO usage"
      - "file_get_contents"
      - "curl calls"
    severity: critical
    message: "Presenter darf nicht direkt auf Infrastructure zugreifen"

# =============================================================================
# PASS THRESHOLD
# =============================================================================
pass_threshold:
  critical_violations_max: 0
  major_violations_max: 2
  minor_violations_max: 5

  outcome_logic:
    - condition: "critical_violations > 0"
      result: architecture_rejected
    - condition: "major_violations > 2"
      result: revision_required
    - condition: "all within limits"
      result: architecture_approved

# =============================================================================
# ENFORCEMENT
# =============================================================================
enforcement:
  on_new_file:
    rule: "Datei muss in korrektem Layer-Verzeichnis liegen"
    action: "BLOCKIERT bei falschem Pfad"

  on_import_change:
    rule: "Neue Imports müssen Dependency Rules einhalten"
    action: "BLOCKIERT bei forbidden import"

  before_sync_to_prod:
    rule: "Alle Architektur-Checks müssen bestanden sein"
    action: "KEIN SYNC bei critical violations"

Aktionen

Bearbeiten

← Zurück zur Übersicht