Architecture Patterns
1. Key Classes
Core Singletons
| Class |
Location |
Role |
| SettingsManager |
core/settings_manager.h |
Singleton, JSON config persistence |
| ArtProvider |
core/art_provider.h |
Singleton, icons, colors, QAction creation |
| IconRegistry |
core/icon_registry.h |
Singleton, icon registration and caching |
| ThemeManager |
core/theme_manager.h |
Singleton, theme loading, palette management |
| CommandRegistry |
gui/command_registry.h |
Singleton, central QAction owner, getAction(), updateActionState() |
| Logger |
core/logger.h |
Singleton, spdlog wrapper |
| TrustedKeys |
core/trusted_keys.h |
Singleton, plugin publisher key management |
MainWindow Coordinators
| Class |
Location |
Role |
| MainWindow |
gui/main_window.h |
Thin orchestrator (~805 lines) |
| IconRegistrar |
gui/icon_registrar.h |
Icon registration with IconRegistry |
| CommandRegistrar |
gui/command_registrar.h |
Command registration with callbacks |
| DockCoordinator |
gui/dock_coordinator.h |
Panel and dock widget management |
| DocumentCoordinator |
gui/document_coordinator.h |
Document lifecycle, open/save/close |
| NavigatorCoordinator |
gui/navigator_coordinator.h |
Navigator panel interaction handlers |
| DiagnosticController |
gui/diagnostic_controller.h |
Diagnostic and dev mode management |
| SettingsCoordinator |
gui/settings_coordinator.h |
Settings dialog integration |
Plugin Security
| Class |
Location |
Role |
| PluginSignature |
core/plugin_signature.h |
Ed25519 signature verification |
| TrustedKeys |
core/trusted_keys.h |
Trusted publisher key management |
2. Design Patterns Used
Singleton
- SettingsManager, ArtProvider, ThemeManager, IconRegistry, Logger
- Access:
ClassName::getInstance()
Command Pattern
- CommandRegistry stores CommandDef entries
- Actions created via ArtProvider::createAction()
Observer (Qt Signals/Slots)
- ThemeManager::themeChanged signal
- ArtProvider::resourcesChanged signal
- Components connect to update on changes
Composite
- Book → Part → Chapter (Document)
- BookElement hierarchy
3. Source Structure
include/kalahari/
├── core/ # business logic, singletons
│ ├── art_provider.h
│ ├── settings_manager.h
│ ├── theme_manager.h
│ ├── icon_registry.h
│ ├── logger.h
│ ├── book.h
│ ├── document.h
│ ├── plugin_signature.h # Ed25519 verification
│ └── trusted_keys.h # Publisher key management
├── gui/ # UI components
│ ├── main_window.h # Thin orchestrator
│ ├── icon_registrar.h # Icon registration
│ ├── command_registrar.h # Command registration
│ ├── dock_coordinator.h # Panel management
│ ├── document_coordinator.h
│ ├── navigator_coordinator.h
│ ├── diagnostic_controller.h
│ ├── settings_coordinator.h
│ ├── command_registry.h
│ ├── settings_dialog.h
│ ├── panels/
│ │ ├── editor_panel.h
│ │ ├── navigator_panel.h
│ │ └── log_panel.h
│ └── utils/
│ └── layout_utils.h # clearLayout() helper
└── utils/ # utilities
└── ...
src/
├── core/
├── gui/
└── utils/
4. Adding New Components
New Panel (QDockWidget)
- Create header:
include/kalahari/gui/panels/my_panel.h
- Create source:
src/gui/panels/my_panel.cpp
- Inherit from QDockWidget
- Register in MainWindow::createDockWidgets()
- Add to CMakeLists.txt
New Dialog (QDialog)
- Create header:
include/kalahari/gui/my_dialog.h
- Create source:
src/gui/my_dialog.cpp
- Inherit from QDialog
- Add action in MainWindow or menu
- Add to CMakeLists.txt
New Widget (QWidget)
- Create header:
include/kalahari/gui/my_widget.h
- Create source:
src/gui/my_widget.cpp
- Inherit from QWidget
- Use in panel or dialog
- Add to CMakeLists.txt
New Core Class
- Create header:
include/kalahari/core/my_class.h
- Create source:
src/core/my_class.cpp
- Use
kalahari::core namespace
- Add to CMakeLists.txt
5. Signal/Slot Connections
Theme changes
connect(&core::ThemeManager::getInstance(), &core::ThemeManager::themeChanged,
this, &MyClass::onThemeChanged);
Icon/color changes
connect(&core::ArtProvider::getInstance(), &core::ArtProvider::resourcesChanged,
this, &MyClass::onResourcesChanged);
6. File Naming
| Component Type |
Header |
Source |
| Panel |
my_panel.h |
my_panel.cpp |
| Dialog |
my_dialog.h |
my_dialog.cpp |
| Widget |
my_widget.h |
my_widget.cpp |
| Core class |
my_class.h |
my_class.cpp |
7. CMakeLists.txt Integration
set(KALAHARI_GUI_SOURCES
...
src/gui/my_new_file.cpp
)
set(KALAHARI_GUI_HEADERS
...
include/kalahari/gui/my_new_file.h
)
8. Analyzing Existing Code
mcp__serena__get_symbols_overview("path/to/file.cpp") - see class structure
mcp__serena__find_symbol("ClassName") - find class definition
mcp__serena__find_referencing_symbols("ClassName") - find usages
(Serena = semantic C++ engine. Fallback if unavailable: Grep / Glob / Read.)
Key files to check
main_window.cpp - thin orchestrator, coordinator creation
dock_coordinator.cpp - panel/dock widget patterns
document_coordinator.cpp - document lifecycle patterns
settings_dialog.cpp - dialog patterns
art_provider.cpp - icon/color handling
plugin_signature.cpp - Ed25519 verification patterns
1---2name: architecture-patterns3description: Kalahari architecture patterns and key classes. Use for code analysis and design.4---56# Architecture Patterns78## 1. Key Classes910### Core Singletons11| Class | Location | Role |12|-------|----------|------|13| SettingsManager | core/settings_manager.h | Singleton, JSON config persistence |14| ArtProvider | core/art_provider.h | Singleton, icons, colors, QAction creation |15| IconRegistry | core/icon_registry.h | Singleton, icon registration and caching |16| ThemeManager | core/theme_manager.h | Singleton, theme loading, palette management |17| CommandRegistry | gui/command_registry.h | Singleton, central QAction owner, getAction(), updateActionState() |18| Logger | core/logger.h | Singleton, spdlog wrapper |19| TrustedKeys | core/trusted_keys.h | Singleton, plugin publisher key management |2021### MainWindow Coordinators22| Class | Location | Role |23|-------|----------|------|24| MainWindow | gui/main_window.h | Thin orchestrator (~805 lines) |25| IconRegistrar | gui/icon_registrar.h | Icon registration with IconRegistry |26| CommandRegistrar | gui/command_registrar.h | Command registration with callbacks |27| DockCoordinator | gui/dock_coordinator.h | Panel and dock widget management |28| DocumentCoordinator | gui/document_coordinator.h | Document lifecycle, open/save/close |29| NavigatorCoordinator | gui/navigator_coordinator.h | Navigator panel interaction handlers |30| DiagnosticController | gui/diagnostic_controller.h | Diagnostic and dev mode management |31| SettingsCoordinator | gui/settings_coordinator.h | Settings dialog integration |3233### Plugin Security34| Class | Location | Role |35|-------|----------|------|36| PluginSignature | core/plugin_signature.h | Ed25519 signature verification |37| TrustedKeys | core/trusted_keys.h | Trusted publisher key management |3839## 2. Design Patterns Used4041### Singleton42- SettingsManager, ArtProvider, ThemeManager, IconRegistry, Logger43- Access: `ClassName::getInstance()`4445### Command Pattern46- CommandRegistry stores CommandDef entries47- Actions created via ArtProvider::createAction()4849### Observer (Qt Signals/Slots)50- ThemeManager::themeChanged signal51- ArtProvider::resourcesChanged signal52- Components connect to update on changes5354### Composite55- Book → Part → Chapter (Document)56- BookElement hierarchy5758## 3. Source Structure5960```61include/kalahari/62├── core/ # business logic, singletons63│ ├── art_provider.h64│ ├── settings_manager.h65│ ├── theme_manager.h66│ ├── icon_registry.h67│ ├── logger.h68│ ├── book.h69│ ├── document.h70│ ├── plugin_signature.h # Ed25519 verification71│ └── trusted_keys.h # Publisher key management72├── gui/ # UI components73│ ├── main_window.h # Thin orchestrator74│ ├── icon_registrar.h # Icon registration75│ ├── command_registrar.h # Command registration76│ ├── dock_coordinator.h # Panel management77│ ├── document_coordinator.h78│ ├── navigator_coordinator.h79│ ├── diagnostic_controller.h80│ ├── settings_coordinator.h81│ ├── command_registry.h82│ ├── settings_dialog.h83│ ├── panels/84│ │ ├── editor_panel.h85│ │ ├── navigator_panel.h86│ │ └── log_panel.h87│ └── utils/88│ └── layout_utils.h # clearLayout() helper89└── utils/ # utilities90 └── ...9192src/93├── core/94├── gui/95└── utils/96```9798## 4. Adding New Components99100### New Panel (QDockWidget)1011. Create header: `include/kalahari/gui/panels/my_panel.h`1022. Create source: `src/gui/panels/my_panel.cpp`1033. Inherit from QDockWidget1044. Register in MainWindow::createDockWidgets()1055. Add to CMakeLists.txt106107### New Dialog (QDialog)1081. Create header: `include/kalahari/gui/my_dialog.h`1092. Create source: `src/gui/my_dialog.cpp`1103. Inherit from QDialog1114. Add action in MainWindow or menu1125. Add to CMakeLists.txt113114### New Widget (QWidget)1151. Create header: `include/kalahari/gui/my_widget.h`1162. Create source: `src/gui/my_widget.cpp`1173. Inherit from QWidget1184. Use in panel or dialog1195. Add to CMakeLists.txt120121### New Core Class1221. Create header: `include/kalahari/core/my_class.h`1232. Create source: `src/core/my_class.cpp`1243. Use `kalahari::core` namespace1254. Add to CMakeLists.txt126127## 5. Signal/Slot Connections128129### Theme changes130```cpp131connect(&core::ThemeManager::getInstance(), &core::ThemeManager::themeChanged,132 this, &MyClass::onThemeChanged);133```134135### Icon/color changes136```cpp137connect(&core::ArtProvider::getInstance(), &core::ArtProvider::resourcesChanged,138 this, &MyClass::onResourcesChanged);139```140141## 6. File Naming142143| Component Type | Header | Source |144|----------------|--------|--------|145| Panel | `my_panel.h` | `my_panel.cpp` |146| Dialog | `my_dialog.h` | `my_dialog.cpp` |147| Widget | `my_widget.h` | `my_widget.cpp` |148| Core class | `my_class.h` | `my_class.cpp` |149150## 7. CMakeLists.txt Integration151152```cmake153set(KALAHARI_GUI_SOURCES154 ...155 src/gui/my_new_file.cpp156)157158set(KALAHARI_GUI_HEADERS159 ...160 include/kalahari/gui/my_new_file.h161)162```163164## 8. Analyzing Existing Code1651661. `mcp__serena__get_symbols_overview("path/to/file.cpp")` - see class structure1672. `mcp__serena__find_symbol("ClassName")` - find class definition1683. `mcp__serena__find_referencing_symbols("ClassName")` - find usages169170(Serena = semantic C++ engine. Fallback if unavailable: Grep / Glob / Read.)171172### Key files to check173- `main_window.cpp` - thin orchestrator, coordinator creation174- `dock_coordinator.cpp` - panel/dock widget patterns175- `document_coordinator.cpp` - document lifecycle patterns176- `settings_dialog.cpp` - dialog patterns177- `art_provider.cpp` - icon/color handling178- `plugin_signature.cpp` - Ed25519 verification patterns