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)
- Custom Assembly Resolver: Attaches
AppDomain.CurrentDomain.AssemblyResolveto load dependent DLLs viaFile.ReadAllBytesfrom the add-in root orbin/,lib/, andassemblies/, bypassing NTFS Zone-of-Origin / CAS blocks in deployed environments. - WPF ResourceAssembly Fix: Assigns
System.Windows.Application.ResourceAssembly = typeof(ThisAddIn).Assemblysopack://application:,,,/URIs resolve properly inside VSTO (whereAssembly.GetEntryAssembly()isnull). - Offline-First Licensing: Calls
AddInLicense.Start()for sub-millisecond local Ed25519 signature verification plus a background 6-hour refresh timer. - Microkernel Bootstrapping (
InitializeModularInfrastructure):- Instantiates
CustomTaskPaneManager,ShibaCommandBus,ShibaModuleContext, andShibaModuleHost; - Calls
_moduleHost.DiscoverAndRegisterModules(typeof(ThisAddIn).Assembly)to auto-discover all concreteIShibaModuleimplementations; - Calls
_moduleHost.InitializeAll(), wrapping each module in aStopwatchto recordInitDurationMsand isolating any exceptions so a faulty module never crashes PowerPoint startup.
- Instantiates
- Circular Menu & WebView2 Prewarming: Initializes
CircularWindowControllerand schedulesWebView2EnvironmentManager.PrewarmOnUiThread()atDispatcherPriority.ApplicationIdleto eliminate first-open WebView2 latency.
Shutdown (ThisAddIn_Shutdown)
- Stop Background Timers Early: Calls
AddInLicense.Stop()first to prevent background callbacks from touching tearing-down COM contexts (DisconnectedContext). - Detach Host Events: Unsubscribes
AssemblyResolveand PowerPoint window activation events. - Reverse-Order Teardown: Disposes
CircularWindowController, then calls_moduleHost.Dispose()(invokingShutdown()on all modules in reverse registration order, disposing allCustomTaskPaneinstances, and closingSingleInstanceWindowHelperwindows). - Safe WebView2 Finalization: Calls
WebView2LifecycleService.ShutdownAll()andWebView2EnvironmentManager.ResetSharedEnvironment("ThisAddIn_Shutdown")on the STA thread, explicitly closing native controllers and callingGC.SuppressFinalizeto 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_settingsandmod_hotkeysare markedIsProtected = trueand 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 onShibaCommandBus.
3. ShibaCommandBus
- Case-insensitive command registry (
commandId -> Action<object>) that automatically tracks whichModuleIdregistered each command. - Calling
CommandBus.TryExecute("design.toggle_taskpane", param)checksCanExecuteModulePredicate(ownerModuleId)first; if disabled, it alerts the user to re-enable the module inPlugin 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:
- Zero Host Coupling: Never add
using shibappt.mod_*, instantiate feature windows, or callCustomTaskPanes.Add(...)directly insideThisAddIn.cs. - Global Command Bus Dispatch: Ribbon buttons (
UI/Ribbon/Ribbon1.*.cs),CircularMenu,HotkeySystem, andCustomRibbonmust trigger module features exclusively viaGlobals.ThisAddIn.CommandBus.TryExecute("<module>.<action>"). - Multi-Window TaskPane Management: Register all custom task panes through
context.TaskPanes.Register(key, title, width, window => ...)inCustomTaskPaneManagerso every open.pptx(DocumentWindow) gets an isolated lazy-loaded pane instance. - Mandatory WebView2 Service Triad: Never call
.EnsureCoreWebView2Async(,.SetVirtualHostNameToFolderMapping(, or.WebMessageReceived +=directly outsideCore/WebView/. Always useWebView2InitializationService,WebView2LifecycleService, andWebViewMessageRouter. - 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. - File Size Guardrails & Concise Comments:
- C# files $\le 2,000$ lines (excluding
*.Designer.cs): split large classes into<ClassName>.<SubDomain>.cspartial classfiles. - Vue SFCs $\le 2,000$ lines: extract logic into
composables/useXxx.jsand stylesheets into companion.cssfiles. - Single-line function comments: place
// Domain - Action descriptionabove newly added functions.
- C# files $\le 2,000$ lines (excluding
