MILTON API Service Context

You are working in the MILTON service — the main ASP.NET Core API.

Responsibilities

  • Document management, user interactions, and core business logic.
  • Owns milton-db via AppDbContext (EF Core + PostgreSQL).
  • The only service that reads/writes milton-db directly.
  • Publishes/consumes cross-service messages via Wolverine.

Owned Paths

  • MILTON/Features/ — vertical slices for Documents, Projects, Templates, Git, Clustering, ProjectConfig, Health
  • MILTON/Domain/ — EF Core entities and domain logic
  • MILTON/Infrastructure/ — persistence, auth, encryption, tenant interceptors
  • MILTON/Shared/ — DTOs, DTO validators, and contract models
  • MILTON/Migrations/ — EF Core migrations for milton-db

Key Technologies & Patterns

  • FastEndpoints: Inherit from Endpoint<TRequest, TResponse>. Always use Send.OkAsync() (not deprecated SendOkAsync()). Use MiltonPermissions policies for endpoint auth.
  • Wolverine CQRS: Prefer static handlers (Handle(MyCommand cmd, AppDbContext db)). Dependencies injected as method parameters. Durable inbox/outbox handles retries automatically (do not add manual retry loops).
  • EF Core & Multi-tenancy: PostgreSQL persistence. TenantInterceptor automatically sets session variable for Row-Level Security based on ITenantService.
  • ContentBlock Polymorphism: Blocks are polymorphic (Requirement, TestCase, TestResult, Text, Mermaid, Scanner, TraceMatrix). PropertiesJson is accessed via block.As<T>() and modified via block.UpdateConfig(model).
  • Encrypted LLM Presets: Built-in presets (Writer, Coder, Analyst) with per-project overrides stored encrypted in ProjectConfig.LlmPresetsJson. Use LlmPreset.Resolve() / LlmPreset.ResolveWithOverrides(). Encrypt secrets using IEncryptionService with purpose string "MILTON.Encryption.Tokens".
  • Cross-Service Contracts: [MessageIdentity] records declared per-producer. Payload claim-checks travel through S3 (IClaimCheckStore).

Contracts This Service Owns

  • DocumentCreatedEvent
  • PrepareRequirementGenerationRequested / RequirementGenerationCompleted (API-side mirrors)
  • PrepareScannerGenerationRequested / ScannerGenerationCompleted (API-side mirrors)
  • PrepareTestCaseGenerationRequested / TestCaseGenerationCompleted (API-side mirrors)
  • Outbound notification messages bound to MILTON.NotificationService

Working Rules

  1. Load and follow milton-vertical-slice before creating any new MILTON/Features/<Feature>.
  2. Load and follow milton-tdd before writing or changing behavior. Strict RED-GREEN-REFACTOR.
  3. Keep endpoints in MILTON/Features/<Feature>/.
  4. Use MiltonPermissions policies on endpoints.
  5. Do not let other services touch milton-db; expose data via messages or APIs.
  6. Maintain [MessageIdentity] parity with MILTON.DocumentGenerator and MILTON.NotificationService.

Migrations & Verification

# Add EF Core migration for milton-db (from solution root)
dotnet ef migrations add MigrationName --project MILTON --startup-project MILTON
 
# Apply migration manually (normally applied by MILTON.ApiMigrationService on startup)
dotnet ef database update --project MILTON --startup-project MILTON
 
# Run tests
dotnet test MILTON.Tests --no-build --verbosity normal
  • New behavior has a failing-then-passing test in MILTON.Tests/.
  • dotnet build succeeds with no warnings.
  • dotnet test MILTON.Tests/ passes.
  • Cross-service contracts have matching [MessageIdentity] strings in consumer services.