Minimal Structure
Here is the minimal structure for a Cardinal project:| File / Directory | Description |
|---|---|
shards/ | Source code for your game shards. |
shards/<shard-id>/main.go | The entry point for the shard. |
world.toml | Project configuration. |
go.mod | Go dependency definition. |
Registering Shards
To include a shard in your project, you must define it in theworld.toml file. The World CLI only builds and runs shards that are explicitly listed in this configuration.
By default, the framework looks for a shard’s source code in shards/<shard-id>. You can override this location by specifying the path key (relative to the project root).
world.toml
TODO: Fix the link below.
Examples
Organization by Concept
In this structure, code within a shard is organized by Cardinal concepts: components, systems, events, etc.Organization by Domain
For larger, more complex projects, you may prefer a domain-driven approach where code is grouped by feature (e.g., combat, movement).internal/: Contains the domain logic and definitions. The specialinternaldirectory name prevents these packages from being imported by other shards, as enforced by Go’s internal packages rule.types/: Contains type aliases to the definitions in theinternaldomain packages. This acts as the public API for the shard.
types/, you allow other shards to interact with your data without exposing your internal logic or creating direct dependencies on your implementation packages.