Projektarbeit-MYP/docs/PROJECT_STRUCTURE.md

175 lines
6.8 KiB
Markdown

# 🏗️ 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)