# πŸ—οΈ MYP Projektstruktur - Perfektionierte Architektur ## πŸ“‹ Übersicht MYP (Manage your Printer) ist ein containerbasiertes Microservice-System mit klarer Trennung zwischen Frontend und Backend. ## πŸ—‚οΈ Verzeichnisstruktur ``` Projektarbeit-MYP/ β”œβ”€β”€ πŸ–₯️ backend/ # Flask API Server (Port 5000) β”‚ β”œβ”€β”€ πŸ“ src/ # Hauptanwendungslogik β”‚ β”‚ β”œβ”€β”€ πŸ“ api/ # API Endpunkte β”‚ β”‚ β”œβ”€β”€ πŸ“ models/ # Datenmodelle β”‚ β”‚ β”œβ”€β”€ πŸ“ services/ # GeschΓ€ftslogik β”‚ β”‚ β”œβ”€β”€ πŸ“ auth/ # Authentifizierungslogik β”‚ β”‚ └── πŸ“ utils/ # Hilfsfunktionen β”‚ β”œβ”€β”€ πŸ“ tests/ # Unit- und Integrationstests β”‚ β”œβ”€β”€ πŸ“ migrations/ # Datenbankmigrationen β”‚ β”œβ”€β”€ πŸ“ instance/ # SQLite Datenbank (gitignore) β”‚ β”œβ”€β”€ πŸ“ logs/ # Anwendungslogs (gitignore) β”‚ β”œβ”€β”€ πŸ“ config/ # Konfigurationsdateien β”‚ β”œβ”€β”€ πŸ“„ Dockerfile # Backend Container β”‚ β”œβ”€β”€ πŸ“„ requirements.txt # Python AbhΓ€ngigkeiten β”‚ β”œβ”€β”€ πŸ“„ app.py # Flask Anwendung Einstiegspunkt β”‚ └── πŸ“„ .env.example # Umgebungsvariablen Vorlage β”‚ β”œβ”€β”€ 🌐 frontend/ # Next.js Web Interface (Port 3000) β”‚ β”œβ”€β”€ πŸ“ src/ # Hauptanwendungslogik β”‚ β”‚ β”œβ”€β”€ πŸ“ app/ # Next.js App Router β”‚ β”‚ β”œβ”€β”€ πŸ“ components/ # React Komponenten β”‚ β”‚ β”œβ”€β”€ πŸ“ lib/ # Bibliotheken und Utilities β”‚ β”‚ └── πŸ“ types/ # TypeScript Typdefinitionen β”‚ β”œβ”€β”€ πŸ“ public/ # Statische Assets β”‚ β”œβ”€β”€ πŸ“ drizzle/ # Frontend Datenbankschema β”‚ β”œβ”€β”€ πŸ“ tests/ # Frontend Tests β”‚ β”œβ”€β”€ πŸ“„ Dockerfile # Frontend Container β”‚ β”œβ”€β”€ πŸ“„ package.json # Node.js AbhΓ€ngigkeiten β”‚ β”œβ”€β”€ πŸ“„ next.config.mjs # Next.js Konfiguration β”‚ └── πŸ“„ .env.example # Umgebungsvariablen Vorlage β”‚ β”œβ”€β”€ πŸ”„ proxy/ # Caddy Reverse Proxy (Port 80/443) β”‚ β”œβ”€β”€ πŸ“„ Caddyfile # Proxy Konfiguration β”‚ └── πŸ“„ docker-compose.caddy.yml # Caddy Service Definition β”‚ β”œβ”€β”€ πŸ“Š monitoring/ # Überwachung und Logging β”‚ β”œβ”€β”€ πŸ“ grafana/ # Dashboards β”‚ β”œβ”€β”€ πŸ“ prometheus/ # Metriken β”‚ └── πŸ“„ docker-compose.monitoring.yml β”‚ β”œβ”€β”€ πŸ”§ infrastructure/ # Infrastruktur-Konfiguration β”‚ β”œβ”€β”€ πŸ“ scripts/ # Automatisierungsskripte β”‚ β”‚ β”œβ”€β”€ πŸ“„ start.sh # Linux/MacOS Start β”‚ β”‚ β”œβ”€β”€ πŸ“„ start.ps1 # Windows Start β”‚ β”‚ β”œβ”€β”€ πŸ“„ cleanup.sh # Linux/MacOS Bereinigung β”‚ β”‚ └── πŸ“„ cleanup.ps1 # Windows Bereinigung β”‚ β”œβ”€β”€ πŸ“ environments/ # Umgebungskonfigurationen β”‚ β”‚ β”œβ”€β”€ πŸ“„ development.env # Entwicklungsumgebung β”‚ β”‚ β”œβ”€β”€ πŸ“„ production.env # Produktionsumgebung β”‚ β”‚ └── πŸ“„ testing.env # Testumgebung β”‚ └── πŸ“ ssl/ # SSL Zertifikate (gitignore) β”‚ β”œβ”€β”€ πŸ“š docs/ # Projektdokumentation β”‚ β”œβ”€β”€ πŸ“„ API.md # API Dokumentation β”‚ β”œβ”€β”€ πŸ“„ DEPLOYMENT.md # Deployment Anweisungen β”‚ β”œβ”€β”€ πŸ“„ DEVELOPMENT.md # Entwicklungsrichtlinien β”‚ └── πŸ“„ ARCHITECTURE.md # Systemarchitektur β”‚ β”œβ”€β”€ πŸ§ͺ tests/ # Übergreifende Tests β”‚ β”œβ”€β”€ πŸ“ integration/ # Integrationstests β”‚ β”œβ”€β”€ πŸ“ e2e/ # End-to-End Tests β”‚ └── πŸ“„ docker-compose.test.yml # Test Environment β”‚ β”œβ”€β”€ πŸ“„ docker-compose.yml # Hauptkomposition (Prod) β”œβ”€β”€ πŸ“„ docker-compose.dev.yml # Entwicklungsumgebung β”œβ”€β”€ πŸ“„ docker-compose.override.yml # Lokale Overrides β”œβ”€β”€ πŸ“„ .gitignore # Git Ignorierte Dateien β”œβ”€β”€ πŸ“„ .dockerignore # Docker Ignorierte Dateien β”œβ”€β”€ πŸ“„ README.md # Projekt Hauptdokumentation └── πŸ“„ PROJECT_STRUCTURE.md # Diese Strukturdokumentation ``` ## πŸ”Œ Service-Kommunikation ### Interne Container-Kommunikation - **Frontend β†’ Backend**: `http://backend:5000/api` - **Proxy β†’ Frontend**: `http://frontend:3000` - **Proxy β†’ Backend**: `http://backend:5000` ### Externe Zugriffe - **Web Interface**: `https://localhost` (ΓΌber Caddy Proxy) - **API Direct**: `http://localhost:5000` (nur Entwicklung) - **Frontend Direct**: `http://localhost:3000` (nur Entwicklung) ## 🌐 Netzwerk-Architektur ``` Internet/Intranet ↓ [Caddy Proxy] (80/443) ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β” ↓ ↓ ↓ [Frontend] [Backend] [Monitoring] (3000) (5000) (9090/3001) ↓ ↓ [SQLite] [SQLite] ``` ## πŸ” Sicherheitskonzept ### Umgebungsvariablen - Sensible Daten nur ΓΌber `.env` Dateien - Produktionsgeheimnisse ΓΌber sichere Umgebungsvariablen - Keine Geheimnisse in Git-Repository ### Netzwerksicherheit - Container-isolierte Netzwerke - Nur notwendige Ports exponiert - HTTPS-VerschlΓΌsselung ΓΌber Caddy - Firewall-kompatible Konfiguration ### Authentifizierung - JWT-Token fΓΌr API-Authentifizierung - Session-basierte Frontend-Authentifizierung - OAuth2 Integration vorbereitet ## πŸš€ Deployment-Strategien ### Entwicklung ```bash # Linux/MacOS ./infrastructure/scripts/start.sh dev # Windows .\infrastructure\scripts\start.ps1 dev ``` ### Produktion ```bash # Linux/MacOS ./infrastructure/scripts/start.sh prod # Windows .\infrastructure\scripts\start.ps1 prod ``` ## πŸ“¦ Container-Optimierungen ### Multi-Stage Builds - Frontend: Node.js Build β†’ Minimales Runtime Image - Backend: Python Requirements β†’ Optimiertes Laufzeit-Image - Reduzierte Image-Grâßen und SicherheitsoberflΓ€che ### Health Checks - Automatische GesundheitsprΓΌfungen fΓΌr alle Services - Graceful Restart bei Fehlern - Monitoring-Integration ### Volume Management - Persistente Datenbank-Volumes - Log-Rotation und -Management - Backup-freundliche Struktur ## πŸ”„ CI/CD Integration ### Git Hooks - Pre-commit Linting und Testing - Automatische Dependency Updates - Security Scanning ### Container Registry - Automatisches Image Building - Versionierung ΓΌber Git Tags - Multi-Architecture Support (x86_64, ARM64)