Project Structure
Learn about Motia's project structure, file organization, and automatic step discovery system for building scalable workflow applications.
Project Structure
Understanding how to organize your Motia project is crucial for building maintainable and scalable workflow applications. This guide covers the directory structure, file naming conventions, and Motia's automatic step discovery system.
Basic Project Structure
Here's what a typical Motia project looks like:
File Descriptions
File | Purpose | Type | Auto-Generated |
---|---|---|---|
01-api-gateway.step.ts | TypeScript API endpoint | User Code | - |
02-data-processor_step.py | Python data processing | User Code | - |
03-send-notification.step.js | JavaScript automation | User Code | - |
send-notification.tsx | Optional UI override component | User Code | - |
package.json | Node.js dependencies (if using JS/TS) | Config | - |
requirements.txt | Python dependencies (if using Python) | Config | - |
tsconfig.json | TypeScript config (if using TypeScript) | Config | - |
types.d.ts | Type definitions for your project | Generated | ✅ By TypeScript |
motia-workbench.json | 🤖 Visual workflow positioning | Generated | ✅ By Motia |
config.yml | Optional Motia configuration | Config | - |
The steps/
directory is the heart of your Motia application - this is where all your workflow logic lives. Motia automatically discovers and registers any file following the naming pattern.
- The
steps/
directory must live at the project root (e.g.,my-motia-project/steps
). - You can freely nest steps in subfolders under
steps/
(e.g.,steps/aaa/a1.step.ts
,steps/bbb/ccc/c1_step.py
). - Discovery is recursive inside
steps/
, so deeper folder structures for large apps are supported.
Automatic Step Discovery
Key Concept: Automatic Discovery
Motia will automatically discover and register any file that follows the .step.
naming pattern as a workflow step. You don't need to manually register steps - just create a file with the right naming pattern and Motia will find it.
Discovery Rules
Motia scans your steps/
directory and automatically registers files as steps based on these rules:
- File must contain
.step.
or_step.
in the filename (e.g.,my-task.step.ts
,my_task_step.py
) - File must export a
config
object defining the step configuration - File must export a
handler
function containing the step logic - File extension determines the runtime (
.ts
= TypeScript,.py
= Python,.js
= JavaScript)
When you run motia dev
, Motia will:
- Scan the
steps/
directory recursively - Find all files matching
*.step.*
- Parse their
config
exports to understand step types and connections - Register them in the workflow engine
- Make them available in the Workbench
File Naming Convention
Motia uses this specific pattern for automatic step discovery:
The .step.
part in the filename is required - this is how Motia identifies which files are workflow steps during automatic discovery.
Supported Languages & Extensions
Language | Extension | Example Step File | Runtime |
---|---|---|---|
TypeScript | .ts | user-registration.step.ts | Node.js with TypeScript |
Python | .py | data-analysis_step.py | Python interpreter |
JavaScript | .js | send-notification.step.js | Node.js |
Naming Examples by Step Type
Step Type | TypeScript | Python | JavaScript |
---|---|---|---|
API Endpoint | 01-auth-api.step.ts | 01-auth-api_step.py or auth_api_step.py | 01-auth-api.step.js |
Event Handler | process-order.step.ts | process-order_step.py or process_order_step.py | process-order.step.js |
Cron Job | daily-report.step.ts | daily-report_step.py or daily_report_step.py | daily-report.step.js |
Data Processing | transform-data.step.ts | ml-analysis_step.py or ml_analysis_step.py | data-cleanup.step.js |
Step Organization Patterns
Sequential Flow Organization
Perfect for linear workflows where order matters:
Step | Language | Purpose |
---|---|---|
01-api-start.step.ts | TypeScript | API endpoint |
02-validate-data_step.py | Python | Data validation |
03-process-payment.step.js | JavaScript | Payment processing |
04-send-confirmation.step.ts | TypeScript | Email service |
05-cleanup_step.py | Python | Cleanup tasks |
Language-Specific Configuration
TypeScript/JavaScript Projects
For Node.js-based steps, you'll need:
Python Projects
For Python-based steps:
Step Discovery Examples
Let's see how Motia discovers different step types:
Example 1: TypeScript API Step
Example 2: Python Event Step
Example 3: JavaScript Automation Step
Auto-Generated Files
Some files in your Motia project are automatically generated:
types.d.ts
- TypeScript generates this for type definitionsmotia-workbench.json
- Motia manages visual node positions in the Workbench
Discovery Troubleshooting
If Motia isn't discovering your steps:
Common Issues
Missing .step.
(or _step
for Python) in filename
❌ Won't be discovered:
✅ Will be discovered:
Discovery Verification
Check if your steps are discovered:
Next Steps
Now that you understand how Motia discovers and organizes steps:
- Learn about Core Concepts to understand how steps work together
- Explore Defining Steps for detailed step creation
- Check out Triggers for API, Event, and Cron steps