Skip to main content

CQRS & Application Layer

The Alert.CA.Admin.API.Application project implements the Command Query Responsibility Segregation (CQRS) pattern using MediatR. Every API request flows through this layer β€” controllers never access repositories or services directly.

Request Pipeline​

Module Organization​

The application layer is organized by domain module. Each module contains its own commands, queries, and handlers:

Alert.CA.Admin.API.Application/
β”œβ”€β”€ DeviceConfig/
β”‚ β”œβ”€β”€ Commands/
β”‚ β”‚ β”œβ”€β”€ CreateDeviceConfigCommand.cs
β”‚ β”‚ β”œβ”€β”€ UpdateDeviceConfigCommand.cs
β”‚ β”‚ └── DeleteDeviceConfigCommand.cs
β”‚ └── Queries/
β”‚ β”œβ”€β”€ GetAllDeviceConfigsQuery.cs
β”‚ └── GetDeviceConfigByIdQuery.cs
β”œβ”€β”€ ImageAcquisition/
β”‚ β”œβ”€β”€ Commands/
β”‚ └── Queries/
β”œβ”€β”€ AxisCamera/
β”‚ β”œβ”€β”€ Commands/
β”‚ └── Queries/
β”œβ”€β”€ UserAgencyCamera/
β”‚ β”œβ”€β”€ Commands/
β”‚ └── Queries/
β”œβ”€β”€ Users/
β”œβ”€β”€ Locations/
β”œβ”€β”€ FeatureFlags/
β”œβ”€β”€ ActivityLog/
└── EsriMapSync/
β”œβ”€β”€ Commands/
β”‚ β”œβ”€β”€ ConvertToArcgisJsonCommand.cs
β”‚ β”œβ”€β”€ QueryEsriObjectIdsCommand.cs
β”‚ β”œβ”€β”€ DeleteEsriFeaturesCommand.cs
β”‚ β”œβ”€β”€ UploadEsriFeaturesCommand.cs
β”‚ └── FullEsriMapSyncCommand.cs
β”œβ”€β”€ Queries/
β”‚ β”œβ”€β”€ GetEsriSyncConfigQuery.cs
β”‚ β”œβ”€β”€ GetEsriCameraDataQuery.cs
β”‚ └── GetEsriTokenQuery.cs
└── Models/

Audit Behavior​

The AuditBehavior<TRequest, TResponse> is a MediatR pipeline behavior that automatically logs audit records for any command implementing IAuditCommand:

What Gets Audited​

  • Who β€” User identity from JWT claims
  • What β€” Command type and parameters
  • When β€” Timestamp
  • Result β€” Success or failure

This ensures every write operation has a traceable audit trail without requiring individual handlers to implement logging.

Registered Services​

The DependencyInjection class registers all application-layer services:

ServiceInterfacePurpose
Onboarding ServiceIOnboardingServiceMulti-step camera onboarding workflow
Bulk Operations ServiceIBulkOperationsServiceBatch camera operations
Location File ServiceILocationFileServiceLocation data file parsing and import
Durable Entity ServiceIDurableEntityServiceInteraction with Durable Functions entities
Feature Layer ServiceIFeatureLayerServiceESRI feature layer updates
UCSD ClientIUCSDClientUCSD Metadata API integration
ESRI ClientIESRIClientESRI GIS service integration
ESRI Map Sync ServiceIEsriMapSyncServiceFull ESRI map layer sync workflow

Adding a New Feature​

To add a new feature to the Admin API:

  1. Create a command or query in the appropriate module under Alert.CA.Admin.API.Application
  2. Create a handler implementing IRequestHandler<TRequest, TResponse>
  3. If the command modifies data, implement IAuditCommand to get automatic audit logging
  4. Add a controller action in Alert.CA.Admin.API that calls _mediator.Send(command)
  5. MediatR auto-discovers handlers β€” no manual registration needed