Skip to content

AI Model Governance

The EU AI Act (enacted in 2024, fully enforced in 2026) classifies AI systems by risk level and mandates conformity assessments, post-deployment monitoring, and incident reporting for high-risk AI. This example implements the core requirements of the EU AI Act within a single bounded context using DDD tactical patterns and the Functorium framework.

ExampleLayerDomainKey Learning
designing-with-typesDomainContact ManagementValue Object, Aggregate Root
ecommerce-dddDomain + ApplicationE-CommerceCQRS, FinT LINQ, Apply Pattern
ai-model-governance (this example)Domain + Application + AdapterAI Model GovernanceAdvanced IO Features, Observability, Full-stack DDD

This is the third and final example in the series, building on the patterns covered in the Domain/Application layers by adding Adapter layer LanguageExt IO advanced features (Retry, Timeout, Fork, Bracket) and OpenTelemetry 3-Pillar observability.

This example follows the 7-step workflow of functorium-develop plugin v0.4.0.

StepSkillDocumentDescription
0project-specProject Requirements SpecificationPRD: KPIs, Ubiquitous Language, Aggregate Candidates, Acceptance Criteria
1architecture-designArchitecture DesignProject Structure, DI Strategy, Observability Pipeline
2-4domain-developDomain TrackVO, Aggregate, Domain Service, Specification
2-4application-developApplication TrackCQRS UseCase, Port, Event Handler
2-4adapter-developAdapter TrackRepository, External Service, HTTP API
5observability-developObservability TrackDashboard, Alerts, ctx.* Propagation
6test-develop(Test code included)268 Unit Tests, Integration Tests
DDD ConceptFunctorium TypeApplication
Value ObjectSimpleValueObject<T>, ComparableSimpleValueObject<T>ModelName, ModelVersion, EndpointUrl, DriftThreshold, etc.
Smart EnumSimpleValueObject<string> + HashMapRiskTier, DeploymentStatus, IncidentStatus, AssessmentStatus, etc.
EntityEntity<TId>AssessmentCriterion (child entity)
Aggregate RootAggregateRoot<TId>AIModel, ModelDeployment, ComplianceAssessment, ModelIncident
Domain EventDomainEvent18 types (Registered, Quarantined, Reported, etc.)
Domain ErrorDomainErrorType.CustomInvalidStatusTransition, AlreadyDeleted, etc.
SpecificationExpressionSpecification<T>12 types (ModelNameSpec, DeploymentActiveSpec, etc.)
Domain ServiceIDomainServiceRiskClassificationService, DeploymentEligibilityService
RepositoryIRepository<T, TId>4 Repository Interfaces
PatternImplementationApplication
CQRSICommandUsecase / IQueryUsecase8 Commands, 7 Queries
Apply Patterntuple.ApplyT()Parallel VO Validation Composition
FinT LINQfrom...in ChainingAsync Error Propagation
Port/AdapterIQueryPort, IRepositoryRead/Write Separation
Event HandlerIDomainEventHandler<T>2 Event Handlers
FluentValidationMustSatisfyValidationSyntactic + Semantic Dual Validation

Applied Adapter Patterns (Advanced IO Features)

