feat(mvp): implement MVP multi-site platform
Complete MVP implementation (Étape 1) covering: - Domain: primitives (Entity<TId>, ValueObject), 10 entities, 6 enums - EF Core: AppDbContext + Identity, 8 EntityTypeConfigurations, audit/soft-delete interceptors, initial migration - Application: service interfaces, DTOs, FluentValidation, ServiceResult pattern - Security: Identity + JWT + API Key multi-auth, role-based permissions, constant-time key validation - API: Auth/Sites/Agents controllers with explicit auth scheme policies - Workers: Hangfire PostgreSQL setup with schema isolation, HeartbeatMonitorJob - Agent: registration service + 30s heartbeat loop - Docker: multi-stage Dockerfiles for central + agent, docker-compose.yml - CI/CD: GitHub Actions pipeline with build+test and Docker build - Tests: 13 domain tests (Site, Agent, Camera entities) Architecture decisions per deliberation council: - API Key via AuthenticationHandler<T> (not middleware) - Explicit [Authorize(AuthenticationSchemes)] on all endpoints - Event/Recording/Person/Vehicle deferred from initial migration - Hangfire compatible with .NET 10 (v1.8.17)
This commit is contained in:
1 parent
ad78346ac4
commit
b217c932e8
78 files changed
+5359
-11
No files matched your search
@@ -0,0 +1,61 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class AgentConfiguration : IEntityTypeConfiguration<Agent>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Agent> builder)
|
||||
{
|
||||
builder.ToTable("agents");
|
||||
|
||||
builder.HasKey(a => a.Id);
|
||||
|
||||
builder.Property(a => a.Name)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Hostname)
|
||||
.HasMaxLength(255)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.Version)
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(a => a.Status)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(20)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(a => a.PublicIp)
|
||||
.HasMaxLength(45);
|
||||
|
||||
builder.Property(a => a.ApiKeyHash)
|
||||
.HasMaxLength(128);
|
||||
|
||||
builder.Property(a => a.ApiKeyPrefix)
|
||||
.HasMaxLength(8);
|
||||
|
||||
builder.Property(a => a.GpuType)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(20);
|
||||
|
||||
builder.Property(a => a.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(a => a.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(a => a.SiteId);
|
||||
builder.HasIndex(a => a.LastHeartbeat)
|
||||
.HasFilter("\"status\" = 'Online'");
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(a => a.Site)
|
||||
.WithMany(s => s.Agents)
|
||||
.HasForeignKey(a => a.SiteId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class ApiKeyConfiguration : IEntityTypeConfiguration<ApiKey>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ApiKey> builder)
|
||||
{
|
||||
builder.ToTable("api_keys");
|
||||
|
||||
builder.HasKey(k => k.Id);
|
||||
|
||||
builder.Property(k => k.KeyHash)
|
||||
.HasMaxLength(128)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(k => k.KeyPrefix)
|
||||
.HasMaxLength(8)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(k => k.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(k => k.KeyHash);
|
||||
builder.HasIndex(k => k.KeyPrefix);
|
||||
builder.HasIndex(k => k.SiteId);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(k => k.Site)
|
||||
.WithMany()
|
||||
.HasForeignKey(k => k.SiteId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<AuditLog> builder)
|
||||
{
|
||||
builder.ToTable("audit_logs");
|
||||
|
||||
builder.HasKey(al => al.Id);
|
||||
|
||||
builder.Property(al => al.Action)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(al => al.ResourceType)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(al => al.ResourceId)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(al => al.IpAddress)
|
||||
.HasMaxLength(45);
|
||||
|
||||
builder.Property(al => al.Timestamp)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(al => al.Timestamp)
|
||||
.IsDescending();
|
||||
|
||||
builder.HasIndex(al => new { al.ResourceType, al.ResourceId, al.Timestamp })
|
||||
.IsDescending(false, false, true);
|
||||
|
||||
builder.HasIndex(al => al.UserId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class CameraConfiguration : IEntityTypeConfiguration<Camera>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Camera> builder)
|
||||
{
|
||||
builder.ToTable("cameras");
|
||||
|
||||
builder.HasKey(c => c.Id);
|
||||
|
||||
builder.Property(c => c.Name)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(c => c.Manufacturer)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.Model)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.RtspUrl)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
builder.Property(c => c.Status)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(20)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(c => c.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(c => c.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(c => c.SiteId);
|
||||
builder.HasIndex(c => c.AgentId);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(c => c.Site)
|
||||
.WithMany(s => s.Cameras)
|
||||
.HasForeignKey(c => c.SiteId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(c => c.Agent)
|
||||
.WithMany(a => a.Cameras)
|
||||
.HasForeignKey(c => c.AgentId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
// One-to-one with credentials
|
||||
builder.HasOne(c => c.Credentials)
|
||||
.WithOne(cr => cr.Camera)
|
||||
.HasForeignKey<CameraCredentials>(cr => cr.CameraId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// One-to-one with detection profile
|
||||
builder.HasOne(c => c.DetectionProfile)
|
||||
.WithOne(dp => dp.Camera)
|
||||
.HasForeignKey<CameraDetectionProfile>(dp => dp.CameraId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class CameraCredentialsConfiguration : IEntityTypeConfiguration<CameraCredentials>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CameraCredentials> builder)
|
||||
{
|
||||
builder.ToTable("camera_credentials");
|
||||
|
||||
builder.HasKey(c => c.CameraId);
|
||||
|
||||
builder.Property(c => c.OnvifUsername)
|
||||
.HasMaxLength(100)
|
||||
.HasDefaultValue("admin");
|
||||
|
||||
builder.Property(c => c.OnvifPassword)
|
||||
.HasMaxLength(500)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(c => c.RtspUsername)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.RtspPassword)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(c => c.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class CameraDetectionProfileConfiguration : IEntityTypeConfiguration<CameraDetectionProfile>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CameraDetectionProfile> builder)
|
||||
{
|
||||
builder.ToTable("camera_detection_profiles");
|
||||
|
||||
builder.HasKey(p => p.CameraId);
|
||||
|
||||
builder.Property(p => p.YoloModel)
|
||||
.HasMaxLength(50)
|
||||
.HasDefaultValue("yolov8n");
|
||||
|
||||
builder.Property(p => p.MinConfidence)
|
||||
.HasDefaultValue(0.4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class AppUserConfiguration : IEntityTypeConfiguration<AppUser>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<AppUser> builder)
|
||||
{
|
||||
builder.ToTable("users");
|
||||
|
||||
builder.Property(u => u.DisplayName)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(u => u.Theme)
|
||||
.HasMaxLength(20)
|
||||
.HasDefaultValue("Auto");
|
||||
|
||||
builder.Property(u => u.Language)
|
||||
.HasMaxLength(10)
|
||||
.HasDefaultValue("fr");
|
||||
|
||||
builder.Property(u => u.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
public class AppRoleConfiguration : IEntityTypeConfiguration<AppRole>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<AppRole> builder)
|
||||
{
|
||||
builder.ToTable("roles");
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserRoleConfiguration : IEntityTypeConfiguration<IdentityUserRole<Guid>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityUserRole<Guid>> builder)
|
||||
{
|
||||
builder.ToTable("user_roles");
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserClaimConfiguration : IEntityTypeConfiguration<IdentityUserClaim<Guid>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityUserClaim<Guid>> builder)
|
||||
{
|
||||
builder.ToTable("user_claims");
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserLoginConfiguration : IEntityTypeConfiguration<IdentityUserLogin<Guid>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityUserLogin<Guid>> builder)
|
||||
{
|
||||
builder.ToTable("user_logins");
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityRoleClaimConfiguration : IEntityTypeConfiguration<IdentityRoleClaim<Guid>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityRoleClaim<Guid>> builder)
|
||||
{
|
||||
builder.ToTable("role_claims");
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserTokenConfiguration : IEntityTypeConfiguration<IdentityUserToken<Guid>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityUserToken<Guid>> builder)
|
||||
{
|
||||
builder.ToTable("user_tokens");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class SiteConfiguration : IEntityTypeConfiguration<Site>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Site> builder)
|
||||
{
|
||||
builder.ToTable("sites");
|
||||
|
||||
builder.HasKey(s => s.Id);
|
||||
|
||||
builder.Property(s => s.Name)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(s => s.Address)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(s => s.Timezone)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired()
|
||||
.HasDefaultValue("UTC");
|
||||
|
||||
builder.Property(s => s.RegistrationTokenHash)
|
||||
.HasMaxLength(128);
|
||||
|
||||
builder.Property(s => s.CreatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.Property(s => s.UpdatedAt)
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(s => s.Name);
|
||||
builder.HasIndex(s => s.IsDeleted)
|
||||
.HasFilter("\"is_deleted\" = false");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Heimdall.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Heimdall.Infrastructure.Data.Configurations;
|
||||
|
||||
public class UserSiteConfiguration : IEntityTypeConfiguration<UserSite>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserSite> builder)
|
||||
{
|
||||
builder.ToTable("user_sites");
|
||||
|
||||
builder.HasKey(us => new { us.UserId, us.SiteId });
|
||||
|
||||
builder.HasOne(us => us.User)
|
||||
.WithMany(u => u.UserSites)
|
||||
.HasForeignKey(us => us.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(us => us.Site)
|
||||
.WithMany()
|
||||
.HasForeignKey(us => us.SiteId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
// Index for "find all users for a site" queries
|
||||
builder.HasIndex(us => us.SiteId);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user