Merge Phase 2 into the UI branch, so auth is built on top of it
Phase 3 auth is next, and this branch's server/ was still at Phase 1. Building
sessions here without merging first would have meant writing them against a
config.py with credentials still defaulted, no deps.py device auth to follow as
a pattern, and - the one that actually matters - no rate limiter, leaving a
login endpoint brute-forceable until the branches finally met.
So the branches meet now, while the only conflict is a documentation one, rather
than later on top of an auth implementation.
TODO.md was the single conflict: both sides had edited Phase 3, which is exactly
what should happen when one branch finishes Phase 2 and the other starts the UI.
Both sides' content is kept - the Phase 2 ticks and the UI decisions in 3.0 -
and the resolution fixed two things a purely textual merge leaves broken:
- "Minimal gallery page, no auth yet" is struck. SPEC 3.3 requires image
serving to be auth-checked, so that is not a state the gallery can
legitimately pass through, and the scaffold's System page already proves the
browser-to-Postgres path that item existed to prove.
- The themes line appeared twice, once ticked by the scaffold and once not.
The genuinely open half is persisting the choice per user, which needs
accounts, so that is what it now says.
web/ is untouched by the merge: it had no files at the merge base and none on
the server branch, so that side contributes no deletion. Verified - 27 files
before and after.
Verified both halves after resolving: server 194 passed, ruff clean, alembic
clean; UI typecheck clean, build green, 36 contrast pairs across 3 themes with
no failures.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
89ebe99bed
44 files changed
+6751
-95
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,596 @@
|
||||
# Code Review: poorBird Server (feature/Server_Basic_implementation)
|
||||
|
||||
**Reviewer:** Mistral Vibe
|
||||
**Date:** 2026-09-21
|
||||
**Branch:** feature/Server_Basic_implementation
|
||||
**Commit:** 142b476 (Server: Phase 2 (REVIEW not respected yet))
|
||||
**Version:** 0.1.0
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
**Status: Phase 1 COMPLETE, Phase 2 STARTED**
|
||||
|
||||
Der Server-Branch enthalt die **vollstandige Phase 1 Implementation** (Server Foundation) und erste Ansatze fur Phase 2. Die Code-Qualitat ist **exzellent** - die Architektur ist durchdacht, gut dokumentiert und production-ready. Allerdings gibt es **kritische Sicherheitsprobleme**, die **vor Phase 2/3** behoben werden mussen.
|
||||
|
||||
| Kategorie | Rating | Priority | Notes |
|
||||
|----------|--------|----------|-------|
|
||||
| **Architektur** | 5/5 | Niedrig | Sehr gut durchdacht, UI-ready |
|
||||
| **Sicherheit** | 2/5 | **Hoch** | **Muss vor Phase 2/3 fixen** |
|
||||
| **Performance** | 4/5 | Mittel | Gut fur aktuelle Skala |
|
||||
| **Code Qualitat** | 5/5 | Niedrig | Exzellent |
|
||||
| **Test Coverage** | 5/5 | Niedrig | 12/12 Tests passen |
|
||||
| **Dokumentation** | 5/5 | Niedrig | Ausgezeichnet |
|
||||
|
||||
---
|
||||
|
||||
## Branch Status
|
||||
|
||||
### Current State
|
||||
- **Branch Name:** feature/Server_Basic_implementation
|
||||
- **Commit:** 142b476 ("Server: Phase 2 (REVIEW not respected yet)")
|
||||
- **Phase:** 1 (Server Foundation) - **COMPLETE**
|
||||
- **Phase 2:** STARTED (Web-Build-Dateien vorhanden, aber keine Device-Endpoints)
|
||||
- **Relation:** Basis fur feature/UI_Basic_implementation
|
||||
|
||||
### Wichtige Beobachtung
|
||||
Dieser Branch ist der **kanonische Server-Branch**. Er enthalt:
|
||||
- ✅ Vollstandige Server-Infrastruktur (Phase 1)
|
||||
- ✅ Alle Datenbank-Modelle
|
||||
- ✅ Job-Queue mit PostgreSQL (FOR UPDATE SKIP LOCKED)
|
||||
- ✅ Health-Endpoints
|
||||
- ✅ Systemd-Units und Caddy-Konfiguration
|
||||
- ✅ migrations und Schema-Validierung
|
||||
- ❌ **Keine Device-Endpoints** (Phase 2 noch nicht implementiert)
|
||||
- ❌ **Keine Authentifizierung** (wird fur Phase 2/3 benotigt)
|
||||
|
||||
### Phasen-Information
|
||||
```
|
||||
Phase 1 (DONE): Server foundation, config, schema, health, job queue, scheduler
|
||||
Phase 2 (STARTED): Device endpoints (/enroll, /ingest, /heartbeat, /status, /config)
|
||||
Phase 3 (TARGET): WebUI (React+TS+Vite) - in feature/UI_Basic_implementation
|
||||
Phase 4: Device management, OTA
|
||||
Phase 5: Operations (backup, retention, alarms)
|
||||
Phase 6: Streaming
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 1. Projekt-Ubersicht
|
||||
|
||||
### Core Purpose
|
||||
Radar-gesteuertes Vogel-Kamera-System, das:
|
||||
1. Vogel mit LD2410 Radar-Sensor erkennt
|
||||
2. Bilder mit ESP32 Kamera aufnimmt
|
||||
3. Bilder uber MQTT an Server sendet
|
||||
4. Bilder und Metadaten in PostgreSQL speichert
|
||||
5. Web-Interface fur Anzeige und Verwaltung bereitstellt
|
||||
|
||||
### Domain
|
||||
- **Primar:** IoT + Computer Vision + Web Application
|
||||
- **Sekundar:** Datenverwaltung, Device Management, Benutzerverwaltung
|
||||
|
||||
### Benutzer-Typen
|
||||
| Benutzer-Typ | Zugriff | Use Cases |
|
||||
|-------------|---------|----------|
|
||||
| Device | API nur | Enroll, Bilder hochladen, Status senden |
|
||||
| Viewer | Nur Lesen | Galerie anzeigen, suchen, filtern |
|
||||
| Editor | Lesen+Schreiben | Anzeigen + Beobachtungen hinzufugen, Tags, Metadaten bearbeiten |
|
||||
| Admin | Voll | Alles von Editor + Device-Management, Benutzerverwaltung, Einstellungen |
|
||||
|
||||
### Technologie-Stack
|
||||
| Layer | Technologie | Version | Status |
|
||||
|-------|------------|---------|--------|
|
||||
| Backend | Python | 3.14.7 (verifiziert) | Phase 1 Complete |
|
||||
| Framework | FastAPI | Latest | Phase 1 Complete |
|
||||
| Database | PostgreSQL | 17 | Phase 1 Complete |
|
||||
| ORM | SQLAlchemy | 2.0 | Phase 1 Complete |
|
||||
| Migrations | Alembic | Latest | Phase 1 Complete |
|
||||
| Proxy | Caddy | 2.x | Phase 1 Complete |
|
||||
| Logging | structlog/stdout | - | Phase 1 Complete |
|
||||
|
||||
### Skalierungs-Erwartungen
|
||||
| Metrik | Wert | Notes |
|
||||
|--------|------|-------|
|
||||
| Kameras | 1-10 (Phase 3), 100+ (zukunftig) | Aktuell: 1 |
|
||||
| Captures/Tag | 5000 | 1 Kamera, ~10/Stunde |
|
||||
| Bild-Grose | 200-500KB | JPEG |
|
||||
| Thumb-Grose | 20-50KB | WebP, 400px |
|
||||
| Gleichzeitige Nutzer | 1-5 typisch, 10 peak | LAN-only |
|
||||
| Storage/Monat | ~1GB | 5000 Bilder * 200KB |
|
||||
|
||||
---
|
||||
|
||||
## 2. Architektur-Analyse
|
||||
|
||||
### Was bereits vorhanden ist (Phase 1)
|
||||
|
||||
#### ✅ **Konfiguration**
|
||||
- `config.py`: Alle Werte aus Umgebungsvariablen (keine Hardcoded-Werte)
|
||||
- `POORBIRD_` Prefix fur alle Variablen
|
||||
- Gute Trennung von database, http, storage, devices, worker, logging
|
||||
- **Kritikpunkt:** database_url hat Standardwert mit Credentials (siehe SEC-008)
|
||||
|
||||
#### ✅ **Datenbank**
|
||||
- `db.py`: SQLAlchemy Engine + Session Factory
|
||||
- Sync SQLAlchemy (bewusste Entscheidung, kein Async)
|
||||
- Connection Pool: 5 (kann fur Phase 3 erhoht werden)
|
||||
- `schema_compare.py`: Normalisierung von Server-Defaults (geniale Losung!)
|
||||
- Verhindert falsche Drift-Meldungen durch Postgres-Type-Casts
|
||||
- Gleiche Logik fur Migrationen und Tests
|
||||
|
||||
#### ✅ **Modelle**
|
||||
- Vollstandiges Schema nach SPEC S3
|
||||
- Alle Tabellen: users, sessions, devices, captures, observations, taxa, tags, firmware, device_commands, device_status, settings, audit_log, backup_runs, jobs
|
||||
- Gute Beziehungen und Constraints
|
||||
- JSONB fur flexible Konfiguration (device.config)
|
||||
|
||||
#### ✅ **API**
|
||||
- `app.py`: FastAPI App mit Lifespan Management
|
||||
- Health-Endpoints: `/api/v1/health`, `/healthz`
|
||||
- API-Prefix: `/api/v1/`
|
||||
- Gute Fehlerbehandlung und Logging
|
||||
|
||||
#### ✅ **Job-Queue**
|
||||
- `queue.py`: PostgreSQL-basierte Queue mit FOR UPDATE SKIP LOCKED
|
||||
- Keine Redis-Abhangigkeit (SPEC 6)
|
||||
- Handler: noop, prune_expired_commands
|
||||
- Scheduler in `worker/main.py`
|
||||
- Worker claimt Jobs und verarbeitet sie sequentiell
|
||||
|
||||
#### ✅ **CLI**
|
||||
- `cli.py`: serve, worker, migrate, check, enqueue
|
||||
- `poorbird check`: Validiert Config, Pfade, Datenbank
|
||||
- `poorbird serve`: Startet API
|
||||
- `poorbird worker`: Startet Worker + Scheduler
|
||||
- `poorbird migrate`: Wendet Migrationen an
|
||||
|
||||
#### ✅ **Deployment**
|
||||
- systemd-Units: `poorbird-api.service`, `poorbird-worker.service`
|
||||
- Caddyfile mit DNS-01 TLS, Image-Handoff, Camera-Listener
|
||||
- Installationsanleitung in `deploy/INSTALL.md`
|
||||
- Windows-Entwicklung mit uv + Podman dokumentiert
|
||||
|
||||
### Was fehlt fur Phase 2/3
|
||||
|
||||
#### ❌ **Device-Endpoints** (Phase 2)
|
||||
- `/api/v1/enroll` - Device-Registrierung
|
||||
- `/api/v1/ingest` - Bild-Hochladen
|
||||
- `/api/v1/heartbeat` - Device-Status
|
||||
- `/api/v1/status` - Device-Statistik
|
||||
- `/api/v1/config` - Device-Konfiguration
|
||||
- `/api/v1/firmware` - Firmware-Upload
|
||||
|
||||
#### ❌ **Authentifizierung**
|
||||
- Keine Device-Authentifizierung
|
||||
- Keine User-Authentifizierung (fur WebUI)
|
||||
- Keine Session-Verwaltung
|
||||
- Kein Passwort-Hashing
|
||||
- Keine CSRF-Schutz
|
||||
- Keine Rate-Limiting
|
||||
|
||||
#### ❌ **CORS**
|
||||
- Keine CORS-Konfiguration (wird fur WebUI benotigt)
|
||||
|
||||
---
|
||||
|
||||
## 3. Sicherheits-Analyse
|
||||
|
||||
### Severity-System
|
||||
- **KRITISCH:** Muss vor Phase 2/3 behoben werden. Blockiert Produktion.
|
||||
- **HOCH:** Muss vor Phase 3 behoben werden. Ernstes Risiko.
|
||||
- **MITTEL:** Sollte vor Phase 3 behoben werden. Moderates Risiko.
|
||||
- **NIEDRIG:** Nice to have. Geringes Risiko.
|
||||
|
||||
### KRITISCHE Probleme (BLOCK PHASE 2/3)
|
||||
|
||||
#### SEC-001: Enroll Secret im Klartext
|
||||
- **Ort:** config.py:53, .env-Dateien, systemd EnvironmentFile
|
||||
- **Code:** `enroll_secret: SecretStr = SecretStr("")`
|
||||
- **Problem:** Bootstrap Secret wird in Dateien im Klartext gespeichert
|
||||
- **Risiko:** Dateisystem-Zugriff = vollstandige Device-Spoofing. Wenn UI Device-Management freigibt, kann Angreifer bösartige Gerate registrieren.
|
||||
- **Auswirkung:** Katastrophal. Gefahrdet gesamten Device-Netzwerk.
|
||||
- **Lösung:**
|
||||
```python
|
||||
# Option 1: Nur uber CLI setzen
|
||||
enroll_secret: SecretStr # Kein Standardwert
|
||||
# Nur setzen uber: poorbird config set enroll_secret <wert>
|
||||
|
||||
# Option 2: Environment-Variable ohne Standard
|
||||
enroll_secret: SecretStr
|
||||
```
|
||||
- **Dateien zu andern:** config.py, deploy/poorbird.env.example
|
||||
- **Tests:** Verifizieren, dass Secret nicht geloggt wird
|
||||
- **Prioritat:** KRITISCH
|
||||
- **Aufwand:** 2-4 Stunden
|
||||
|
||||
#### SEC-002: Keine Request-Authentifizierung
|
||||
- **Ort:** Alle API-Endpoints
|
||||
- **Problem:** Keine Authentifizierung fur beliebige Endpoints
|
||||
- **Risiko:** Jeder kann Device-Kommandos senden, Admin-Funktionen nutzen, Benutzer verwalten
|
||||
- **Auswirkung:** Vollstandiger System-Kompromiss
|
||||
- **Lösung:**
|
||||
```python
|
||||
# Device-Auth (fur /enroll, /ingest, /heartbeat, /status)
|
||||
from fastapi import Request, HTTPException, Header
|
||||
|
||||
async def verify_device(request: Request,
|
||||
x_enroll_secret: str = Header(None)):
|
||||
if not x_enroll_secret:
|
||||
raise HTTPException(status_code=401)
|
||||
# Verifizieren gegen enroll_secret Hash
|
||||
|
||||
# User-Auth (fur UI-Endpoints)
|
||||
from fastapi import Cookie
|
||||
|
||||
async def verify_user(request: Request,
|
||||
session_id: str = Cookie(None)):
|
||||
if not session_id:
|
||||
raise HTTPException(status_code=401)
|
||||
# Verifizieren Session in DB
|
||||
```
|
||||
- **Dateien zu erstellen:** api/routes/auth.py, api/deps.py
|
||||
- **Dateien zu andern:** app.py
|
||||
- **Prioritat:** KRITISCH
|
||||
- **Aufwand:** 1-2 Tage
|
||||
|
||||
#### SEC-003: Keine Input-Validierung
|
||||
- **Ort:** queue.py:47-66 (enqueue-Funktion), alle zukunftigen Endpoints
|
||||
- **Problem:** Payloads werden nicht vor DB-Insert validiert
|
||||
- **Risiko:** SQL Injection, XSS, bosartige Daten, Datenkorruption
|
||||
- **Auswirkung:** Hoch. UI akzeptiert User-Input
|
||||
- **Lösung:**
|
||||
```python
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Literal, Optional, Union
|
||||
|
||||
class NoopJobPayload(BaseModel):
|
||||
message: Optional[str] = None
|
||||
|
||||
class ThumbnailJobPayload(BaseModel):
|
||||
capture_id: str # UUID
|
||||
quality: int = Field(ge=1, le=100)
|
||||
width: int = Field(ge=100, le=2000)
|
||||
|
||||
JobPayload = Union[NoopJobPayload, ThumbnailJobPayload]
|
||||
|
||||
def enqueue(session: Session,
|
||||
kind: Literal["noop", "thumbnail"],
|
||||
payload: JobPayload,
|
||||
...):
|
||||
# Payload ist jetzt validiert!
|
||||
```
|
||||
- **Dateien zu erstellen:** api/schemas.py
|
||||
- **Dateien zu andern:** queue.py, alle Route-Dateien
|
||||
- **Prioritat:** KRITISCH
|
||||
- **Aufwand:** 1-2 Tage
|
||||
|
||||
### HOHE Priorität (FIX BEFORE PHASE 2/3)
|
||||
|
||||
#### SEC-004: Keine Rate-Limiting
|
||||
- **Ort:** API-Layer (app.py)
|
||||
- **Problem:** Kein Schutz vor DoS oder Brute Force
|
||||
- **Risiko:** API-Endpoints konnen uberflutet werden
|
||||
- **Lösung:** slowapi oder FastAPI-Limiter
|
||||
- **Prioritat:** HOCH
|
||||
- **Aufwand:** 1 Tag
|
||||
|
||||
#### SEC-005: Keine CORS-Konfiguration
|
||||
- **Ort:** API-Layer
|
||||
- **Problem:** Keine CORS-Header konfiguriert
|
||||
- **Risiko:** WebUI kann keine Requests machen (auch localhost:3000)
|
||||
- **Lösung:**
|
||||
```python
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:3000", "http://localhost:5173", "https://poorbird.local"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
```
|
||||
- **Prioritat:** HOCH
|
||||
- **Aufwand:** 1 Stunde
|
||||
|
||||
#### SEC-006: DB-URL mit Credentials in Defaults
|
||||
- **Ort:** config.py:30
|
||||
- **Problem:** Standardwert enthalt Credentials im Klartext
|
||||
- **Risiko:** Accidentelles Committen von Credentials
|
||||
- **Lösung:**
|
||||
```python
|
||||
# Andern von:
|
||||
database_url: str = "postgresql+psycopg://poorbird:poorbird@127.0.0.1:5432/poorbird"
|
||||
|
||||
# Zu:
|
||||
database_url: str = "" # Muss uber POORBIRD_DATABASE_URL gesetzt werden
|
||||
```
|
||||
- **Prioritat:** HOCH
|
||||
- **Aufwand:** 1 Stunde
|
||||
|
||||
#### SEC-007: Keine Session-Verwaltung
|
||||
- **Ort:** models/users.py hat Session-Modell, aber nicht implementiert
|
||||
- **Problem:** Session-Tabelle existiert aber wird nicht genutzt
|
||||
- **Risiko:** User-Login/Logout nicht implementierbar
|
||||
- **Lösung:** Session-Cookie-Handling implementieren
|
||||
- **Prioritat:** HOCH
|
||||
- **Aufwand:** 1 Tag
|
||||
|
||||
### MITTLERE Priorität
|
||||
|
||||
#### SEC-008: Keine Passwort-Hashing-Implementierung
|
||||
- **Ort:** models/users.py (password_hash-Spalte existiert)
|
||||
- **Problem:** Keine Hashing-Implementierung vorhanden
|
||||
- **Lösung:** Argon2id implementieren
|
||||
- **Prioritat:** MITTEL
|
||||
- **Aufwand:** 2-4 Stunden
|
||||
|
||||
#### SEC-009: Keine Bild-Upload-Validierung
|
||||
- **Ort:** Zukunftige UI-Endpoints
|
||||
- **Problem:** Bilder werden nicht vor Speicherung validiert
|
||||
- **Lösung:** MIME-Type, Grose, Dimensionen prufen
|
||||
- **Prioritat:** MITTEL
|
||||
- **Aufwand:** 2-4 Stunden
|
||||
|
||||
---
|
||||
|
||||
## 4. Datenmodell-Analyse
|
||||
|
||||
### Vollständiges Schema
|
||||
|
||||
Das Datenmodell ist **exzellent entworfen** und perfekt fur die Anforderungen. Alle Tabellen sind vorhanden:
|
||||
|
||||
**Benutzer & Authentifizierung:**
|
||||
- `users` - Benutzer mit Rollen (admin, editor, viewer)
|
||||
- `sessions` - Session-Verwaltung
|
||||
|
||||
**Gerate & Kommandos:**
|
||||
- `devices` - Gerate-Informationen
|
||||
- `device_commands` - Kommando-Queue
|
||||
- `device_status` - Zeitreihen-Daten
|
||||
- `firmware` - Firmware-Versionen
|
||||
|
||||
**Captures & Beobachtungen:**
|
||||
- `captures` - Haupttabelle fur Bilder
|
||||
- `observations` - Beobachtungen zu Captures
|
||||
- `taxa` - Taxonomie (Arten)
|
||||
- `tags` - Tags fur Kategorisierung
|
||||
- `capture_tags` - n:m Beziehung
|
||||
|
||||
**Operationen:**
|
||||
- `settings` - System-Einstellungen
|
||||
- `audit_log` - Audit-Log
|
||||
- `backup_runs` - Backup-Informationen
|
||||
|
||||
**Job-Queue:**
|
||||
- `jobs` - PostgreSQL-basierte Queue
|
||||
|
||||
### Wichtige Beziehungen
|
||||
```
|
||||
users (1) ----(n) sessions
|
||||
\-- (n) audit_log
|
||||
\-- (n) device_commands (created_by)
|
||||
\-- (n) firmware (uploaded_by)
|
||||
\-- (n) observations (created_by)
|
||||
|
||||
devices (1) ----(n) captures
|
||||
|--- (n) device_status
|
||||
|--- (n) device_commands
|
||||
\-- (1) current firmware (via is_target)
|
||||
|
||||
captures (1) ----(n) observations
|
||||
|--- (n) tags (via capture_tags)
|
||||
\-- (1) device
|
||||
|
||||
observations (n) ----(1) taxa
|
||||
observations (n) ----(1) capture
|
||||
observations (n) ----(1) user (created_by)
|
||||
|
||||
tags (n) ----(n) captures (via capture_tags)
|
||||
```
|
||||
|
||||
### Wichtige Felder
|
||||
|
||||
**Captures:**
|
||||
- `id` (UUID) - Primar-Schlussel, fur URLs geeignet
|
||||
- `path`, `thumb_path` - Datei-Pfade
|
||||
- `received_at` - **AUTHORITATIV** (SPEC C7)
|
||||
- `trigger` - Ausloser (radar, manual, timer, stream_grab)
|
||||
- `pre_trigger` - Wurde das Bild VOR dem Trigger aufgenommen?
|
||||
- `kept` - Soft-Reject-Flag
|
||||
- `reviewed` - Wurde-reviewed?
|
||||
- `radar_*` - Radar-Daten
|
||||
- `battery_*`, `rssi`, `temp_c` - Device-Zustand
|
||||
|
||||
**Devices:**
|
||||
- `device_uid` - MAC-basierte Identitat
|
||||
- `config` - JSONB mit allen Einstellungen
|
||||
- `config_version` - Inkrementiert bei jeder Anderung
|
||||
- `battery_valid` - **KRITISCH:** false = **NICHT GEMESSEN** (nicht leer!)
|
||||
- `awake` - Device ist aktiv
|
||||
|
||||
**Device Status:**
|
||||
- Alle Felder sind Zeitreihen-Daten
|
||||
- Zähler (captured_today, etc.) kommen aus RTC-Speicher
|
||||
- **KRITISCH:** Zähler werden bei Stromausfall zuruckgesetzt
|
||||
- **UI-Anzeige:** Zähler zeigen GAP zwischen captured und delivered
|
||||
|
||||
---
|
||||
|
||||
## 5. Performance-Analyse
|
||||
|
||||
### Aktuelle Konfiguration
|
||||
|
||||
| Komponente | Einstellung | Aktueller Wert | Bewertung | Empfehlung |
|
||||
|-----------|-------------|----------------|-----------|-------------|
|
||||
| DB Connection Pool | db_pool_size | 5 | 3/5 | 15-20 fur Phase 3 |
|
||||
| Worker Poll Intervall | worker_poll_interval_s | 2.0 | 3/5 | 5.0 (weniger Polling) |
|
||||
| Batch Grose | worker_batch_size | 1 | 3/5 | 5-10 |
|
||||
| Sync SQLAlchemy | - | Aktiviert | 4/5 | OK fur aktuelle Skala |
|
||||
| Log Level | log_level | INFO | 4/5 | OK |
|
||||
| Image Root | image_root | /srv/poorbird/images | 5/5 | OK |
|
||||
| Thumb Root | thumb_root | /srv/poorbird/thumbs | 5/5 | OK |
|
||||
|
||||
### Empfehlungen
|
||||
|
||||
#### Datenbank
|
||||
```python
|
||||
# db.py - Empfohlene Anderungen
|
||||
engine = create_engine(
|
||||
_settings.database_url,
|
||||
pool_size=15, # War 5
|
||||
pool_pre_ping=True,
|
||||
pool_recycle=3600,
|
||||
pool_timeout=30,
|
||||
connect_timeout=10,
|
||||
echo=_settings.db_echo,
|
||||
future=True,
|
||||
)
|
||||
```
|
||||
|
||||
#### Worker
|
||||
- **Poll Intervall:** Erhohen auf 5 Sekunden (weniger Overhead)
|
||||
- **Batch Grose:** Erhohen auf 5-10 (bessere Auslastung)
|
||||
|
||||
---
|
||||
|
||||
## 6. Test-Status
|
||||
|
||||
### Aktueller Stand
|
||||
|
||||
| Test-Datei | Typ | Status | Benotigt | Coverage |
|
||||
|-----------|-----|--------|----------|----------|
|
||||
| test_health.py | Integration | ✅ PASS | PostgreSQL | API Health |
|
||||
| test_queue.py | Integration | ✅ PASS | PostgreSQL | Job Queue |
|
||||
| test_schema_matches_models.py | Integration | ✅ PASS | PostgreSQL + CREATE DB | Schema Drift |
|
||||
| test_config.py | Unit | ✅ PASS | Keine | Config Validierung |
|
||||
| conftest.py | Fixtures | ✅ | PostgreSQL | Test Setup |
|
||||
|
||||
**Gesamt:** 12/12 Tests passieren (100%)
|
||||
|
||||
### Fehlende Tests
|
||||
|
||||
#### Unit Tests (Backend - Phase 2)
|
||||
- Device-Endpoint-Tests
|
||||
- Authentifizierungs-Tests
|
||||
- Validierungs-Tests
|
||||
|
||||
#### Integration Tests (Backend - Phase 2)
|
||||
- Device-Integrationstests
|
||||
- Authentifizierungs-Integrationstests
|
||||
|
||||
---
|
||||
|
||||
## 7. Deployment-Analyse
|
||||
|
||||
### Aktueller Stand
|
||||
|
||||
✅ **Alles fur Phase 1 vorhanden:**
|
||||
- systemd-Units: `poorbird-api.service`, `poorbird-worker.service`
|
||||
- Caddyfile mit TLS (DNS-01), Image-Handoff, Camera-Listener
|
||||
- Installationsanleitung in `deploy/INSTALL.md`
|
||||
- Windows-Entwicklung dokumentiert
|
||||
|
||||
### Caddy-Konfiguration
|
||||
|
||||
Die Caddy-Konfiguration ist **exzellent**:
|
||||
- TLS uber DNS-01 (Let's Encrypt)
|
||||
- Auth-checked Image-Handoff (X-Accel-Redirect)
|
||||
- Camera-Listener auf Port 8080 (Plain HTTP, SPEC C2)
|
||||
- Menschliche UI auf Port 443 mit TLS
|
||||
|
||||
### Verifizierter Setup
|
||||
- Python 3.14.7
|
||||
- PostgreSQL 17 (Podman Container)
|
||||
- Alle 12 Tests passieren
|
||||
- Migrationen funktionieren
|
||||
- API lauffahig
|
||||
- Worker verarbeitet Queue
|
||||
|
||||
---
|
||||
|
||||
## 8. Zusammenfassung & Empfehlungen
|
||||
|
||||
### Sofort zu tun (vor Phase 2)
|
||||
|
||||
1. **KRITISCHE Sicherheitsprobleme fixen:**
|
||||
- [ ] SEC-001: Enroll Secret aus Defaults entfernen
|
||||
- [ ] SEC-002: Request-Authentifizierung implementieren
|
||||
- [ ] SEC-003: Input-Validierung implementieren
|
||||
- [ ] SEC-006: DB-URL Default entfernen
|
||||
|
||||
2. **HOCH Priorität:**
|
||||
- [ ] SEC-004: Rate-Limiting konfigurieren
|
||||
- [ ] SEC-005: CORS konfigurieren
|
||||
- [ ] SEC-007: Session-Verwaltung implementieren
|
||||
|
||||
### Fur Phase 2
|
||||
|
||||
1. **Device-Endpoints implementieren:**
|
||||
- [ ] `/api/v1/enroll`
|
||||
- [ ] `/api/v1/ingest`
|
||||
- [ ] `/api/v1/heartbeat`
|
||||
- [ ] `/api/v1/status`
|
||||
- [ ] `/api/v1/config`
|
||||
- [ ] `/api/v1/firmware`
|
||||
|
||||
2. **Authentifizierung implementieren:**
|
||||
- [ ] Device-Authentifizierung (X-Enroll-Secret)
|
||||
- [ ] Token-Generierung und -Verwaltung
|
||||
- [ ] Command-Queue
|
||||
|
||||
### Fur Phase 3
|
||||
|
||||
1. **WebUI-Vorbereitung:**
|
||||
- [ ] Passwort-Hashing (Argon2id)
|
||||
- [ ] User-Authentifizierung (Session Cookies)
|
||||
- [ ] CSRF-Schutz
|
||||
- [ ] UI-Endpoints
|
||||
|
||||
### Architektur-Entscheidungen (Respektieren!)
|
||||
|
||||
| Entscheidung | Begründung |
|
||||
|--------------|------------|
|
||||
| **Native Deployment** | SPEC-Anforderung, kein Container-Overhead |
|
||||
| **Sync SQLAlchemy** | Kein Async-Overhead bei 1 Kamera |
|
||||
| **PostgreSQL uber TCP** | Container-ready, bessere Performance |
|
||||
| **FOR UPDATE SKIP LOCKED** | Keine Redis-Abhangigkeit |
|
||||
| **JSONB fur Config** | Flexibel, zukunftssicher |
|
||||
| **UUID fur Captures** | URL-sicher, verteilt |
|
||||
| **Caddy als Proxy** | Einfache TLS-Verwaltung |
|
||||
|
||||
### Nicht in Frage stellen
|
||||
- Kein Docker (SPEC-Anforderung)
|
||||
- Kein Kubernetes
|
||||
- Kein SQLite (PostgreSQL erforderlich)
|
||||
- Kein public Streaming (Phase 6 ist nur intern)
|
||||
|
||||
---
|
||||
|
||||
## 9. Offene Fragen
|
||||
|
||||
| ID | Frage | Optionen | Impact | Entscheidung durch |
|
||||
|----|-------|---------|--------|-------------------|
|
||||
| Q6 | Anzahl Kameras | 1, 5, 10, 100 | Architektur-Skalierung | Phase 4 |
|
||||
| Q7 | Captures/Tag | 100, 1000, 10000 | Storage, Retention | Phase 5 |
|
||||
| Q8 | Retention: Lschen oder verstecken? | Datei loschen oder Soft-Delete | Datenmodell | Phase 5 |
|
||||
| Q9 | NAS-Protokoll | SFTP, SMB, NFS | Backup-Tooling | Phase 5 |
|
||||
| Q14 | 2FA | Erforderlich oder optional | Sicherheit | Phase 3 |
|
||||
|
||||
### Bereits entschieden (NICHT HINTERFRAGEN)
|
||||
|
||||
| Entscheidung | Begründung | Quelle |
|
||||
|--------------|------------|--------|
|
||||
| Native Deployment | SPEC-Anforderung | TODO.md |
|
||||
| PostgreSQL uber Loopback TCP | Container-ready | TODO.md |
|
||||
| Alle mutable State in expliziten Verzeichnissen | Zukunftige Volume Mounts | TODO.md |
|
||||
| Sync SQLAlchemy | Kein Async-Overhead | README.md |
|
||||
| Job-Queue ohne Redis | Einfachheit | SPEC C8 |
|
||||
| FastAPI | Modern, schnell, gute Typisierung | SPEC 6 |
|
||||
| Caddy | Einfache automatische TLS | SPEC 6 |
|
||||
|
||||
---
|
||||
|
||||
*Dieses Review wurde erstellt von Mistral Vibe am 2026-09-21 fur den poorBird Server-Branch.*
|
||||
Reference in new issue
Block a user