OpenWriterControle/plugins/claude-code/scripts/context/development/ai/mastra-ai/guides/modular-building.md
Darren Hinde a8fc9c7715
feat(plugin): enhance context management and skill invocation (#239)
* fix(shellcheck): declare and assign separately in router.sh (SC2155)

* feat(plugin): enhance context management and skill invocation

- Update .context-manifest.json to include profile and detailed source information.
- Revise context-scout.md to clarify context root discovery and navigation.
- Modify commands to replace deprecated skills with updated ones (brainstorming → approach, systematic-debugging → debugger).
- Streamline install-context.md for clarity and remove interactive profile selection.
- Improve oac-status.md to provide a more comprehensive status report.
- Add OAC system paths to session-start.sh for better context management.
- Remove obsolete skills and improve documentation for existing commands.
2026-02-23 12:12:29 +00:00

1.4 KiB

Guide: Modular Mastra Building

Purpose: Best practices for structuring a large-scale Mastra implementation.

Last Updated: 2026-01-09


Core Idea

Modular building ensures that as the project grows, components remain testable, reusable, and easy to navigate. This is achieved by separating logic into specialized directories and using a central registry.

Key Points

  • Component Separation: Keep agents, tools, workflows, and scorers in their own top-level directories within src/mastra/.
  • Shared Services: Use a shared.ts file to instantiate services (DB, repositories) to prevent circular dependencies between workflows and the main Mastra instance.
  • Central Registry: Register all components in src/mastra/index.ts. This is the single source of truth for the Mastra instance.
  • Feature-Based Steps: Group related workflow steps into sub-directories (e.g., src/mastra/workflows/v3/steps/) to keep workflow files clean.

Quick Example

// src/mastra/shared.ts
export const services = createServices();

// src/mastra/index.ts
import { services } from './shared';
export const mastra = new Mastra({
  workflows: { myWorkflow },
  agents: { myAgent },
  // ...
});

Reference: src/mastra/index.ts, src/mastra/shared.ts Related:

  • concepts/core.md
  • guides/workflow-step-structure.md