Skip to content

Plan Mode Guide

Deep dive into using Plan Mode for complex development tasks.

What is Plan Mode?

Plan Mode helps you think through complex tasks before implementation. It acts as a planning assistant that breaks down tasks, identifies risks, and creates step-by-step plans.

When to Use Plan Mode

Use Plan Mode for:

  • Complex Features: Multi-step features with many components
  • Refactoring: Large-scale code changes
  • Bug Investigation: Complex bugs requiring deep investigation
  • Architecture Decisions: Choosing between approaches
  • Team Planning: Planning work for the team

The Planning Process

Phase 1: Requirements Analysis

First, understand what needs to be built:

Task: Create user authentication system

Analysis:
- Need user registration
- Need login/logout
- Need password reset
- Need session management
- Need security (hashing, JWT)

Phase 2: Identify Dependencies

What does this task depend on?

Dependencies:
- Database schema for users
- Email service for password reset
- JWT library for tokens
- Security libraries (bcrypt, etc.)

Phase 3: Architecture Design

How should it be structured?

Architecture:
├── Models: User model
├── Services: AuthService (business logic)
├── Controllers: AuthController (API endpoints)
├── Middleware: AuthMiddleware (route protection)
├── Routes: Auth routes
└── Utils: Password hashing, JWT generation

Phase 4: Implementation Steps

Break it down into steps:

Step 1: Database Schema
  1.1 Create users table
  1.2 Add indexes
  1.3 Create migration

Step 2: User Model
  2.1 Define User model
  2.2 Add validation
  2.3 Add methods (hashPassword, verifyPassword)

Step 3: Authentication Service
  3.1 Implement register
  3.2 Implement login
  3.3 Implement logout
  3.4 Implement password reset

Step 4: Controllers
  4.1 Create AuthController
  4.2 Add endpoints
  4.3 Add error handling

Step 5: Middleware
  5.1 Create AuthMiddleware
  5.2 Add JWT validation
  5.3 Add user context

Step 6: Routes
  6.1 Define routes
  6.2 Add middleware
  6.3 Add validation

Step 7: Testing
  7.1 Unit tests for service
  7.2 Integration tests for API
  7.3 End-to-end tests

Phase 5: Risk Assessment

What could go wrong?

Risks:
1. Security: Passwords must be hashed
   Mitigation: Use bcrypt with proper rounds

2. JWT Security: Tokens could be stolen
   Mitigation: Use short expiration, refresh tokens

3. Email Delivery: Password reset emails might not send
   Mitigation: Queue system, retry logic

4. Database: Performance issues with large user base
   Mitigation: Add indexes, pagination

Detailed Examples

Example 1: Building a REST API

Task: Create REST API for blog posts

Plan:

1. Requirements
   • CRUD operations for posts
   • Post categories
   • Post tags
   • Search functionality
   • Pagination

2. Data Model
   • Post entity
   • Category entity
   • Tag entity
   • Many-to-many relationships

3. API Endpoints
   GET    /posts           - List all posts
   GET    /posts/:id       - Get single post
   POST   /posts           - Create post
   PUT    /posts/:id       - Update post
   DELETE /posts/:id       - Delete post
   GET    /posts/search    - Search posts
   GET    /categories      - List categories
   GET    /tags            - List tags

4. Implementation Order
   1. Create database schema
   2. Create models
   3. Create service layer
   4. Create controllers
   5. Add authentication/authorization
   6. Add search functionality
   7. Add tests
   8. Add documentation

Estimated Time: 4-6 hours
Risk Level: Low

Example 2: Refactoring

Task: Refactor UserController

Current Issues:
- Large file (500+ lines)
- Too many responsibilities
- Hard to test
- Poor error handling

Refactoring Plan:

Phase 1: Analysis
  1. Identify responsibilities
  2. Map dependencies
  3. Document current behavior

Phase 2: Extract
  1. Extract validation logic → ValidationService
  2. Extract data access → UserService
  3. Extract email sending → EmailService
  4. Extract logging → Logger

Phase 3: Simplify
  1. Apply Single Responsibility
  2. Reduce complexity
  3. Improve naming
  4. Add error handling

Phase 4: Test
  1. Add unit tests for services
  2. Add integration tests for controller
  3. Ensure backward compatibility

Phase 5: Deploy
  1. Feature flag
  2. Monitor metrics
  3. Rollback plan

Estimated Time: 2-3 hours
Risk Level: Medium

Example 3: Debugging

Task: Debug payment processing failure

Symptoms:
- Intermittent failures
- No clear error messages
- Affects ~5% of transactions

Investigation Plan:

