Overview
Projects in moon represent discrete units of code that can be built, tested, and deployed. Each project:- Has a unique identifier (ID) or alias
- Can depend on other projects
- Inherits or defines tasks
- Has its own configuration
- Belongs to a specific language/toolchain
Project IDs
A project identifier (or name) is a unique resource for locating a project. The ID is explicitly configured within.moon/workspace.yml, as a key within the projects setting, and can be written in camel/kebab/snake case.
ID Requirements
IDs support:- Alphabetic unicode characters
- Numbers
0-9 - Underscores
_, hyphens-, forward slashes/, dots. - Must start with a character
.moon/workspace.yml
IDs are used throughout moon for configuration and CLI commands. They’re typically easier to remember and type than full file paths.
Usage Examples
Project Aliases
Aliases are a secondary approach for naming projects, and can be used as a drop-in replacement for standard IDs. An alias can be used when configuring dependencies or defining targets.How Aliases Work
The difference between aliases and IDs is that aliases cannot be explicitly configured in moon. Instead, they are derived from the toolchain that has been detected for the project. Examples:- A JavaScript project uses the
namefield frompackage.jsonas the alias - A Rust project uses the package name from
Cargo.toml - A Python project uses the package name from
pyproject.toml
packages/ui/package.json
.moon/workspace.yml
Because of this, a project can be referenced by its name or alias, or both. Choose the pattern that makes the most sense for your company or team!
Project Dependencies
Projects can depend on other projects within the workspace to build a project graph, and in turn, an action graph for executing tasks. Project dependencies are divided into 2 categories:Explicit Dependencies
These are dependencies that are explicitly defined in a project’smoon.yml config file, using the dependsOn setting.
apps/web/moon.yml
Implicit Dependencies
These are dependencies that are implicitly discovered by moon when scanning the repository. How an implicit dependency is discovered is based on the project’slanguage setting, and how that language’s ecosystem functions.
For JavaScript/TypeScript projects:
Moon automatically detects dependencies from package.json:
packages/api/package.json
@company/shared dependency is automatically discovered as an implicit project dependency.
Dependency Resolution
When you runmoon run web:build, moon automatically:
- Analyzes the dependency graph
- Determines the correct build order
- Runs dependency tasks first
- Executes the web build task
Project Configuration
Projects can be configured with an optionalmoon.yml in the project root, or through the workspace-level .moon/tasks/**/* for inherited tasks.
Basic Configuration
packages/api/moon.yml
Project Metadata
Theproject field allows you to add rich metadata:
moon.yml
Language and Toolchain
Specify the language and platform for the project:moon.yml
The
language setting determines which toolchain is used and how implicit dependencies are detected.Project Types
Applications
Deployable applications that produce runnable artifacts:apps/web/moon.yml
Libraries
Reusable packages consumed by other projects:packages/ui/moon.yml
Tools
Internal tooling and scripts:tools/codegen/moon.yml
Task Inheritance
Projects automatically inherit tasks from workspace-level configurations in.moon/tasks/. You can control this inheritance:
moon.yml
File Groups
Define reusable file groups for use in task inputs:moon.yml
Tags
Tags allow you to group and target multiple projects:moon.yml
Best Practices
Keep projects focused and cohesive
Keep projects focused and cohesive
Each project should have a single, well-defined purpose. Avoid creating monolithic projects that do too much.
Use explicit dependencies when possible
Use explicit dependencies when possible
While implicit dependencies are convenient, explicit dependencies in
moon.yml make the dependency graph clearer and more maintainable.Leverage tags for organization
Leverage tags for organization
Document your projects
Document your projects
Use the
project metadata fields to document the purpose, maintainers, and communication channels for each project.Related Concepts
- Workspace - The root container for all projects
- Tasks - Commands that run in project context
- Targets - Project:task identifiers
- Dependencies - Task and project dependencies