Skip to content

Microkernel Architecture & Six Core Rules ​

ShibaPPT is a modular PowerPoint VSTO Add-in built on .NET Framework 4.8 (C# 8.0 / WPF / WinForms) and Vue 3 + Vite + WebView2. It adopts a Microkernel Module Host (ShibaModuleHost) + Global Command Bus (ShibaCommandBus) architecture, enabling all 29 independent feature modules and 46 registered commands to be developed in isolation, toggled dynamically at runtime, measured for startup latency, and built incrementally.


1. High-Level Architecture Topology ​

text
┌─────────────────────────────────────────────────────────────────────────┐
│                    PowerPoint Host (ThisAddIn.cs)                       │
│  AssemblyResolve · ResourceAssembly · AddInLicense · PrewarmWebView2    │
└───────────────────────────────────┬─────────────────────────────────────┘
                                    │ Bootstraps
                                    ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                     ShibaModuleHost (Microkernel Host)                  │
│  Reflection Discovery -> Latency Profiling -> Fault Isolation -> State  │
├─────────────────────────┬─────────────────────────┬─────────────────────┤
│    ShibaCommandBus      │  CustomTaskPaneManager  │  Core Services      │
│  Case-Insensitive Bus   │ Multi-Window Pane Pool  │ WebView2 / i18n /   │
│  Disabled-Module Guard  │ Lazy Init & Visibility  │ Providers / Logger  │
└───────────▲─────────────┴───────────▲─────────────┴──────────▲──────────┘
            │ TryExecute              │ Toggle / Register      │
┌───────────┴─────────────────────────┴────────────────────────┴──────────┐
│  UI Triggers: Ribbon1 Partials · 3-Layer CircularMenu · Global Hotkeys  │
│  Feature Modules: 29 IShibaModule Classes (mod_design, mod_ai, ...)     │
│  Hybrid Frontend: shibappt-ui (Vue 3 + Vite 9 Entries) + Sidecar CLIs   │
└─────────────────────────────────────────────────────────────────────────┘

2. Host Startup & Shutdown Lifecycle (ThisAddIn.cs) ​

ThisAddIn.cs acts strictly as a lightweight bootstrapper with zero business-module coupling:

Startup (ThisAddIn_Startup) ​

  1. Custom Assembly Resolver: Attaches AppDomain.CurrentDomain.AssemblyResolve to load dependent DLLs via File.ReadAllBytes from the add-in root or bin/, lib/, and assemblies/, bypassing NTFS Zone-of-Origin / CAS blocks in deployed environments.
  2. WPF ResourceAssembly Fix: Assigns System.Windows.Application.ResourceAssembly = typeof(ThisAddIn).Assembly so pack://application:,,,/ URIs resolve properly inside VSTO (where Assembly.GetEntryAssembly() is null).
  3. Offline-First Licensing: Calls AddInLicense.Start() for sub-millisecond local Ed25519 signature verification plus a background 6-hour refresh timer.
  4. Microkernel Bootstrapping (InitializeModularInfrastructure):
    • Instantiates CustomTaskPaneManager, ShibaCommandBus, ShibaModuleContext, and ShibaModuleHost;
    • Calls _moduleHost.DiscoverAndRegisterModules(typeof(ThisAddIn).Assembly) to auto-discover all concrete IShibaModule implementations;
    • Calls _moduleHost.InitializeAll(), wrapping each module in a Stopwatch to record InitDurationMs and isolating any exceptions so a faulty module never crashes PowerPoint startup.
  5. Circular Menu & WebView2 Prewarming: Initializes CircularWindowController and schedules WebView2EnvironmentManager.PrewarmOnUiThread() at DispatcherPriority.ApplicationIdle to eliminate first-open WebView2 latency.

Shutdown (ThisAddIn_Shutdown) ​

  1. Stop Background Timers Early: Calls AddInLicense.Stop() first to prevent background callbacks from touching tearing-down COM contexts (DisconnectedContext).
  2. Detach Host Events: Unsubscribes AssemblyResolve and PowerPoint window activation events.
  3. Reverse-Order Teardown: Disposes CircularWindowController, then calls _moduleHost.Dispose() (invoking Shutdown() on all modules in reverse registration order, disposing all CustomTaskPane instances, and closing SingleInstanceWindowHelper windows).
  4. Safe WebView2 Finalization: Calls WebView2LifecycleService.ShutdownAll() and WebView2EnvironmentManager.ResetSharedEnvironment("ThisAddIn_Shutdown") on the STA thread, explicitly closing native controllers and calling GC.SuppressFinalize to prevent MTA finalizer crashes (0xc0000409 / E_NOINTERFACE) when unloading the AppDomain.

3. Core Modularity Contracts (Core/Modularity/) ​

1. IShibaModule ​

csharp
public interface IShibaModule
{
    string ModuleId { get; }       // Unique module key, e.g. "mod_design"
    string DisplayName { get; }    // Default display name, e.g. "简报"
    void Initialize(ShibaModuleContext context); // Register TaskPanes & Commands
    void Shutdown();               // Release hooks, timers, or background windows
}

2. ShibaModuleHost ​

  • Registry Persistence: Module enable/disable states are persisted under HKCU\SOFTWARE\ShibAppt\Modules ("true" / "false", defaulting to enabled).
  • Protected Core Modules (ProtectedModuleIds): mod_settings and mod_hotkeys are marked IsProtected = true and cannot be disabled, ensuring users can always access settings.
  • Instant Runtime Enforcement: Calling SetModuleEnabled(moduleId, false) immediately hides any open task panes for that module across all PowerPoint windows and blocks all commands owned by that module on ShibaCommandBus.

3. ShibaCommandBus ​

  • Case-insensitive command registry (commandId -> Action<object>) that automatically tracks which ModuleId registered each command.
  • Calling CommandBus.TryExecute("design.toggle_taskpane", param) checks CanExecuteModulePredicate(ownerModuleId) first; if disabled, it alerts the user to re-enable the module in Plugin Settings -> Module Management.

4. Six Core Architectural Rules (Enforced by CI Guardrails) ​

scripts\verify-architecture.ps1 runs automatically during every build and fails compilation if any rule below is violated:

  1. Zero Host Coupling: Never add using shibappt.mod_*, instantiate feature windows, or call CustomTaskPanes.Add(...) directly inside ThisAddIn.cs.
  2. Global Command Bus Dispatch: Ribbon buttons (UI/Ribbon/Ribbon1.*.cs), CircularMenu, HotkeySystem, and CustomRibbon must trigger module features exclusively via Globals.ThisAddIn.CommandBus.TryExecute("<module>.<action>").
  3. Multi-Window TaskPane Management: Register all custom task panes through context.TaskPanes.Register(key, title, width, window => ...) in CustomTaskPaneManager so every open .pptx (DocumentWindow) gets an isolated lazy-loaded pane instance.
  4. Mandatory WebView2 Service Triad: Never call .EnsureCoreWebView2Async(, .SetVirtualHostNameToFolderMapping(, or .WebMessageReceived += directly outside Core/WebView/. Always use WebView2InitializationService, WebView2LifecycleService, and WebViewMessageRouter.
  5. User-Writable Storage Paths: Never write runtime files into the installation folder. Use PathHelper.GetUserWritableConfigPath(...) (%AppData%\ShibaPPT\Config\), ProviderConfigManager (Documents\ShibAppt\providers_config.json), and %LocalAppData%\ShibaPPT\ for logs and downloaded assets.
  6. File Size Guardrails & Concise Comments:
    • C# files $\le 2,000$ lines (excluding *.Designer.cs): split large classes into <ClassName>.<SubDomain>.cs partial class files.
    • Vue SFCs $\le 2,000$ lines: extract logic into composables/useXxx.js and stylesheets into companion .css files.
    • Single-line function comments: place // Domain - Action description above newly added functions.