1. Gather Information
   • Check error logs
   • Identify failure patterns
   • Review recent changes

2. Reproduce Issue
   • Test with different payment methods
   • Test different amounts
   • Test at different times
   • Capture detailed logs

3. Hypothesis Generation
   • Network timeout?
   • API rate limit?
   • Race condition?
   • Invalid data?
   • Payment gateway issue?

4. Test Hypotheses
   • Add logging at each step
   • Test with controlled conditions
   • Monitor in production

5. Identify Root Cause
   • Analyze logs
   • Correlate with events
   • Confirm hypothesis

6. Implement Fix
   • Code the fix
   • Add tests
   • Document change

7. Verify
   • Test in staging
   • Monitor production
   • Rollback if needed

Estimated Time: 4-8 hours
Risk Level: Medium

Customizing Plans

Adding Custom Steps

Task: Create API for X

Plan:
[MyDeskBot generates default plan]

You: Add security review step
[MyDeskBot adds: "Step 5: Security Review"]

You: Add documentation step
[MyDeskBot adds: "Step 6: Documentation"]

Modifying Steps

Task: Create user feature

Plan: Step 1: Database
You: Split into two steps:
  1.1 Create schema
  1.2 Create migration

Reordering Steps

Plan:
Step 1: Create model
Step 2: Create API
Step 3: Add tests

You: Move tests before API
[MyDeskBot reorders]
Step 1: Create model
Step 2: Add tests
Step 3: Create API

Plan Templates

Create reusable plan templates:

json
{
  "mydeskbot.planMode.templates": {
    "REST API": {
      "phases": [
        "Requirements Analysis",
        "Data Model",
        "API Design",
        "Implementation",
        "Testing",
        "Documentation"
      ]
    },
    "Refactoring": {
      "phases": [
        "Analyze Current Code",
        "Identify Issues",
        "Plan Changes",
        "Implement",
        "Test",
        "Deploy"
      ]
    },
    "Bug Fix": {
      "phases": [
        "Investigate",
        "Hypothesize",
        "Test Hypothesis",
        "Implement Fix",
        "Verify",
        "Deploy"
      ]
    }
  }
}

Best Practices

1. Be Specific

Provide clear requirements:

Good: Create a user API with JWT auth, rate limiting (100 req/min), and detailed logging

Bad: Create user stuff

2. Review Before Implementing

Always review the plan:

You: Plan the feature
[Plan created]

You: Can we add caching?
[Plan updated]

You: What about monitoring?
[Plan updated with metrics]

You: OK, let's implement

3. Break Down Complex Tasks

Don't create huge plans:

Bad: Plan entire e-commerce platform

Good: Plan shopping cart feature
Good: Plan payment processing
Good: Plan user authentication

4. Estimate Time

Get time estimates for planning:

Task: Create user API

Plan: [detailed plan]
Estimated Time: 4-6 hours
Risk Level: Low

This helps with sprint planning

5. Document Decisions

MyDeskBot keeps a decision log:

Decision Log:
- Chose PostgreSQL over MongoDB (ACID transactions needed)
- Using JWT for auth (stateless, scalable)
- Redis for caching (already available)
- REST over GraphQL (simpler, team familiar)

Integration with Other Features

With Code Completion

Plan Mode: Creates the plan
Code Completion: Implements each step

With Code Review

Plan Mode: Designs the approach
Code Review: Validates implementation

With Continuous AI

Plan Mode: Sets direction
Continuous AI: Helps execute

Exporting Plans

Export as Markdown

File → Export Plan → Markdown

Example output:

markdown
# Plan: User Authentication System

## Requirements

- User registration
- Login/logout
- Password reset
- JWT authentication

## Implementation Steps

1. Database schema
2. User model
3. Auth service
4. Auth controller
5. Auth middleware
6. Tests

## Risk Assessment

- Security: Use bcrypt
- JWT: Short expiration
- Email: Queue system

Export as Checklist

File → Export Plan → Checklist

Share with Team

File → Export Plan → Share Link

Advanced Features

Dependency Graphs

Visualize dependencies:

Dependencies:
AuthService → User model → Database
AuthService → JWT library
AuthService → EmailService → SMTP server

Timeline View

See project timeline:

Week 1:
  Day 1-2: Database schema
  Day 3-4: User model
  Day 5: Auth service

Week 2:
  Day 1-2: Auth controller
  Day 3-4: Auth middleware
  Day 5: Testing

Resource Allocation

Assign resources:

Resources:
  Developer A: Backend (AuthService, Controller)
  Developer B: Database (Schema, Model)
  Developer C: Testing (Unit, Integration)

See Also