How forairaaaaa/mooncake works
Project type and purpose
• Mooncake is an embedded C++ framework for microcontroller units (MCU). It provides a multi-app management and scheduling system, abstracting application behaviors as “Abilities” and offering lifecycle management for each.
• It is not a full-stack app but rather a library/framework that runs on bare-metal or RTOS-based MCUs, allowing developers to plug in multiple “AppAbility” instances and other Ability types (UIAbility, WorkerAbility, BasicAbility).
File structure
• Top-level:
• CMakeLists.txt + cmake/ → build configuration for cross-platform and ESP-IDF builds
• src/ → framework core code
– src/mooncake.cpp/.h → Mooncake class, the core scheduler
– src/ability/ → definitions of AbilityBase and derived Ability types
– src/ability_manager/ → AbilityManager implementation and API wrapping
• example/ → C++ demo applications showing how to install/open/close abilities
• test/ → Python-based automated tests against example outputs
• Configuration and metadata: .clang-format, .gitignore, LICENSE, library.json/properties
• CI config in .github/workflows for multi-platform CMake builds
README for additional insights
• Describes the core concepts:
• AbilityBase with onCreate/baseUpdate/baseDestroy
• Derived Ability types: BasicAbility, UIAbility, WorkerAbility, AppAbility, each with distinct lifecycle graphs
• Mooncake holds two AbilityManager instances: one for AppAbility, one for extensions (any AbilityBase)
• Shows usage patterns: installApp, openApp, update loop, thread-safety considerations
Main components
a. Hardware layer
– MCU (target hardware platform)
b. Framework core
– Mooncake (central scheduler)
– AbilityManager for AppAbility
– AbilityManager for ExtensionAbility
c. Ability hierarchy
– AbilityBase (abstract)
– AppAbility, UIAbility, WorkerAbility, BasicAbility (derived classes)
d. User-provided code
– User App classes (derive from AppAbility)
– Extensions (derive from other Ability types)
e. Build and test infrastructure (optional detail)
– CMake toolchain
– Python test runner
Relationships and interactions
• API calls (installApp, createExtension) → Mooncake → appropriate AbilityManager → stores Ability instance → returns ID
• update() loop in Mooncake → iterates over both AbilityManagers → calls baseUpdate() on each Ability → dispatches to specific lifecycle callbacks (onOpen, onRunning, etc.)
• openApp/closeApp → AppAbilityManager → state transitions in AppAbility
• Manager pattern: AbilityManager hides storage, ID allocation, and raw lifecycle scheduling
Architectural patterns and design principles
• Inversion of control / plugin architecture: user code injects derived Ability instances
• Manager pattern: centralized creation/destruction and dispatching
• State-machine lifecycles: each Ability type implements a small state machine
• Single-threaded event loop by default; thread-safety via user-provided locking
• Layered design: low-level hardware build scripts → framework core → user extensions
Relevant technologies, frameworks, and libraries
• C++17 (unique_ptr, override)
• CMake (modular scripts, esp-idf integration)
• Python (pytest or custom tests under test/)
• GitHub Actions for CI
• “MCU Hardware”
• “CMake Build System” (optional)
• “Mooncake Scheduler”
• “AppAbility Manager”
• “Extension Ability Manager”
• “AbilityBase & Derived Types”
• “User App Modules”
• “User Extensions”
• API calls → Managers → Stored Abilities
• update() loop → Managers → Ability callbacks
Final recommendation
• Be exhaustive in separating each responsibility: build, core scheduler, managers, base class, derived classes, user code
• Plugin-style extensibility and event-driven loop clearly
• Labels and flows are unambiguous—this will directly map to code modules under src/ and example/