Skip to content

Comments

Architecture Modernization: Event System, CQRS, Repository Pattern + Production Integration#243

Merged
michaelbeale-IL merged 7 commits intomasterfrom
copilot/refactor-architecture-patterns
Feb 21, 2026
Merged

Architecture Modernization: Event System, CQRS, Repository Pattern + Production Integration#243
michaelbeale-IL merged 7 commits intomasterfrom
copilot/refactor-architecture-patterns

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Delivers Phase 2 architecture modernization infrastructure (Issues #202#205) and integrates the new patterns into production code across the key leverage points.

Infrastructure Delivered

Event System (ACATCore/EventManagement/)

  • IEventBus / EventBus — thread-safe pub/sub with weak-reference delegates; dead subscriptions pruned lazily on publish
  • Domain event types: PanelShowEvent, PanelHideEvent, PanelActivateEvent, ActuatorSwitchActivatedEvent, ConfigurationReloadEvent, ConfigurationChangedEvent, ConfigurationReloadFailedEvent, AgentContextChangedEvent
  • IEventBus registered as singleton in ServiceConfiguration.AddACATServices()

CQRS (ACATCore/Patterns/CQRS/)

  • ICommand, IQuery<TResult>, ICommandHandler<T>, IQueryHandler<T,TResult> marker interfaces
  • PanelCommands.csShowPanelCommand, HidePanelCommand, GetActivePanelQuery
  • Four reference handler implementations wired to IPanelManager, IActuatorManager, IAgentManager, EnvironmentConfiguration
  • All four handlers registered in DI via ServiceConfiguration.AddACATServices()

Repository Pattern (ACATCore/DataAccess/)

  • IRepository<T> with Load(key) / Save(entity, key) / GetDefault()
  • PreferencesRepository<T> (XML via XmlUtils), ConfigurationRepository<T> (JSON via System.Text.Json), ThemeRepository
  • IRepository<Theme> registered in DI

Interface Extraction Guide

docs/INTERFACE_EXTRACTION_GUIDE.md — naming conventions, directory layout, migration checklist, component priority tiers.

Production Integration

EventBus — Live in Production

Four managers now publish domain events via IEventBus:

  • PanelManagerPanelShowEvent / PanelHideEvent
  • ActuatorManagerActuatorSwitchActivatedEvent
  • AgentManagerAgentContextChangedEvent
  • ConfigurationReloadServiceConfigurationReloadEvent / ConfigurationReloadFailedEvent

PanelActivityMonitor (ACATCore/Diagnostics/) is a real production subscriber active in both ACATApp and ACATTalk, demonstrating the event-driven pattern end-to-end with real-time panel lifecycle and switch activation logging.

CQRS — Live in Production

  • ACATApp and ACATTalk resolve ICommandHandler<CreatePanelCommand> from DI for all entry-point panel creation, replacing direct PanelManager.Instance.CreatePanel() calls.

Repository — Live in Production

  • PreferencesBase.Load<T> and Save now delegate to PreferencesRepository<T>, automatically migrating 20+ call sites throughout ActuatorManagement, TTSManagement, CommandManagement, and more.
  • GlobalPreferences fully migrated to PreferencesRepository<T>.
  • ThemeManager uses IRepository<Theme> via constructor injection from DI.

Tests

ACATCore.Tests.Architecture MSTest project (30 tests) covering EventBus, CQRS contracts, and repository CRUD. Added to CI workflow.

Implementation Status Report

docs/ARCHITECTURE_IMPLEMENTATION_STATUS.md provides a full audit of the migration state, documents all remaining call sites (incremental follow-on work), and serves as a guide for future contributors to continue the migration.

Pattern Status
IEventBus.Publish() ✅ Active in 4 managers; PanelActivityMonitor subscribed in both apps
CQRS handlers ✅ Registered in DI; used in ACATApp + ACATTalk entry points
Repository PreferencesBase + GlobalPreferences + ThemeManager migrated (covers 20+ call sites)
Original prompt

This section details on the original issue you should resolve

<issue_title>Architecture Modernization</issue_title>
<issue_description>Refactor architecture patterns to modern best practices, reduce coupling, improve maintainability.

Key Deliverables:

  • Interface extraction
  • Event-driven patterns
  • Command/Query separation
  • Repository pattern

Benefits:

  • Reduced coupling
  • Better separation of concerns
  • Easier testing
  • Clearer responsibilities

🔗 Dependencies

Epic: Phase 2 - Core Infrastructure Modernization

Estimated Effort: 2-3 weeks


📋 Tasks

</issue_description>

<agent_instructions>Use this as the final review that all sub-tasks have been completed and a final wrapup of this feature.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…n Guide, and Architecture Tests

Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor architecture patterns for modern best practices Architecture Modernization: Event System, CQRS, and Repository Pattern Feb 20, 2026
@michaelbeale-IL
Copy link
Contributor

@copilot - I've merged all the changes from master and now have build failing and tests failing. can you reconcile things?

…merge

Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot - I've merged all the changes from master and now have build failing and tests failing. can you reconcile things?

Fixed in commit 2c688f7. The master merge introduced conflicts in three areas:

  1. Ambiguous type referencesHandleActuatorSwitchCommand and GetConfigurationValueQuery were defined in both PanelCommands.cs (our namespace) and Samples/ (master's namespace). Removed the duplicates from PanelCommands.cs so only the Samples versions remain.

  2. EventBus API change — Master replaced the token-based subscribe/unsubscribe with a handler-reference API, and renamed event types (PanelShownEventPanelShowEvent, ActuatorSwitchEventActuatorSwitchActivatedEvent, etc.). Updated EventBusTests.cs in ACATCore.Tests.Architecture to match the new API and event names.

  3. Repository API change — Master replaced the CRUD-style repository with a Load(key)/Save(entity,key)/GetDefault() pattern and made ConfigurationRepository and PreferencesRepository generic. Updated RepositoryTests.cs to use the new API, and cleaned up duplicate Compile entries in ACAT.Core.csproj.

…sessment and TODO list

Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
Copilot AI changed the title Architecture Modernization: Event System, CQRS, and Repository Pattern Architecture Modernization: Event System, CQRS, Repository Pattern + Implementation Status Report Feb 20, 2026
Completed EventBus publishing in 4 managers and migrated 26+ call sites to Repository pattern for preferences/config. Added PanelActivityMonitor as first real EventBus subscriber, registered in DI and activated in ACATApp/ACATTalk for real-time activity logging. All changes are backward compatible; CQRS infrastructure is DI-ready with guides. Codebase now supports loose coupling, testability, and future-proofing.
Migrated 4 app entry points from PanelManager singleton to CQRS pattern using dependency-injected ICommandHandler<CreatePanelCommand>. Added CreatedPanel property to command for result passing. Updated handler to set this property. Added documentation (SECTION_3_3_1_PHASE1_COMPLETE.md) detailing migration, benefits, and next steps. Phase 1 complete; CQRS pattern established for future expansion.
@michaelbeale-IL
Copy link
Contributor

@copilot - Review all the changes in this PR and determine if we have met the spirit of the acceptance criteria of Feature #194.

Copy link
Contributor Author

Copilot AI commented Feb 21, 2026

@copilot - Review all the changes in this PR and determine if we have met the spirit of the acceptance criteria of Feature #194.

Yes — the PR meets the spirit of the acceptance criteria for Feature #194. Here's the assessment against each deliverable:


✅ Interface Extraction (#202)
All major manager interfaces (IPanelManager, IAgentManager, IActuatorManager, IThemeManager, etc.) exist and are registered in DI via ServiceConfiguration.AddACATServices(). docs/INTERFACE_EXTRACTION_GUIDE.md documents the conventions and migration checklist.


✅ Event-Driven Patterns (#203)
IEventBus / EventBus infrastructure is complete and wired into real production code:

  • PanelManager publishes PanelShowEvent / PanelHideEvent
  • ActuatorManager publishes ActuatorSwitchActivatedEvent
  • AgentManager publishes AgentContextChangedEvent
  • ConfigurationReloadService publishes ConfigurationReloadEvent / ConfigurationReloadFailedEvent
  • PanelActivityMonitor is a real subscriber active in both ACATApp and ACATTalk that logs panel lifecycle and switch activation in real time — demonstrating the pattern end-to-end.

✅ Command/Query Separation (#204)
CQRS interfaces and sample handlers are complete and wired:

  • All four handlers registered in DI (in ServiceConfiguration)
  • ACATApp and ACATTalk both resolve ICommandHandler<CreatePanelCommand> via DI for all entry-point panel creation — replacing direct PanelManager.Instance.CreatePanel() calls

✅ Repository Pattern (#205)
IRepository<T> / RepositoryBase<T> / three concrete implementations are complete and in use:

  • PreferencesBase.Load<T> and Save now delegate to PreferencesRepository<T> — this is the highest-leverage change, covering 20+ call sites throughout ActuatorManagement, TTSManagement, CommandManagement, etc., automatically
  • GlobalPreferences migrated to PreferencesRepository<T>
  • ThemeManager uses IRepository<Theme> via constructor injection
  • IRepository<Theme> registered in DI

What's remaining (documented in docs/ARCHITECTURE_IMPLEMENTATION_STATUS.md):
The remaining work is incremental tactical migration — ~65 actuator pause/resume call sites, remaining CreatePanel sites in extensions, legacy += event subscriptions — but these are follow-on work items. The architectural patterns are in place, the key leverage points have been migrated, CI is green, and the codebase now supports loose coupling, testability, and future incremental adoption.

Copilot AI changed the title Architecture Modernization: Event System, CQRS, Repository Pattern + Implementation Status Report Architecture Modernization: Event System, CQRS, Repository Pattern + Production Integration Feb 21, 2026
@michaelbeale-IL michaelbeale-IL marked this pull request as ready for review February 21, 2026 00:04
@michaelbeale-IL michaelbeale-IL merged commit 59e671f into master Feb 21, 2026
3 checks passed
@michaelbeale-IL michaelbeale-IL deleted the copilot/refactor-architecture-patterns branch February 21, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Architecture Modernization

2 participants