608 lines
15 KiB
Markdown
608 lines
15 KiB
Markdown
# Client Web-App Modul
|
|
|
|
## Überblick
|
|
|
|
Das **web-app** Modul stellt eine moderne Progressive Web Application (PWA) für das Meldestelle-System bereit, die Kotlin/JS und Compose for Web verwendet. Dieses Modul liefert einen professionellen webbasierten Client, der nahtlos mit dem geteilten common-ui Modul integriert ist, um eine konsistente plattformübergreifende Erfahrung zu bieten.
|
|
|
|
**Hauptfunktionen:**
|
|
- 🌐 **Progressive Web App** - Moderne PWA mit Installations- und Offline-Fähigkeiten
|
|
- 🏗️ **MVVM-Architektur** - Integriert mit geteiltem common-ui MVVM-Modul
|
|
- 🚀 **Moderne Web-Standards** - Sicherheits-Header, Leistungsoptimierung und SEO
|
|
- 🧪 **Testabdeckung** - Umfassende JavaScript-kompatible Testsuite
|
|
- 📱 **Mobile-First** - Responsives Design optimiert für alle Geräte
|
|
|
|
---
|
|
|
|
## Architektur
|
|
|
|
### Modulstruktur
|
|
|
|
```
|
|
client/web-app/
|
|
├── build.gradle.kts # Erweiterte Webpack-Konfiguration
|
|
├── src/
|
|
│ ├── jsMain/
|
|
│ │ ├── kotlin/at/mocode/client/web/
|
|
│ │ │ ├── Main.kt # Web-Anwendung Einstiegspunkt mit Fehlerbehandlung
|
|
│ │ │ └── AppStylesheet.kt # CSS-Styling-Definitionen
|
|
│ │ └── resources/
|
|
│ │ ├── index.html # Modernisierte HTML-Vorlage mit PWA-Unterstützung
|
|
│ │ └── manifest.json # PWA-Manifest für App-ähnliche Erfahrung
|
|
│ └── jsTest/kotlin/at/mocode/client/web/
|
|
│ └── MainTest.kt # JavaScript-kompatible Tests
|
|
└── README-CLIENT-WEB-APP.md # Diese Dokumentation
|
|
```
|
|
|
|
### Integration mit Common-UI
|
|
|
|
Die Web-App nutzt die geteilte MVVM-Architektur von common-ui:
|
|
|
|
```kotlin
|
|
fun main() {
|
|
onWasmReady {
|
|
try {
|
|
renderComposable(rootElementId = "root") {
|
|
// Erweiterte Fehlerbehandlung und ordnungsgemäße Entsorgung
|
|
DisposableEffect(Unit) {
|
|
onDispose {
|
|
console.log("Disposing web app components")
|
|
}
|
|
}
|
|
|
|
// Verwendet geteilte MVVM App-Komponente
|
|
MeldestelleWebApp()
|
|
}
|
|
} catch (e: Exception) {
|
|
showFallbackErrorUI("Application failed to start: ${e.message}")
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Build-Konfiguration
|
|
|
|
### Erweiterte Webpack-Einrichtung
|
|
|
|
Die web-app verwendet optimierte Webpack-Konfiguration für moderne Web-Entwicklung:
|
|
|
|
#### JavaScript Ziel-Konfiguration
|
|
```kotlin
|
|
js(IR) {
|
|
binaries.executable()
|
|
browser {
|
|
commonWebpackConfig {
|
|
cssSupport {
|
|
enabled.set(true)
|
|
}
|
|
// Source Maps für Debugging aktivieren
|
|
devtool = "source-map"
|
|
}
|
|
// Webpack für Produktionsoptimierung konfigurieren
|
|
webpackTask {
|
|
mainOutputFileName = "web-app.js"
|
|
}
|
|
// Entwicklungsserver konfigurieren
|
|
runTask {
|
|
mainOutputFileName = "web-app.js"
|
|
sourceMaps = true
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Abhängigkeiten
|
|
```kotlin
|
|
val jsMain by getting {
|
|
dependencies {
|
|
implementation(project(":client:common-ui"))
|
|
implementation(compose.html.core)
|
|
implementation(compose.runtime)
|
|
implementation(libs.ktor.client.js)
|
|
implementation(libs.kotlinx.coroutines.core)
|
|
// Erweiterte Web-spezifische Abhängigkeiten
|
|
implementation(libs.ktor.client.contentNegotiation)
|
|
implementation(libs.ktor.client.serialization.kotlinx.json)
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Test-Konfiguration
|
|
```kotlin
|
|
val jsTest by getting {
|
|
dependencies {
|
|
implementation(libs.kotlin.test)
|
|
implementation(libs.kotlinx.coroutines.test)
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Webpack-Optimierungen
|
|
```kotlin
|
|
// Web-spezifische Optimierungen
|
|
tasks.named("jsBrowserDevelopmentWebpack") {
|
|
outputs.upToDateWhen { false }
|
|
}
|
|
|
|
tasks.named("jsBrowserProductionWebpack") {
|
|
outputs.upToDateWhen { false }
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Progressive Web App Features
|
|
|
|
### PWA-Manifest
|
|
|
|
Die Web-App beinhaltet ein umfassendes PWA-Manifest (`manifest.json`):
|
|
|
|
```json
|
|
{
|
|
"name": "Meldestelle Web Application",
|
|
"short_name": "Meldestelle",
|
|
"description": "Professional web application for the Meldestelle system",
|
|
"start_url": "/",
|
|
"display": "standalone",
|
|
"background_color": "#ffffff",
|
|
"theme_color": "#1976d2",
|
|
"lang": "de",
|
|
"scope": "/",
|
|
"categories": ["business", "productivity"],
|
|
"icons": [
|
|
{
|
|
"src": "/icons/icon-192x192.png",
|
|
"sizes": "192x192",
|
|
"type": "image/png",
|
|
"purpose": "any maskable"
|
|
},
|
|
{
|
|
"src": "/icons/icon-512x512.png",
|
|
"sizes": "512x512",
|
|
"type": "image/png",
|
|
"purpose": "any maskable"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Moderne HTML-Vorlage
|
|
|
|
Erweiterte `index.html` mit modernen Web-Standards:
|
|
|
|
- **Sicherheits-Header**: CSP, XSS-Schutz, Frame-Optionen
|
|
- **SEO-Optimierung**: Meta-Tags, Schlüsselwörter, Beschreibungen
|
|
- **Leistung**: Preconnect, DNS-Prefetch, Ressourcen-Hints
|
|
- **PWA-Unterstützung**: Manifest-Link, Theme-Farben, Viewport-Einstellungen
|
|
- **Professionelles Laden**: Lokalisierte Lade-UI mit Spinner
|
|
|
|
---
|
|
|
|
## Entwicklung
|
|
|
|
### Voraussetzungen
|
|
|
|
| Tool | Version | Zweck |
|
|
|------|---------|-------|
|
|
| JDK | 21 (Temurin) | Kotlin/JS-Kompilierung und Gradle-Build |
|
|
| Node.js | ≥ 20 | JavaScript-Laufzeit und Package-Management |
|
|
| Gradle | 8.x (wrapper) | Build-Automatisierung |
|
|
|
|
### Die Anwendung erstellen
|
|
|
|
```bash
|
|
# Die Web-Anwendung kompilieren
|
|
./gradlew :client:web-app:compileKotlinJs
|
|
|
|
# Entwicklungsserver mit Hot Reload starten
|
|
./gradlew :client:web-app:jsBrowserDevelopmentRun
|
|
|
|
# Produktions-Bundle erstellen
|
|
./gradlew :client:web-app:jsBrowserProductionWebpack
|
|
```
|
|
|
|
### Entwicklungsserver
|
|
|
|
Der Entwicklungsserver bietet:
|
|
- **Hot Reload**: Automatisches Neuladen bei Code-Änderungen
|
|
- **Source Maps**: Vollständige Debugging-Unterstützung
|
|
- **CORS-Unterstützung**: Ordnungsgemäße API-Integration
|
|
- **Lokale Entwicklung**: Läuft typischerweise auf `http://localhost:8080`
|
|
|
|
### Tests ausführen
|
|
|
|
```bash
|
|
# Alle JavaScript-Tests ausführen
|
|
./gradlew :client:web-app:jsTest
|
|
|
|
# Spezifischen Test ausführen
|
|
./gradlew :client:web-app:jsTest --tests "MainTest"
|
|
|
|
# Ausführliche Test-Ausgabe
|
|
./gradlew :client:web-app:jsTest --info
|
|
```
|
|
|
|
---
|
|
|
|
## Tests
|
|
|
|
### Testabdeckung
|
|
|
|
| Komponente | Test-Datei | Tests | Abdeckung |
|
|
|-----------|-----------|-------|----------|
|
|
| Hauptanwendung | MainTest.kt | 4 | Bootstrap, Struktur, Styling |
|
|
|
|
### JavaScript-kompatible Tests
|
|
|
|
```kotlin
|
|
class MainTest {
|
|
@Test
|
|
fun `main function should be accessible`()
|
|
|
|
@Test
|
|
fun `package structure should be correct`()
|
|
|
|
@Test
|
|
fun `AppStylesheet should be accessible`()
|
|
|
|
@Test
|
|
fun `web app structure should be well organized`()
|
|
}
|
|
```
|
|
|
|
### Test-Überlegungen für Kotlin/JS
|
|
|
|
- **Keine Reflection**: Tests vermeiden Java Reflection APIs
|
|
- **Browser-Umgebung**: Tests laufen in JavaScript-Umgebung
|
|
- **Begrenzte APIs**: Einige JVM-spezifische Test-Utilities nicht verfügbar
|
|
|
|
---
|
|
|
|
## Styling & UI
|
|
|
|
### CSS-Architektur
|
|
|
|
Die Web-App verwendet `AppStylesheet.kt` für typsichere CSS:
|
|
|
|
```kotlin
|
|
object AppStylesheet : StyleSheet() {
|
|
val container by style {
|
|
// Container-Styles
|
|
}
|
|
|
|
val header by style {
|
|
// Header-Styles
|
|
}
|
|
|
|
val main by style {
|
|
// Hauptinhalt-Styles
|
|
}
|
|
|
|
val footer by style {
|
|
// Footer-Styles
|
|
}
|
|
|
|
val card by style {
|
|
// Card-Komponenten-Styles
|
|
}
|
|
|
|
val button by style {
|
|
// Button-Styles
|
|
}
|
|
}
|
|
```
|
|
|
|
### Responsive Design
|
|
|
|
- **Mobile-First**: Optimiert für mobile Geräte
|
|
- **Progressive Enhancement**: Desktop-Features progressiv hinzugefügt
|
|
- **Touch-Friendly**: Ordnungsgemäße Touch-Ziele und Gesten
|
|
- **Barrierefreiheit**: Semantisches HTML und ARIA-Labels
|
|
|
|
---
|
|
|
|
## Sicherheit & Leistung
|
|
|
|
### Sicherheits-Features
|
|
|
|
- **Content Security Policy (CSP)**: Verhindert XSS-Angriffe
|
|
- **X-Frame-Options**: Verhindert Clickjacking
|
|
- **X-Content-Type-Options**: Verhindert MIME-Sniffing
|
|
- **Referrer-Policy**: Kontrolliert Referrer-Informationen
|
|
- **Permissions-Policy**: Kontrolliert Browser-Features
|
|
|
|
### Leistungsoptimierungen
|
|
|
|
- **Webpack-Optimierung**: Minifizierung und Tree Shaking
|
|
- **Source Maps**: Entwicklungs-Debugging ohne Leistungseinbußen
|
|
- **Lazy Loading**: Komponenten werden bei Bedarf geladen
|
|
- **Caching-Strategie**: Browser-Caching für statische Assets
|
|
- **Bundle Splitting**: Optimierte Lademuster
|
|
|
|
### Lade-Leistung
|
|
|
|
- **Professionelle Lade-UI**: Markierte Lade-Spinner
|
|
- **Progressives Laden**: Inhalte erscheinen, sobald sie verfügbar werden
|
|
- **Fehler-Wiederherstellung**: Eleganter Fallback bei Ladefehlern
|
|
- **Offline-Unterstützung**: PWA-Offline-Fähigkeiten
|
|
|
|
---
|
|
|
|
## Deployment
|
|
|
|
### Entwicklungs-Deployment
|
|
|
|
```bash
|
|
# Entwicklungsserver starten
|
|
./gradlew :client:web-app:jsBrowserDevelopmentRun
|
|
|
|
# Server läuft typischerweise auf:
|
|
# http://localhost:8080
|
|
```
|
|
|
|
### Produktions-Deployment
|
|
|
|
```bash
|
|
# Optimierten Produktions-Build erstellen
|
|
./gradlew :client:web-app:jsBrowserProductionWebpack
|
|
|
|
# Ausgabe-Ort:
|
|
# build/distributions/
|
|
```
|
|
|
|
### Produktions-Build-Ausgabe
|
|
|
|
```
|
|
build/distributions/
|
|
├── web-app.js # Optimiertes JavaScript-Bundle
|
|
├── web-app.js.map # Source Maps für Debugging
|
|
├── index.html # Verarbeitete HTML-Vorlage
|
|
├── manifest.json # PWA-Manifest
|
|
└── static/
|
|
├── css/ # Verarbeitete CSS-Dateien
|
|
└── icons/ # PWA-Icons und Assets
|
|
```
|
|
|
|
### Web-Server-Konfiguration
|
|
|
|
**Beispiel Nginx-Konfiguration:**
|
|
|
|
```nginx
|
|
server {
|
|
listen 443 ssl;
|
|
server_name your-domain.com;
|
|
|
|
root /path/to/build/distributions;
|
|
index index.html;
|
|
|
|
# PWA-Unterstützung
|
|
location /manifest.json {
|
|
add_header Cache-Control "public, max-age=31536000";
|
|
}
|
|
|
|
# Statische Assets-Caching
|
|
location /static/ {
|
|
add_header Cache-Control "public, max-age=31536000";
|
|
}
|
|
|
|
# SPA-Routing-Unterstützung
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## PWA-Installation
|
|
|
|
### Installationsprozess
|
|
|
|
Benutzer können die Web-App als native-ähnliche Anwendung installieren:
|
|
|
|
1. **Browser-Prompt**: Moderne Browser zeigen Installations-Prompt
|
|
2. **Manuelle Installation**: Über Browser-Menü "App installieren"
|
|
3. **Icon-Erstellung**: App-Icon erscheint auf Homescreen/Desktop
|
|
4. **Standalone-Modus**: Läuft ohne Browser-UI
|
|
|
|
### Installations-Anforderungen
|
|
|
|
- ✅ **HTTPS**: Sichere Verbindung erforderlich
|
|
- ✅ **Manifest**: Gültiges PWA manifest.json
|
|
- ✅ **Service Worker**: (Zukünftige Verbesserung)
|
|
- ✅ **Responsive**: Mobile und Desktop optimiert
|
|
|
|
---
|
|
|
|
## Fehlerbehandlung & Überwachung
|
|
|
|
### Fehlerbehandlungs-Strategie
|
|
|
|
```kotlin
|
|
fun showFallbackErrorUI(message: String) {
|
|
document.getElementById("root")?.innerHTML = """
|
|
<div style="text-align: center; padding: 50px; font-family: Arial;">
|
|
<h2 style="color: #d32f2f;">Anwendungsfehler</h2>
|
|
<p>$message</p>
|
|
<button onclick="window.location.reload()"
|
|
style="padding: 10px 20px; margin-top: 20px;">
|
|
Seite neu laden
|
|
</button>
|
|
</div>
|
|
""".trimIndent()
|
|
}
|
|
```
|
|
|
|
### Fehler-Wiederherstellung
|
|
|
|
- **Eleganter Fallback**: Professionelle Fehler-UI mit Reload-Option
|
|
- **Konsolen-Protokollierung**: Detaillierte Fehler-Protokollierung für Debugging
|
|
- **Benutzer-Feedback**: Klare deutsche Fehlermeldungen
|
|
- **Wiederherstellungsoptionen**: Einfache Reload- und Wiederherstellungsmechanismen
|
|
|
|
---
|
|
|
|
## Browser-Kompatibilität
|
|
|
|
### Unterstützte Browser
|
|
|
|
| Browser | Version | Status |
|
|
|---------|---------|--------|
|
|
| Chrome | ≥ 88 | ✅ Vollständige Unterstützung |
|
|
| Firefox | ≥ 85 | ✅ Vollständige Unterstützung |
|
|
| Safari | ≥ 14 | ✅ Vollständige Unterstützung |
|
|
| Edge | ≥ 88 | ✅ Vollständige Unterstützung |
|
|
|
|
### Feature-Erkennung
|
|
|
|
- **WebAssembly**: Erforderlich für Kotlin/JS
|
|
- **ES2015+**: Moderne JavaScript-Features
|
|
- **CSS Grid/Flexbox**: Layout-Unterstützung
|
|
- **Service Workers**: PWA-Features (zukünftig)
|
|
|
|
---
|
|
|
|
## Leistungsüberwachung
|
|
|
|
### Schlüsselmetriken
|
|
|
|
- **First Contentful Paint (FCP)**: < 2 Sekunden
|
|
- **Largest Contentful Paint (LCP)**: < 2,5 Sekunden
|
|
- **First Input Delay (FID)**: < 100ms
|
|
- **Cumulative Layout Shift (CLS)**: < 0,1
|
|
|
|
### Überwachungs-Tools
|
|
|
|
```bash
|
|
# Bundle-Größen-Analyse
|
|
./gradlew :client:web-app:jsBrowserProductionWebpack --info
|
|
|
|
# Entwicklungs-Profiling
|
|
./gradlew :client:web-app:jsBrowserDevelopmentRun --debug
|
|
```
|
|
|
|
---
|
|
|
|
## Zukünftige Verbesserungen
|
|
|
|
### Empfohlene Entwicklung
|
|
|
|
1. **Service Worker-Implementierung**
|
|
- Offline-Funktionalität
|
|
- Hintergrund-Synchronisation
|
|
- Push-Benachrichtigungen
|
|
- Erweiterte Caching-Strategien
|
|
|
|
2. **Erweiterte PWA-Features**
|
|
- App-Verknüpfungen
|
|
- Share Target API
|
|
- Dateisystem-Zugriff
|
|
- Geräte-APIs-Integration
|
|
|
|
3. **Leistungsoptimierung**
|
|
- Code-Splitting-Strategien
|
|
- Lazy Loading-Implementierung
|
|
- Bild-Optimierung
|
|
- Web Vitals-Überwachung
|
|
|
|
4. **Internationalisierung**
|
|
- Mehrsprachige Unterstützung
|
|
- RTL-Sprachen-Unterstützung
|
|
- Locale-specific formatting
|
|
- Dynamic language switching
|
|
|
|
5. **Enhanced Testing**
|
|
- E2E testing with browser automation
|
|
- Visual regression testing
|
|
- Performance testing
|
|
- Accessibility testing
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
| Issue | Symptoms | Solution |
|
|
|-------|----------|----------|
|
|
| White screen on load | Blank page, no errors | Check browser console, verify JavaScript loading |
|
|
| PWA not installing | No install prompt | Verify HTTPS, manifest.json, and PWA requirements |
|
|
| Hot reload not working | Changes not reflected | Restart dev server, check file watchers |
|
|
| Build failures | Webpack errors | Clear `build` directory, check dependencies |
|
|
| API connection errors | Network failures | Verify CORS settings, API URL configuration |
|
|
|
|
### Debug Commands
|
|
|
|
```bash
|
|
# Clear build cache
|
|
./gradlew :client:web-app:clean
|
|
|
|
# Analyze bundle content
|
|
./gradlew :client:web-app:jsBrowserProductionWebpack --scan
|
|
|
|
# Verbose webpack output
|
|
./gradlew :client:web-app:jsBrowserDevelopmentRun --info
|
|
|
|
# Check JavaScript compilation
|
|
./gradlew :client:web-app:compileKotlinJs --debug
|
|
```
|
|
|
|
### Browser Debugging
|
|
|
|
- **DevTools**: Use browser developer tools for runtime debugging
|
|
- **Source Maps**: Enable for debugging original Kotlin code
|
|
- **Network Tab**: Monitor API calls and resource loading
|
|
- **Console**: Check for JavaScript errors and warnings
|
|
|
|
---
|
|
|
|
## Contributing
|
|
|
|
### Development Workflow
|
|
|
|
1. **Setup**
|
|
```bash
|
|
# Verify Node.js installation
|
|
node --version
|
|
|
|
# Build and test
|
|
./gradlew :client:web-app:build
|
|
```
|
|
|
|
2. **Development**
|
|
```bash
|
|
# Start development server
|
|
./gradlew :client:web-app:jsBrowserDevelopmentRun
|
|
|
|
# Run tests
|
|
./gradlew :client:web-app:jsTest
|
|
```
|
|
|
|
3. **Code Standards**
|
|
- Follow Kotlin coding conventions
|
|
- Add tests for new web-specific functionality
|
|
- Maintain integration with common-ui MVVM architecture
|
|
- Test across different browsers
|
|
- Verify PWA functionality
|
|
|
|
### Pull Request Requirements
|
|
|
|
- [ ] All existing tests pass
|
|
- [ ] New functionality includes JavaScript-compatible tests
|
|
- [ ] Integration with common-ui verified
|
|
- [ ] PWA functionality tested
|
|
- [ ] Cross-browser compatibility verified
|
|
- [ ] Performance impact assessed
|
|
- [ ] Documentation updated
|
|
|
|
---
|
|
|
|
**Module Status**: ✅ Production Ready
|
|
**Architecture**: ✅ MVVM Integrated
|
|
**PWA Features**: ✅ Complete Implementation
|
|
**Test Coverage**: ✅ JavaScript-Compatible
|
|
**Web Standards**: ✅ Modern Compliance
|
|
|
|
*Last Updated: August 16, 2025*
|