Section titled “Applied Adapter Patterns (Advanced IO Features)”
IO PatternImplementation ClassPurpose
Timeout + CatchModelHealthCheckServiceHealth Check Timeout Handling
Retry + ScheduleModelMonitoringServiceExternal API Retry (Exponential Backoff)
Fork + awaitAllParallelComplianceCheckServiceParallel Compliance Checks
BracketModelRegistryServiceResource Lifecycle Management (Session)
PatternImplementationApplication
Observable Port[GenerateObservablePort] + Source GeneratorRepository 10, Query 5, External Service 4
Pipeline MiddlewareUseObservability() + Explicit Opt-inMetrics, Tracing, CtxEnricher, Logging, Validation, Exception
DomainEvent ObservabilityObservableDomainEventNotificationPublisherObserving Publication/Handling of 18 DomainEvents
ctx.* Propagation[CtxTarget] + CtxPillarMetricsTag(2), MetricsValue(1), Default(8+), Logging(2)
StepDocumentDescription
0. RequirementsDomain Business RequirementsBusiness Rules, State Transitions, Cross-Domain Rules
1. DesignDomain Type Design DecisionsAggregate Identification, Invariant Classification, Functorium Pattern Mapping
2. CodeDomain Code DesignVO, Smart Enum, Aggregate, Domain Service Code
3. ResultsDomain Implementation ResultsType Count Summary, Folder Structure, Test Status
StepDocumentDescription
0. RequirementsApplication Business RequirementsWorkflow Rules, Event-Reactive Flows
1. DesignApplication Type Design DecisionsCommand/Query/Port Identification, ApplyT, FinT Composition
2. CodeApplication Code DesignCommand Handler, Event Handler Code
3. ResultsApplication Implementation ResultsUseCase/Port Summary, Applied Pattern Overview
StepDocumentDescription
0. RequirementsAdapter Technical RequirementsPersistence, External Services, HTTP API, Observability Requirements
1. DesignAdapter Type Design DecisionsIO Pattern Selection Rationale, Observable Port Design
2. CodeAdapter Code DesignAdvanced IO Patterns, DI Registration Code
3. ResultsAdapter Implementation ResultsEndpoints, Implementations, Test Status
StepDocumentDescription
0. RequirementsObservability Business Requirements3-Pillar Requirements, SLO Targets
1. DesignObservability Type Design DecisionsKPI-Metric Mapping, ctx.* Propagation Strategy
2. CodeObservability Code DesignL1/L2 Dashboards, Alert Rules, PromQL
3. ResultsObservability Implementation ResultsObservable Port, Pipeline, IO Pattern Status
samples/ai-model-governance/
├── AiModelGovernance.slnx # Solution file (8 projects)
├── 00-project-spec.md # Project requirements specification
├── 01-architecture-design.md # Architecture design
├── domain/ # Domain layer docs (4)
├── application/ # Application layer docs (4)
├── adapter/ # Adapter layer docs (4)
├── observability/ # Observability docs (4)
├── Src/
│ ├── AiGovernance.Domain/
│ │ ├── SharedModels/Services/ # Domain Services
│ │ └── AggregateRoots/
│ │ ├── Models/ # AIModel, VOs, Specs
│ │ ├── Deployments/ # ModelDeployment, VOs, Specs
│ │ ├── Assessments/ # ComplianceAssessment, AssessmentCriterion, VOs, Specs
│ │ └── Incidents/ # ModelIncident, VOs, Specs
│ ├── AiGovernance.Application/
│ │ └── Usecases/
│ │ ├── Models/ # Commands, Queries, Ports
│ │ ├── Deployments/ # Commands, Queries, Ports
│ │ ├── Assessments/ # Commands, Queries, EventHandlers
│ │ └── Incidents/ # Commands, Queries, EventHandlers
│ ├── AiGovernance.Adapters.Persistence/
│ │ ├── Models/ # Repository, Query (InMemory + EfCore)
│ │ ├── Deployments/
│ │ ├── Assessments/
│ │ ├── Incidents/
│ │ └── Registrations/ # DI Registration
│ ├── AiGovernance.Adapters.Infrastructure/
│ │ ├── ExternalServices/ # Advanced IO Feature Demos (4 types)
│ │ └── Registrations/ # DI Registration
│ ├── AiGovernance.Adapters.Presentation/
│ │ ├── Endpoints/ # FastEndpoints (15 types)
│ │ └── Registrations/ # DI Registration
│ └── AiGovernance/ # Host (Program.cs)
└── Tests/
├── AiGovernance.Tests.Unit/ # Unit Tests
└── AiGovernance.Tests.Integration/ # Integration Tests
Terminal window
# Build
dotnet build Docs.Site/src/content/docs/samples/ai-model-governance/AiModelGovernance.slnx
# Test (268 tests)
dotnet test --solution Docs.Site/src/content/docs/samples/ai-model-governance/AiModelGovernance.slnx
ItemCount
Aggregate Root4
Value Object16 (String 6, Comparable 2, Smart Enum 8)
Domain Service2
Specification12
Domain Event18
Command8
Query7
Event Handler2
HTTP Endpoint15
Observable Port19
Advanced IO Pattern4 (Timeout, Retry, Fork, Bracket)
Total Tests268