2.7 KiB
2.7 KiB
name, description
| name | description |
|---|---|
| nexus-code-review | Code Review Checklist and Standards for NexusReader SaaS |
NexusReader Code Review Standards
When conducting or receiving a code review for NexusReader, ensure the implementation adheres to the following critical architectural and performance standards:
1. Architectural Boundaries (CQRS & Blazor Hybrid)
- Client vs. Server Execution: MediatR handlers that depend on server-side infrastructure (
AppDbContext,IHubContext, secrets) MUST NOT be executed directly from client environments (WASM/MAUI). - Dependency Leakage: Ensure
NexusReader.Web.Client(WASM) does not referenceNexusReader.Infrastructureif the infrastructure requiresMicrosoft.AspNetCore.Appframework references. - SignalR Bridges: Client-initiated state changes should be sent via SignalR
SendAsyncto a server Hub, which then dispatches the internalMediatRcommand.
2. Event Handling & Debouncing
- High-Frequency UI Events: UI actions like scrolling, resizing, or typing must be debounced.
- Trailing-Edge Debounce: Use a
CancellationTokenSourceandTask.Delayto ensure the last event in a rapid sequence is executed. Do not use simple time-window drops, as they result in lost final states. - Async Void: Ensure UI event handlers do not use
async voidunless they are top-level framework event bindings, and even then, they must catch all exceptions.
3. SignalR & Real-Time Contexts
- Authentication Context: Do not rely on
IHttpContextAccessorinside MediatR handlers triggered by SignalR Hubs. UseContext.UserIdentifierdirectly from the Hub and pass it as a command parameter. - Connection State: Always check
HubConnection.State == HubConnectionState.Connectedbefore attempting to send messages from the client. - Targeted Broadcasting: Use SignalR
Groups(e.g.,$"User_{userId}") to broadcast updates only to the devices owned by the relevant user.
4. Performance & Scalability
- Database Write Contention: High-frequency telemetry (like reading progress) should ideally be batched or cached in-memory before writing to SQL, unless real-time persistence is strictly required.
- Memory Leaks: Ensure all components and services that subscribe to events (e.g.,
OnProgressReceived, JS Observers) implementIDisposableorIAsyncDisposableand properly unsubscribe.
5. Standard Nexus Guidelines
- Result Pattern: Ensure all application logic returns
ResultorResult<T>via FluentResults. No exceptions for control flow. - AI Prompts: Ensure changes to AI logic do not bypass the
PromptRegistryor token estimation limits defined inAiSettings.