- Relocated AsarWrapper implementation and header files from `src/app/core/` to `src/core/` to enhance modularity and organization. - Updated all relevant include paths across the codebase to reflect the new location of AsarWrapper. - Adjusted CMake configurations to ensure proper compilation of the core library. Benefits: - Improves project structure by separating core functionalities from application-specific code. - Facilitates easier maintenance and understanding of the codebase by clarifying the organization of core components.
6.9 KiB
B7 - Architecture Refactoring Plan
Date: October 15, 2025 Status: Proposed Author: Gemini AI Assistant
1. Overview & Goals
This document outlines a comprehensive refactoring plan for the YAZE architecture. The current structure has resulted in tight coupling between components, slow incremental build times, and architectural inconsistencies (e.g., shared libraries located within the app/ directory).
The primary goals of this refactoring are:
- Establish a Clear, Layered Architecture: Separate foundational libraries (
core,gfx,zelda3) from the applications that consume them (app,cli). - Improve Modularity & Maintainability: Decompose large, monolithic libraries into smaller, single-responsibility modules.
- Drastically Reduce Build Times: Minimize rebuild cascades by ensuring changes in one module do not trigger unnecessary rebuilds in unrelated components.
- Enable Future Development: Create a flexible foundation for new features like alternative rendering backends (SDL3, Metal, Vulkan) and a fully-featured CLI.
2. Proposed Target Architecture
The proposed architecture organizes the codebase into two distinct layers: Foundational Libraries and Applications.
/src
├── core/ (NEW) 📖 Project model, Asar wrapper, etc.
├── gfx/ (MOVED) 🎨 Graphics engine, backends, resource management
├── zelda3/ (MOVED) Game Game-specific data models and logic
├── util/ (EXISTING) Low-level utilities (logging, file I/O)
│
├── app/ (REFACTORED) Main GUI Application
│ ├── controller.cc (MOVED) Main application controller
│ ├── platform/ (MOVED) 윈도우 Windowing, input, platform abstractions
│ ├── service/ (MOVED) AI gRPC services for automation
│ ├── editor/ (EXISTING) 🎨 Editor implementations
│ └── gui/ (EXISTING) Shared ImGui widgets
│
└── cli/ (EXISTING) z3ed Command-Line Tool
3. Detailed Refactoring Plan
This plan will be executed in three main phases.
Phase 1: Create yaze_core_lib (Project & Asar Logic)
This phase establishes a new, top-level library for application-agnostic project management and ROM patching logic.
- Create New Directory: Create
src/core/. - Move Files:
- Move
src/app/core/{project.h, project.cc}→src/core/(pending) - Move
src/app/core/{asar_wrapper.h, asar_wrapper.cc}→src/core/(done) - Move
src/app/core/features.h→src/core/(pending)
- Move
- Update Namespace: In the moved files, change the namespace from
yaze::coretoyaze::projectfor clarity. - Create CMake Target: In a new
src/core/CMakeLists.txt, define theyaze_core_libstatic library containing the moved files. This library should have minimal dependencies (e.g.,yaze_util,absl).
Phase 2: Elevate yaze_gfx_lib (Graphics Engine)
This phase decouples the graphics engine from the GUI application, turning it into a foundational, reusable library. This is critical for supporting multiple rendering backends as outlined in docs/G2-renderer-migration-plan.md.
- Move Directory: Move the entire
src/app/gfx/directory tosrc/gfx/. - Create CMake Target: In a new
src/gfx/CMakeLists.txt, define theyaze_gfx_libstatic library. This will aggregate all graphics components (backend,core,resource, etc.). - Update Dependencies: The
yazeapplication target will now explicitly depend onyaze_gfx_lib.
Phase 3: Streamline the app Layer
This phase dissolves the ambiguous src/app/core directory and simplifies the application's structure.
- Move Service Layer: Move the
src/app/core/service/directory tosrc/app/service/. This creates a clear, top-level service layer for gRPC implementations. - Move Platform Code: Move
src/app/core/{window.cc, window.h, timing.h}into the existingsrc/app/platform/directory. This consolidates all platform-specific windowing and input code. - Elevate Main Controller: Move
src/app/core/{controller.cc, controller.h}tosrc/app/. This highlights its role as the primary orchestrator of the GUI application. - Update CMake:
- Eliminate the
yaze_app_core_libtarget. - Add the source files from the moved directories (
app/controller.cc,app/platform/window.cc,app/service/*.cc, etc.) directly to the mainyazeexecutable target.
- Eliminate the
4. Alignment with EditorManager Refactoring
This architectural refactoring fully supports and complements the ongoing EditorManager improvements detailed in docs/H2-editor-manager-architecture.md.
- The
EditorManagerand its new coordinators (UICoordinator,PopupManager,SessionCoordinator) are clearly components of the Application Layer. - By moving the foundational libraries (
core,gfx) out ofsrc/app, we create a clean boundary. TheEditorManagerand its helpers will reside withinsrc/app/editor/andsrc/app/editor/system/, and will consume the newyaze_core_libandyaze_gfx_libas dependencies. - This separation makes the
EditorManager's role as a UI and session coordinator even clearer, as it no longer lives alongside low-level libraries.
5. Migration Checklist
- Phase 1: Create
src/core/and moveproject,asar_wrapper, andfeaturesfiles. - Phase 1: Create the
yaze_core_libCMake target. - Phase 2: Move
src/app/gfx/tosrc/gfx/. - Phase 2: Create the
yaze_gfx_libCMake target. - Phase 3: Move
src/app/core/service/tosrc/app/service/. - Phase 3: Move
window.cc,timing.htosrc/app/platform/. - Phase 3: Move
controller.cctosrc/app/. - Phase 3: Update the
yazeexecutable's CMake target to include the moved sources and link against the new libraries. - Phase 3: Delete the now-empty
src/app/core/directory and itscore_library.cmakefile. - Verification: Perform a clean build of all targets (
yaze,z3ed,yaze_test) to ensure all dependencies are correctly resolved. - Cleanup: Search the codebase for any remaining
#include "app/core/..."or#include "app/gfx/..."directives and update them to their new paths.
6. Expected Benefits
- Faster Builds: Incremental build times are expected to decrease by 40-60% as changes will be localized to smaller libraries.
- Improved Maintainability: A clear, layered architecture makes the codebase easier to understand, navigate, and extend.
- True CLI Decoupling: The
z3edCLI can link againstyaze_core_libandyaze_zelda3_libwithout pulling in any GUI or rendering dependencies, resulting in a smaller, more portable executable. - Future-Proofing: The abstracted
gfxlibrary paves the way for supporting SDL3, Metal, or Vulkan backends with minimal disruption to the rest of the application.