MILTON API (MILTON)

Overview

MILTON is the primary ASP.NET Core Web API that acts as the entry point for the frontend (MILTON.Client). It exposes REST endpoints via FastEndpoints and hosts SignalR hubs for real-time notifications. The project is responsible for routing commands and queries down to MILTON.BackendCore or publishing Wolverine messages for worker sagas like MILTON.DocumentGenerator.

Real-time Sync (SignalR)

The MILTON application hosts the DocumentHub at /hubs/document to push live state updates directly to the connected MILTON.Client browser instances. Connections manage visibility to relevant scopes to minimize traffic and maintain privacy by joining specialized SignalR groups.

Document and Project Groups

The hub implements two primary joining patterns:

  1. Document Groups (JoinDocumentGroup):

    • Clients call JoinDocumentGroup(Guid documentId) when viewing a specific document detail page.
    • The backend pushes granular logs (e.g., “Starting LLM request”, “Formatting snippet”), partial document updates, and completion/error flags specifically to the group named doc-{documentId}.
  2. Project Groups (JoinProjectGroup):

    • Clients call JoinProjectGroup(int projectId) when viewing list pages or dashboards.
    • The backend pushes higher-level updates, such as when a document’s overall status changes or when document sections summarize, to the group named project-{projectId}.

Component Subscription & Memory Leak Prevention

Subscriptions in the client must be carefully managed. When Blazor components are opened, they should invoke StartAsync on the SignalR connection and join the necessary group via JoinDocumentAsync or JoinProjectAsync in the client’s abstractions.

To avoid memory leaks associated with abandoned callbacks, components must explicitly implement IDisposable or IAsyncDisposable. In the destruction logic, they must unsubscribe from StateService events (OnProgress, OnCompleted, etc.) and invoke the corresponding LeaveDocumentAsync or LeaveProjectAsync to halt stream forwarding from the backend DocumentHub.

2 items under this folder.