Thank you for your interest in contributing to MoFA! This document covers everything you need to get started as a contributor to the Rust implementation of MoFA.
- Rust Toolchain Setup
- Common Commands
- Architecture Overview
- Microkernel Layer Rules
- Branch Naming Conventions
- Commit Message Conventions
- Pull Request Guidelines
- Security Guidelines
- Reporting Issues and Discussions
- License
MoFA requires a recent stable Rust toolchain. We target Rust edition 2024.
# Install rustup (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install the latest stable toolchain
rustup toolchain install stable
rustup default stable
# Verify installation
rustc --version # should be 1.85+ for edition 2024 support
cargo --version
# Clone the repository
git clone https://github.com/mofa-org/mofa.git
cd mofa# Build the entire workspace
cargo build
cargo build --release
# Build a specific crate
cargo build -p mofa-sdk
cargo build -p mofa-cli
# Run all tests
cargo test
# Run tests for a specific crate (preferred for focused development)
cargo test -p mofa-sdk
cargo test -p mofa-runtime
cargo test -p mofa-plugins
# Run a specific test by name
cargo test -p mofa-sdk -- test_name
# Format code (run before every commit)
cargo fmt
# Check formatting without modifying files
cargo fmt --check
# Run the linter (must pass with no warnings before opening a PR)
cargo clippy
# Fast compilation check (no output artifacts)
cargo check
# Run the CLI
cargo run -p mofa-cli -- mofa --helpBefore making changes, please read:
- CLAUDE.md — Full architecture description, workspace structure, feature flags, and layering rules.
- docs/architecture.md — High-level design document.
mofa/
├── Cargo.toml # Workspace root
├── crates/
│ ├── mofa-kernel/ # Microkernel core — traits and core types ONLY
│ ├── mofa-foundation/ # Concrete implementations and business logic
│ ├── mofa-runtime/ # Runtime system (message bus, registry, event loop)
│ ├── mofa-plugins/ # Plugin system (dual-layer architecture)
│ ├── mofa-cli/ # CLI tool (`mofa` command)
│ ├── mofa-sdk/ # Main SDK — public API surface
│ ├── mofa-ffi/ # FFI bindings (UniFFI for Python, Java, Go, Kotlin, Swift)
│ ├── mofa-macros/ # Procedural macros
│ ├── mofa-monitoring/ # Monitoring and observability
│ └── mofa-extra/ # Additional utilities
└── examples/ # 27+ usage examples
MoFA enforces a strict layered architecture. Violating these rules will block a PR.
| Layer | Allowed | Forbidden |
|---|---|---|
mofa-kernel |
Trait definitions, core data types (AgentInput, AgentOutput, AgentState) |
Concrete implementations, business logic |
mofa-foundation |
Concrete implementations, business-specific types | Re-defining kernel traits, depending on mofa-foundation from kernel |
mofa-plugins |
Plugin adapters and concrete plugin implementations | — |
mofa-sdk |
Re-exports of user-facing APIs | Heavy logic (delegate to lower crates) |
Dependency direction (arrows = "may depend on"):
mofa-sdk → mofa-runtime → mofa-foundation → mofa-kernel
mofa-plugins → mofa-foundation → mofa-kernel
mofa-kernel must never depend on mofa-foundation (circular dependency).
- New trait definitions live in
mofa-kernel. - Concrete
structimplementations live inmofa-foundationormofa-plugins. -
mofa-foundationdoes not re-define a trait already present inmofa-kernel. - No new circular dependencies introduced (
cargo checkcatches these).
| Type | Pattern | Example |
|---|---|---|
| New feature | feature/<short-description> |
feature/rhai-hot-reload |
| Bug fix | fix/<short-description> |
fix/registry-deadlock |
| Documentation | docs/<short-description> |
docs/add-contributing |
| Refactor | refactor/<short-description> |
refactor/kernel-trait-split |
| Chore / CI | chore/<short-description> |
chore/update-dependencies |
Use lowercase kebab-case for all branch names.
Follow the Conventional Commits specification:
<type>(<scope>): <short summary>
[optional body]
[optional footer]
Types: feat, fix, docs, refactor, test, chore, perf, ci
Scope should be the crate name without the mofa- prefix (e.g., kernel, foundation, sdk, cli).
Examples:
feat(sdk): add secretary agent draft PR workflow
fix(runtime): resolve deadlock in AgentRegistry under high concurrency
docs(kernel): clarify trait definition placement rules
refactor(foundation): extract SimpleToolRegistry to its own module
- Keep the summary line under 72 characters.
- Use the imperative mood ("add", "fix", "remove" — not "added" or "fixes").
- Reference issues in the footer:
Closes #42orRelated to #17.
- Fork the repository and work on your own fork.
- Base your branch on the latest
main. - Run the full quality gate locally:
cargo fmt --check cargo clippy --workspace --all-features -- -D errors cargo test --workspace --all-features cargo build --examples cargo doc --workspace --no-deps --all-features - Make sure every commit compiles on its own (
cargo checkper commit).
Open a draft PR early when:
- You want early feedback on direction before the implementation is complete.
- The change is large and you want to discuss the approach first.
Mark it as "Ready for review" only when all quality gates pass:
cargo fmt --check
cargo clippy --workspace --all-features -- -D errors
cargo test --workspace --all-features
cargo build --examples
cargo doc --workspace --no-deps --all-features## Summary
<!-- What does this PR do? -->
## Motivation
<!-- Why is this change needed? -->
## Changes
<!-- Bullet list of what was changed and in which crate. -->
## Related Issues
<!-- Link to a related issue if present -->
## Testing
<!-- How was this tested? New unit tests? Manual verification? -->
## Checklist
- [ ] `cargo fmt --check` passes
- [ ] `cargo clippy --workspace --all-features -- -D errors` passes
- [ ] `cargo test --workspace --all-features` passes
- [ ] `cargo build --examples` succeeds
- [ ] `cargo doc --workspace --no-deps --all-features` succeeds
- [ ] Architecture layer rules respected (see CONTRIBUTING.md)
- [ ] Relevant documentation updated- At least one maintainer approval is required to merge.
- Address all review comments before requesting a re-review.
- Prefer small, focused PRs over large monolithic ones — they get reviewed faster.
All PRs must pass the PR Guard CI job before they can be merged. This check runs automatically and verifies:
- Clippy - No compilation errors with all features enabled
- Tests - All tests pass with all features enabled
- Examples - All examples compile successfully
- Documentation - Documentation builds without errors
# Run these locally before pushing to ensure your PR will pass
cargo clippy --workspace --all-features -- -D errors # Lint with all features
cargo test --workspace --all-features # Test with all features
cargo build --examples # Build all examples
cargo doc --workspace --no-deps --all-features # Build documentationNote: Branch protection rules are enabled on main and master branches. PRs cannot be merged until all required status checks pass.
We take security seriously. When contributing to MoFA, please follow these security best practices:
- NEVER commit secrets, credentials, or sensitive data to the repository
- Use environment variables for configuration secrets
- Add
.envfiles to.gitignore - Use placeholder values in examples and documentation
// DO
let api_key = std::env::var("OPENAI_API_KEY")?;
// DO NOT
let api_key = "sk-abc123..."; // Never hardcode credentials- Validate all input parameters
- Sanitize all output data
- Use error handling (avoid
unwrap()andexpect()in production code) - Follow the principle of least privilege
- Avoid unsafe code when possible
- Use type-safe interfaces
- Keep dependencies up to date
- Review security advisories for dependencies
- Use
cargo-auditto check for vulnerable dependencies:cargo install cargo-audit cargo audit
- Use
cargo-denyto enforce dependency policies:cargo install cargo-deny cargo deny check
- DO NOT report security vulnerabilities in public issues or PRs
- Report security vulnerabilities privately through GitHub Security Advisories
- See SECURITY.md for detailed reporting instructions
For more information on security best practices, see our Security Guide.
- Bug reports & feature requests → GitHub Issues
- Search for existing issues before opening a new one.
- For bugs, include: Rust version (
rustc --version), OS, and a minimal reproducer.
- Questions, ideas, and general discussion → GitHub Discussions
- Security vulnerabilities → Do not open a public issue. Email the maintainers directly (see SECURITY.md).
- Community chat → Discord
By contributing, you agree that your contributions will be licensed under the Apache License 2.0.