DocsGetting StartedProject Structure

Project Structure and Organization

This page provides a guide for organizing folders and files in Mastra. Mastra is a modular framework, and you can use any of the modules separately or together.

You could write everything in a single file (as we showed in the quick start), or separate each agent, tool, and workflow into their own files.

We don’t enforce a specific folder structure, but we do recommend some best practices, and the CLI will scaffold a project with a sensible structure.

Using the CLI

mastra init is an interactive CLI that allows you to:

  • Choose a directory for Mastra files: Specify where you want the Mastra files to be placed (default is src/mastra).
  • Select components to install: Choose which components you want to include in your project:
    • Agents
    • Tools
    • Workflows
  • Select a default LLM provider: Choose from supported providers like OpenAI, Anthropic, or Groq.
  • Include example code: Decide whether to include example code to help you get started.

Example Project Structure

Assuming you select all components and include example code, your project structure will look like this:

          • index.ts
          • index.ts
          • index.ts
        • index.ts
    • .env

Top-level Folders

FolderDescription
src/mastraCore application folder
src/mastra/agentsAgent configurations and definitions
src/mastra/toolsCustom tool definitions
src/mastra/workflowsWorkflow definitions

Top-level Files

FileDescription
src/mastra/index.tsMain configuration file for Mastra
.envEnvironment variables

MIT 2025 © Nextra.