Domain Layer

The Domain Layer is the core heart of the MILTON architecture. Following Domain-Driven Design (DDD) principles combined with Entity Framework Core data modeling, it defines the core entities, business rules, strong types, and structural relationships that govern the entire system.

Unlike older architectures, MILTON does not use a shared domain assembly across microservices. Instead, this Domain namespace belongs exclusively to the MILTON.csproj API. The API physically owns the milton-db database. Worker services (like DocumentGenerator) communicate over message buses without having binary references to these EF entities.

Business Logic Intent

The central business domain of MILTON is the generation and lifecycle management of AI-driven technical documentation. The core intent here is:

  1. Multi-Tenancy & Security: Almost all top-level entities are strictly bound to a TenantId enabling automatic PostgreSQL Row-Level Security.
  2. Polymorphic Content: The Documents sub-namespace defines how massive architectural documents are broken down into hierarchical Sections and executable ContentBlocks (e.g., text, mermaid, scanners, test results).
  3. Traceability: Ensuring robust mapping between source control repositories (GitRepository) and specific generated requirements (TraceLink), enabling true bidirectional traceability.

Architecture & Integration

  • Entity Framework Core: Entities are POCOs enriched with EF Core configuration attributes or fluent API configurations in the Infrastructure tier.
  • Tenant Interceptor: AppDbContext leverages a specialized DbCommandInterceptor to inject the TenantId directly into PostgreSQL session variables, making it impossible to accidentally leak data across organizations.
  • JSON Serialization: Configuration fields (like LlmPresetsJson on ProjectConfig and PropertiesJson on ContentBlock) utilize PostgreSQL’s native jsonb column types, blending structured relations with dynamic NoSQL-like behavior where AI configuration demands it.

Mermaid Entity Relationship Diagram

The following diagram depicts the high-level structural map of the core entities modeled in the Domain tier.

erDiagram
    Project ||--o{ ProjectConfig : configures
    Project ||--o{ ProjectMember : has
    Project ||--o{ GitRepository : contains
    Project ||--o{ Document : owns
    Project ||--o{ DocumentTemplate : owns
    
    DocumentTemplate ||--o{ Document : instances

    Document ||--o{ Section : structured_by
    Section ||--o{ ContentBlock : contains
    ContentBlock ||--o{ TraceLink : traces_to

    ApplicationUser ||--o{ ProjectMember : participates_in

Modules and Components

Entities

Located under Entities/, these are the EF Core representations of the domain models.

  • Core Entities: Project, ProjectConfig, GitRepository, ProjectMember, ApplicationUser.
  • Documents Sub-Domain: Document, DocumentTemplate, Section, ContentBlock, TraceLink. This sub-folder defines the rigid hierarchy required for iterative document rendering and AI chunk processing.

Enums

  • Strongly typed state values, such as ProjectUserRole, standardizing domain terms.

Events

  • Domain events mapped to Wolverine messaging (in progress). These events form the backbone of the saga orchestration, communicating “DocumentCreated” or “BlockGenerated” status outwards across RabbitMQ.

3 items under this folder.