docs: initial spec

This commit is contained in:
Arnaud Dartois committed 2026-07-16 20:19:11 +02:00
commit 0680f832a5
3 files changed
+1736

No files matched your search

+828
View File
@@ -0,0 +1,828 @@
# Heimdall - Plan d'implémentation
## Phase 0 - Initialisation projet
### Objectif
Créer le socle technique stable.
Durée estimée : 1-2 jours.
---
## Repository
Créer :
```
Heimdall
│
├── src
│ ├── Heimdall.Domain
│ ├── Heimdall.Application
│ ├── Heimdall.Infrastructure
│ ├── Heimdall.Api
│ ├── Heimdall.Web
│ ├── Heimdall.Agent
│ ├── Heimdall.Workers
│ ├── Heimdall.Contracts
│ └── Heimdall.Shared
│
├── tests
│ ├── Heimdall.Domain.Tests
│ ├── Heimdall.Application.Tests
│ ├── Heimdall.Infrastructure.Tests
│ ├── Heimdall.Api.Tests
│ ├── Heimdall.Agent.Tests
│ └── Heimdall.IntegrationTests
│
├── docker
│
├── .github/workflows
│
└── README.md
```
---
# Phase 1 - Solution .NET 10 + Clean Architecture
## Objectif
Créer tous les projets avec références correctes.
---
## Domain
Aucune dépendance externe.
Références autorisées :
```
Domain
|
X
```
Contient :
* Entities
* Value Objects
* Enums
* Domain Events
* Business Rules
---
Exemple :
```
CameraStatus.cs
EventType.cs
StorageProvider.cs
Site.cs
Camera.cs
Person.cs
Vehicle.cs
```
---
## Application
Dépend :
```
Application
|
v
Domain
```
Contient :
* Commands
* Queries
* DTO
* Validators
* Interfaces
* Specifications
Technologies :
* MediatR
* FluentValidation
---
## Infrastructure
Dépend :
```
Infrastructure
|
v
Application
Domain
```
Contient :
* EF Core
* PostgreSQL
* Identity
* File storage
* S3
* External services
---
## API
Dépend :
```
API
|
Application
Infrastructure
```
Contient :
* REST endpoints
* Authentication
* API Keys
* OpenAPI
---
## Agent
Même architecture :
```
Heimdall.Agent
Domain
Application
Infrastructure
```
Mais orientée :
* Worker Service
* Communication API
* Camera management
---
## Web
Blazor :
```
Heimdall.Web
```
Dernière phase.
---
# Phase 2 - Framework de tests
## Objectif
Avoir les tests avant le métier.
---
Stack :
* xUnit
* Shouldly
* NSubstitute
* Testcontainers
* FluentAssertions éventuellement
---
## Tests Domain
Premier projet.
Exemple :
```
CameraTests.cs
PersonTests.cs
VehicleTests.cs
```
---
Exemple TDD :
Avant code :
```csharp
[Fact]
public void Camera_should_start_disabled()
{
var camera = new Camera();
camera.Status.ShouldBe(CameraStatus.Disabled);
}
```
Puis seulement :
```csharp
public class Camera
{
public CameraStatus Status {get;private set;}
}
```
---
# Phase 3 - CI/CD DockerHub
## Objectif
Chaque commit doit être compilable.
---
Pipeline :
```
Push
↓
Restore
↓
Build
↓
Unit Tests
↓
Coverage
↓
Docker Build
↓
Docker Push
```
---
Images :
```
heimdall/api
heimdall/agent
heimdall/web
```
---
Tags :
```
latest
1.0.0
commit-sha
```
---
Quality gates :
* Build OK
* Tests OK
* Coverage minimum
* Sonar optionnel
---
# Phase 4 - Socle métier commun
## Objectif
Construire les fondations.
Ordre :
1. Tenant / Site
2. User
3. Permissions
4. Audit
5. Configuration
6. Events
---
## Entities
Premier modèle :
```
Site
Camera
Person
Vehicle
LicensePlate
Event
StoragePolicy
ApiKey
```
---
Avant chaque Entity :
Créer :
```
Tests
↓
Implementation
```
---
# Phase 5 - API Core
Développer API et tests ensemble.
---
## Première fonctionnalité
Health Check.
Test :
```
GET /health
200 OK
```
---
Puis :
## Site Management
Tests :
```
CreateSiteCommandTests
GetSiteQueryTests
DeleteSiteTests
```
Code ensuite.
---
## Camera Management
Tests :
```
CreateCameraTests
UpdateCameraTests
DisableCameraTests
```
Puis implémentation.
---
# Phase 6 - Agent Heimdall
Développement parallèle API.
Objectif :
Premier agent connecté.
---
## Fonctionnalités V1
### Agent Registration
Test :
```
Agent can register to server
```
Puis code.
---
### Heartbeat
Test :
```
Agent sends heartbeat
```
Puis code.
---
### Site association
Test :
```
Agent belongs to site
```
Puis code.
---
Architecture :
```
Agent
|
HTTPS
|
API
```
---
# Phase 7 - Camera Discovery
## Agent
Implémentation :
ONVIF discovery.
Tests :
```
Should discover camera
Should reject invalid credentials
Should detect capabilities
```
---
Mock :
Créer :
```
FakeOnvifClient
```
Tests sans caméra réelle.
---
# Phase 8 - Video Pipeline
## FFmpeg abstraction
Ne jamais appeler FFmpeg directement partout.
Créer :
```csharp
IVideoRecorder
```
---
Test :
```
Recorder creates segment
```
---
Implémentation :
* FFmpeg
* Hardware acceleration
---
# Phase 9 - IA Pipeline
## Abstraction
Créer :
```csharp
IAiDetectionService
```
---
Mock :
```csharp
FakeAiDetectionService
```
---
Tests :
```
Person detection creates event
Unknown face creates alert
```
---
Implémentation :
CodeProject.AI.
---
# Phase 10 - Storage
## Abstraction
Créer :
```csharp
IStorageProvider
```
Implémentations :
```
LocalStorageProvider
S3StorageProvider
```
---
Tests :
```
File saved
File deleted
Retention applied
```
---
# Phase 11 - Hangfire
Implémenter :
* Retention jobs
* Health checks
* Cleanup
---
Tests :
```
Expired recording is deleted
Active recording is kept
```
---
# Phase 12 - Security
## Identity
Tests :
```
User can login
Permission denied
Permission granted
```
---
## API Keys
Tests :
```
Generate key
Validate key
Expired key rejected
```
---
# Phase 13 - Blazor Web
Seulement maintenant.
---
Développement :
Tests :
* Component tests
* bUnit
---
Ordre :
1. Layout
2. Authentication
3. Dashboard
4. Sites
5. Cameras
6. Events
7. Persons
8. Vehicles
9. Administration
---
# Phase 14 - Dashboard KPI
Créer les APIs d'abord.
Tests :
```
Dashboard returns camera KPI
Dashboard returns event KPI
Dashboard returns storage KPI
```
Puis UI MudBlazor.
---
# Phase 15 - Production Ready
## Observabilité
Ajouter :
* Serilog
* Sentry
* GlitchTip
* OpenTelemetry
---
## Documentation
Générer :
* README
* Architecture Decision Records
* API documentation
* Deployment guide
---
# Stratégie Git
## Branches
```
main
develop
feature/*
```
---
## Commit convention
```
feat:
fix:
test:
refactor:
docs:
ci:
```
---
# Definition of Done
Une fonctionnalité est terminée uniquement si :
✅ Tests écrits avant le code
✅ Code fonctionnel
✅ Couverture TU OK
✅ Documentation XML
✅ Logs présents
✅ Gestion des erreurs
✅ Validation FluentValidation
✅ Docker OK
✅ CI verte
---
# Ordre global résumé
```
1. Solution .NET 10
2. Clean Architecture
3. Tests Framework
4. CI DockerHub
5. Domain Model
6. Application Layer
7. API Core
8. Agent Core
9. ONVIF
10. FFmpeg
11. CodeProject.AI
12. Storage
13. Hangfire
14. Security
15. Blazor UI
16. Dashboard
17. Production Hardening
```
+908
View File
@@ -0,0 +1,908 @@
Voici une version Markdown complète directement **copier/coller** dans un fichier :
`Heimdall_Complete_Specification.md`
````markdown
# Heimdall
## Intelligent Local AI Video Surveillance Platform
**Version:** 1.0
**Target Framework:** .NET 10+
**Architecture:** Clean Architecture / CQRS / Multi-site / Local AI
---
# 1. Vision
## Overview
Heimdall is a modern self-hosted intelligent video surveillance platform designed around:
- Local AI processing
- Multi-site architecture
- ONVIF camera discovery
- RTSP video management
- Face recognition
- License plate recognition
- Local LLM analysis
- Enterprise security model
- Full configuration through Web UI
Heimdall does not depend on cloud services.
All business configuration is stored in PostgreSQL and managed through the application interface.
---
# 2. Main Objectives
## Functional Objectives
- Manage multiple sites
- Automatically discover ONVIF cameras
- Support Imou cameras at minimum
- Record and manage video streams
- Detect people, vehicles and objects
- Recognize known persons
- Detect and read license plates
- Associate vehicles with persons
- Generate AI summaries using Ollama
- Provide secure API access
- Provide complete administration through Blazor UI
---
## Technical Objectives
- 100% Docker deployment
- .NET 10+
- PostgreSQL as unique source of configuration
- No business configuration files
- Local-first architecture
- GPU acceleration when available
- Enterprise logging and monitoring
---
# 3. Naming
## Heimdall
Inspired by Norse mythology.
Heimdall is the guardian watching the Bifröst bridge.
Mission:
> Protect and monitor your infrastructure.
---
# 4. Global Architecture
```text
Heimdall Central
|
|
HTTPS Secure
|
-----------------------
| |
Heimdall Agent Heimdall Agent
| |
Site A Cameras Site B Cameras
````
---
# 5. Solution Structure
```text
Heimdall.sln
src/
├── Heimdall.Domain
├── Heimdall.Application
├── Heimdall.Infrastructure
├── Heimdall.Api
├── Heimdall.Web
├── Heimdall.Agent
├── Heimdall.Workers
├── Heimdall.Contracts
└── Heimdall.Shared
```
---
# 6. Technology Stack
## Backend
* .NET 10+
* C#
* ASP.NET Core
* Blazor Web App
* Clean Architecture
* CQRS
* MediatR
* FluentValidation
* Entity Framework Core
* Hangfire
* Serilog
* OpenTelemetry ready
* Sentry SDK compatible with GlitchTip
---
## Frontend
* Blazor Web App
* Interactive Server Rendering
* MudBlazor
* Material Design principles
---
## Database
PostgreSQL
ORM:
* Entity Framework Core
Database configuration:
* IEntityTypeConfiguration<T>
* Specification Pattern
No generic repository pattern.
---
# 7. Coding Rules
All code must follow Microsoft .NET recommendations.
## Language
Source code:
* English only
Comments:
* English only
XML documentation:
* English only
---
## C# Rules
Enabled:
* Nullable Reference Types
* Implicit Usings
* File Scoped Namespace
Rules:
* Async everywhere
* No blocking calls
* Strong typing
* No magic strings
* No duplicated business logic
---
# 8. Domain Model Design
## Enum First Approach
Heimdall maximizes strongly typed enums.
Business states must never be represented by strings.
---
## Examples
### Camera Status
```csharp
public enum CameraStatus
{
Unknown,
Online,
Offline,
Disabled,
Error
}
```
---
### Event Type
```csharp
public enum EventType
{
MotionDetected,
PersonDetected,
VehicleDetected,
UnknownPerson,
FaceRecognized,
LicensePlateDetected
}
```
---
### Storage Provider
```csharp
public enum StorageProvider
{
Local,
S3
}
```
---
### Theme Mode
```csharp
public enum ThemeMode
{
Light,
Dark,
Auto
}
```
---
# 9. Authentication and Security
## Authentication
Microsoft Identity.
No Azure AD dependency.
---
## Authorization
Based on:
* Roles
* Permissions
* Policies
Examples:
```
Camera.Read
Camera.Write
Person.Read
Person.Write
Recording.Delete
Administration.Manage
```
---
# 10. API Security
External integrations use API Keys.
Features:
* Generate API key from UI
* Define permissions
* Expiration date
* Revocation
* Audit history
Storage:
* Hash only
* Never store clear text keys
---
# 11. Multi Site Management
## Site Entity
Example:
```
Site
Id
Name
Description
Address
Timezone
Enabled
```
---
Each object belongs to a site:
* Cameras
* Events
* Recordings
* Persons
* Vehicles
---
# 12. Heimdall Agent
Optional Docker component.
Purpose:
* Manage remote sites
* Communicate with local cameras
* Process local streams
* Reduce WAN traffic
Communication:
* HTTPS
* Secure authentication
* API key based
---
# 13. Camera Management
Supported protocols:
* ONVIF
* RTSP
* HTTP MJPEG
---
Supported manufacturers:
Minimum:
* Imou
Compatible:
* Dahua
* Hikvision
* Reolink
* Axis
* Amcrest
* ONVIF compatible devices
---
## ONVIF Discovery
Features:
* Network scan
* Camera identification
* Manufacturer detection
* Model detection
* Firmware detection
* RTSP discovery
* Snapshot discovery
* PTZ capability detection
Authentication:
Optional.
---
# 14. Video Processing
## FFmpeg
Used for:
* RTSP capture
* Recording
* Segmentation
* Snapshot extraction
Hardware acceleration:
Supported:
* NVIDIA CUDA
* Intel QuickSync
* VAAPI
---
# 15. AI Pipeline
```text
Camera
↓
FFmpeg
↓
Snapshot
↓
CodeProject.AI
↓
Detection
↓
Event Creation
↓
Notification
```
---
# 16. Object Detection
Supported:
* Person
* Vehicle
* Animal
* Package
* Custom objects depending on AI model
---
# 17. Face Recognition
Features:
* Person profiles
* Training images
* Recognition history
* Unknown faces
* Manual assignment
---
## Person Management UI
A person contains:
```
Person
Name
Photo
Face Samples
Vehicles
License Plates
Events History
Notes
```
---
# 18. Vehicle Management
Entity:
```
Vehicle
Brand
Model
Color
Plate
Owner
Pictures
```
---
# 19. License Plate Recognition
Pipeline:
```text
Vehicle Detection
↓
Plate Detection
↓
OCR
↓
Database Search
↓
Person Association
```
---
# 20. Storage Management
Supported providers:
## Local Storage
Example:
```
/recordings
```
---
## S3 Storage
Compatible:
* MinIO
* AWS S3
* OVH
* Scaleway
* Wasabi
---
Storage policies are configurable:
Example:
```
Camera Entrance
Retention: 30 days
Provider: Local
```
---
# 21. Retention Management
Implemented with Hangfire.
Database:
PostgreSQL
---
Managed jobs:
* Delete expired recordings
* Delete snapshots
* Delete events
* Cleanup unknown faces
* Cleanup license plates
* Database maintenance
* S3 cleanup
---
# 22. Hangfire
All scheduled tasks are persisted.
No custom timers.
---
UI allows:
* View jobs
* Execute manually
* Disable jobs
* Change schedule
* View history
---
# 23. Logging
Framework:
Serilog
---
Levels:
```
Trace
Debug
Information
Warning
Error
Critical
```
---
Structured logging:
```csharp
_logger.LogInformation(
"Camera {CameraId} changed status to {Status}",
camera.Id,
camera.Status);
```
---
# 24. Sentry / GlitchTip
Integration:
Official Sentry SDK.
Captured:
* Exceptions
* API failures
* Worker failures
* Performance issues
* Background job errors
Context:
* UserId
* SiteId
* CameraId
* JobId
* CorrelationId
Sensitive data filtering enabled.
---
# 25. Ollama Integration
Purpose:
* Daily summaries
* Weekly summaries
* Event analysis
Supported models:
* Qwen
* Gemma
* Mistral
* Llama
Example:
```
Daily Summary:
3 known persons detected.
1 unknown vehicle detected.
No critical events.
```
---
# 26. Web Application
## Framework
Blazor Web App.
---
## UI Library
MudBlazor.
Maximum usage of:
* MudTable
* MudDataGrid
* MudCard
* MudDialog
* MudDrawer
* MudTabs
* MudTimeline
* MudCharts
* MudForms
---
# 27. Theme
Supported:
* Light
* Dark
* Auto
Stored per user.
---
# 28. Localization
Current language:
French.
Architecture ready for:
* English
* Other languages
No hardcoded UI strings.
---
# 29. Dashboard
KPI based.
Widgets:
## Camera KPI
* Total cameras
* Online cameras
* Offline cameras
---
## Event KPI
* Events today
* Persons detected
* Vehicles detected
* Unknown persons
---
## Storage KPI
* Used space
* Available space
* Growth rate
---
## AI KPI
* CodeProject.AI status
* GPU usage
* Ollama status
---
# 30. Docker Deployment
Containers:
```text
heimdall-api
heimdall-web
heimdall-worker
heimdall-agent
postgresql
codeproject-ai
ollama
```
---
# 31. Quality Requirements
Heimdall follows:
* Clean Architecture
* SOLID principles
* CQRS
* Specification Pattern
* Strong typing
* Enum driven design
* Secure by default
* Observable by default
* Fully configurable from UI
---
# 32. Future Extensions
Possible features:
* Mobile application
* PTZ automation
* Advanced analytics
* Custom AI models
* Plugin system
* OpenTelemetry dashboards
* Grafana integration
* Public SDK
---
# Conclusion
Heimdall is a complete local-first AI video surveillance platform.
It combines:
* .NET 10+
* PostgreSQL
* Blazor
* MudBlazor
* CodeProject.AI
* Ollama
* Hangfire
* Sentry / GlitchTip
* Distributed Agents
while keeping full ownership of infrastructure, configuration and data.
View File
Whitespace-only changes.