Core Architecture
The Three Pillars: Carto, Project, and ProjectItem
The codebase is built around three fundamental types that work together:Carto
TheCarto object is the main global container that manages:
- User Preferences: Stored via the
ICartoDatainterface - Storage Locations: Multiple
IStorageobjects for:- Preferences storage (
prefsStorage) - New projects storage (
projectsStorage) - Deployment storage (Minecraft target folder)
- Worlds storage (minecraftWorlds folder)
- Preferences storage (
- Project Gallery: The
loadGallery()function loads starter projects and templates
Carto is designed to be platform-agnostic, insulating the core logic from web vs. Node.js differences.
CartoApp
TheCartoApp represents the application layer with platform-specific operations:
- Platform Detection:
hostTypeproperty and helper methods likeisWeborisNodeJs - Platform Abstraction: Thunk functions for platform-specific operations
- Special Casing: Source of platform-specific behavior branches
Project
TheProject object is the largest type and contains all logic for managing an add-on or world:
- File Discovery: The
_inferProjectItemsFromFolderfunction recursively identifies and creates ProjectItems based on file types - Metadata: Stores project preferences in
IProjectData(saved as JSON) - Utilities: Logic is moving to static classes like
ProjectUtilities,ProjectTools, andProjectExporter
ProjectItem
Represents a single logical resource (entity definition, script file, etc.):- Identification: Identified by canonicalized
storagePathrelative to project root - File Association: Typically associated with an
IFile(orIFolderfor worlds) - Manager Pattern: Uses
IFile.managerproperty to store type-specific managers (e.g.,EntityTypeDefinition) - Metadata: Stores item data in
IProjectItemData(saved in parent project’s JSON)
Variants and Subpacks
ProjectItems support variants for handling subpacks:- Default File:
.defaultFilepoints to the main variant - Primary File:
.primaryFilereturns the “foremost” version based on project organization - Multiple Variants: One ProjectItem can have multiple file variants
File System Abstraction
The project uses a storage abstraction layer located inapp/src/storage/:
IStorage Interface
All file operations go through asynchronous abstractions:Storage Implementations
BrowserStorage
BrowserStorage
Implements local storage for browsers by wrapping localForage APIs, which use browser-standard key-value storage.Use case: Web-based project editing
HttpStorage
HttpStorage
Provides read-only access to files on the web.Use case: Loading samples and templates from web servers
NodeStorage
NodeStorage
Implements storage on top of Node.js
fs API primitives.Use case: Desktop application and CLI toolsReference: app/src/storage/NodeStorage.tsGitHubStorage
GitHubStorage
Provides read-only, non-authenticated access to GitHub repos via OctoKit APIs.Use case: Importing projects from GitHub repositories
A writeable implementation exists but requires server-side token management.
ZipStorage
ZipStorage
Handles .mcworld, .mcpack, and other ZIP-based formats.Use case: Packaging and reading Minecraft world/add-on archivesReference:
app/src/storage/ZipStorage.tsManager Pattern
Files and folders have a.manager property for extended logic:
World Structure
Worlds have a specialized structure for handling Minecraft world data:NBT Foundation
- NbtBinary.ts: Core NBT parsing for hierarchical typed data
- NbtBinaryTag.ts: Individual tag representation
- level.dat: World settings and metadata (see
app/src/minecraft/NbtBinary.ts:1)
LevelDB and Chunks
World data is stored in LevelDB format:- LevelKeyValue pairs: Most are tied to specific chunks or subchunks
- WorldLevelChunk: Focal point for understanding and unifying world data
- Chunk Organization: Data organized by dimension, X, and Z coordinates
app/src/minecraft/MCWorld.ts:1
Project Organization Patterns
Standard Add-on Structure
World Project Structure
Best Practices
Use Storage Abstractions
Always use the IStorage interface rather than direct file system access. This ensures cross-platform compatibility.
Common Patterns
Loading a Project
Working with Files
Accessing Managers
Troubleshooting
Files not appearing after creation
Files not appearing after creation
Remember to call
await folder.load() after creating or modifying files.ProjectItem not found
ProjectItem not found
Call
await project.inferProjectItemsFromFiles(true) to refresh the project item list.Storage path errors
Storage path errors
Use
StorageUtilities.canonicalizeName() to ensure path consistency across platforms.World data not loading
World data not loading
Ensure
await mcworld.loadMetaFiles(false) is called before accessing world properties.Related Resources
- Validation Rules - Understanding validation and info generators
- Working with Worlds - Deep dive into world manipulation
- Packaging Add-ons - Exporting and deployment