BMAD-METHOD/docs/memory-architecture/cursor-ai-implementation-gu...

16 KiB

BMAD Method Memory Enhancement: Cursor AI Implementation Guide

Overview

This guide provides comprehensive instructions for implementing BMAD Method Memory Enhancement in Cursor AI. Cursor AI's IDE integration and workspace awareness make it ideal for persistent, project-based BMAD memory management.

Quick Setup (5 minutes)

Step 1: Create BMAD Memory Structure

# In your project root
mkdir -p .bmad-memory/{storage/{working,decision,solution,learning,pattern,semantic},config,logs,exports}

# Create BMAD memory index
touch .bmad-memory/memory-index.json
touch .bmad-memory/config/bmad-config.json

Step 2: Configure Cursor AI for BMAD

Create .cursor/instructions.md:

# BMAD Method Memory Enhancement - Cursor AI Integration

You are working with the BMAD Method enhanced with intelligent memory capabilities.

## BMAD MEMORY SYSTEM ACTIVATION

BMAD STARTUP SEQUENCE:
1. Check .bmad-memory/ folder for existing BMAD memories
2. Load BMAD memory index from .bmad-memory/memory-index.json
3. Create BMAD working memory for current session
4. Reference relevant BMAD memories in code suggestions

## BMAD MEMORY COMMANDS

Respond to these BMAD commands in chat:
- /bmad-remember [content] [type] [importance]  Create BMAD methodology memory
- /bmad-recall [query] [type] [limit]  Search BMAD methodology memories
- /bmad-memories [filter]  List BMAD methodology memories
- /bmad-status  Show BMAD methodology memory status
- /bmad-workspace  Analyze workspace for BMAD patterns

## BMAD MEMORY STORAGE

Store BMAD memories in:
- .bmad-memory/storage/[type]/bmad_mem_[id].json
- Update .bmad-memory/memory-index.json with new BMAD memories
- Log BMAD memory operations in .bmad-memory/logs/

## BMAD MEMORY-ENHANCED CODING

Before suggesting code:
1. Check for relevant BMAD patterns in memory
2. Reference previous BMAD solutions for similar problems
3. Apply established BMAD coding standards

After solving problems:
1. Create BMAD solution memories for reuse
2. Update BMAD pattern memories with new insights
3. Document BMAD architecture decisions

## BMAD AUTOMATIC MEMORY CREATION

Create BMAD memories automatically when:
- Making architecture decisions  DECISION memory
- Solving coding problems  SOLUTION memory
- Establishing patterns  PATTERN memory
- Learning new approaches  LEARNING memory

## BMAD WORKSPACE INTEGRATION

- Analyze codebase for existing BMAD patterns
- Suggest improvements based on BMAD memory
- Maintain consistency with established BMAD approaches
- Track BMAD methodology evolution over time

BMAD Method Memory Enhancement is now active in Cursor AI.

Step 3: Initialize BMAD Memory System

Open Cursor AI chat and run:

/bmad-workspace

Expected Response:
BMAD WORKSPACE ANALYSIS COMPLETE:

Project Structure:
- .bmad-memory/ folder:  Found
- BMAD memory storage:  Initialized
- BMAD memory index:  Ready

BMAD Memory Status:
- Total BMAD memories: 0 (new project)
- BMAD memory types available: WORKING, DECISION, SOLUTION, LEARNING, PATTERN, SEMANTIC
- BMAD storage location: .bmad-memory/storage/

Workspace BMAD Patterns Detected:
- Package.json: React + TypeScript project
- Folder structure: Standard React app
- BMAD methodology: Ready to establish

Ready for memory-enhanced BMAD development. What shall we build?

BMAD Memory File Structure

BMAD Memory Storage Format

// .bmad-memory/storage/decision/bmad_mem_001.json
{
  "id": "bmad_mem_001",
  "type": "DECISION",
  "content": "BMAD Method recommends TypeScript with strict mode for type safety",
  "importance": 0.8,
  "tags": ["bmad", "methodology", "typescript", "type-safety"],
  "created": "2024-01-15T10:30:00Z",
  "updated": "2024-01-15T10:30:00Z",
  "project": "component-library",
  "context": {
    "file": "tsconfig.json",
    "function": "project_setup",
    "related_files": ["package.json", "src/types/"]
  },
  "relationships": [],
  "usage_count": 0,
  "last_accessed": "2024-01-15T10:30:00Z"
}

BMAD Memory Index

// .bmad-memory/memory-index.json
{
  "version": "1.0.0",
  "project": "component-library",
  "created": "2024-01-15T10:00:00Z",
  "updated": "2024-01-15T10:30:00Z",
  "total_memories": 1,
  "memories": {
    "bmad_mem_001": {
      "type": "DECISION",
      "importance": 0.8,
      "tags": ["bmad", "methodology", "typescript"],
      "file": "storage/decision/bmad_mem_001.json",
      "created": "2024-01-15T10:30:00Z"
    }
  },
  "tags": {
    "bmad": ["bmad_mem_001"],
    "methodology": ["bmad_mem_001"],
    "typescript": ["bmad_mem_001"]
  },
  "types": {
    "DECISION": ["bmad_mem_001"],
    "SOLUTION": [],
    "PATTERN": [],
    "LEARNING": [],
    "WORKING": [],
    "SEMANTIC": []
  }
}

BMAD Commands in Cursor AI

Create BMAD Memory

/bmad-remember "BMAD Method recommends component composition over inheritance" PATTERN 0.8

Expected Response:
[CREATED] bmad_mem_002: PATTERN
CONTENT: BMAD Method recommends component composition over inheritance
IMPORTANCE: 0.8
TAGS: bmad, methodology, composition, inheritance, components
FILE: .bmad-memory/storage/pattern/bmad_mem_002.json
CONTEXT: Current workspace, React development

BMAD memory created and saved to workspace. This pattern will guide future component development.

Search BMAD Memories

/bmad-recall "component composition"

Expected Response:
BMAD MEMORY SEARCH RESULTS:

bmad_mem_002 (PATTERN, importance: 0.8)
CONTENT: BMAD Method recommends component composition over inheritance
TAGS: bmad, methodology, composition, inheritance, components
CREATED: 2024-01-15T10:35:00Z
FILE: .bmad-memory/storage/pattern/bmad_mem_002.json

Found 1 BMAD memory matching "component composition"

Analyze BMAD Workspace

/bmad-workspace

Expected Response:
BMAD WORKSPACE ANALYSIS:

Current Project: component-library
BMAD Memories: 2 total
- DECISION: 1 memory
- PATTERN: 1 memory

Recent BMAD Activity:
- TypeScript configuration established (bmad_mem_001)
- Component composition pattern documented (bmad_mem_002)

Codebase BMAD Pattern Analysis:
- src/components/: Following composition pattern 
- tsconfig.json: Strict mode enabled 
- package.json: TypeScript dependencies 

BMAD Recommendations:
- Consider creating BMAD memory for component naming conventions
- Document BMAD testing patterns as they emerge
- Establish BMAD folder structure patterns

Workspace is aligned with BMAD methodology.

BMAD Memory-Enhanced Development Workflow

Example 1: BMAD Component Development

User: "Help me create a reusable Button component using BMAD methodology"

Cursor AI: "/bmad-recall 'component'

Found relevant BMAD memories:
- bmad_mem_002: Component composition over inheritance

Based on established BMAD patterns, I'll create a Button component using composition.

```tsx
// src/components/Button/Button.tsx
// Following BMAD composition pattern (bmad_mem_002)

import React from 'react';
import { ButtonVariant, ButtonSize } from './Button.types';
import { useButtonStyles } from './Button.hooks';

interface ButtonProps {
  variant?: ButtonVariant;
  size?: ButtonSize;
  disabled?: boolean;
  children: React.ReactNode;
  onClick?: () => void;
}

export const Button: React.FC<ButtonProps> = ({
  variant = 'primary',
  size = 'medium',
  disabled = false,
  children,
  onClick
}) => {
  const styles = useButtonStyles({ variant, size, disabled });
  
  return (
    <button
      className={styles}
      disabled={disabled}
      onClick={onClick}
    >
      {children}
    </button>
  );
};

[AUTO-CREATED] bmad_mem_003: PATTERN CONTENT: BMAD Button component uses composition with variant and size props IMPORTANCE: 0.7 TAGS: bmad, methodology, button, component, composition, variants FILE: .bmad-memory/storage/pattern/bmad_mem_003.json

This follows our established BMAD composition pattern and creates a reusable, configurable Button component.


### Example 2: BMAD Problem Solving

User: "I'm getting TypeScript errors in my component props"

Cursor AI: "/bmad-recall 'typescript'

Found relevant BMAD memory:

  • bmad_mem_001: TypeScript with strict mode for type safety

Let me analyze the TypeScript errors in context of our BMAD methodology.

[Analyzes the specific errors in the codebase]

The issue is with prop type definitions. Based on our BMAD TypeScript approach (strict mode), here's the solution:

// Fix: Define proper interface for component props
interface ComponentProps {
  title: string;
  items: Array<{
    id: string;
    name: string;
    value: number;
  }>;
  onItemClick: (id: string) => void;
}

// Use the interface in your component
export const Component: React.FC<ComponentProps> = ({ title, items, onItemClick }) => {
  // Component implementation
};

[AUTO-CREATED] bmad_mem_004: SOLUTION CONTENT: BMAD TypeScript solution - Define explicit interfaces for component props to satisfy strict mode IMPORTANCE: 0.8 TAGS: bmad, methodology, typescript, props, interfaces, strict-mode FILE: .bmad-memory/storage/solution/bmad_mem_004.json CONTEXT: TypeScript error resolution, component props

This solution follows our BMAD TypeScript methodology and will prevent similar issues in the future.


### Example 3: BMAD Architecture Decision

User: "Should we use Redux or Context API for state management?"

Cursor AI: "/bmad-recall 'state management'

No existing BMAD memories found for state management. Let me help you make this architectural decision using BMAD methodology.

Based on your project structure and requirements, here's my BMAD analysis:

Project Size: Medium (component library) Complexity: Moderate Team Size: Small to medium

BMAD RECOMMENDATION: Start with Context API, migrate to Redux if complexity grows

Reasoning:

  1. Context API aligns with BMAD simplicity principle
  2. Easier to implement and maintain initially
  3. Can be refactored to Redux later if needed
  4. Better for component library use case

[AUTO-CREATED] bmad_mem_005: DECISION CONTENT: BMAD state management decision - Use Context API for initial implementation, consider Redux for complex state IMPORTANCE: 0.9 TAGS: bmad, methodology, state-management, context-api, redux, architecture FILE: .bmad-memory/storage/decision/bmad_mem_005.json CONTEXT: Architecture planning, state management selection

This BMAD decision will guide our state management approach and can be referenced for future projects.


## Advanced BMAD Features in Cursor AI

### BMAD Memory Relationships

/bmad-relate bmad_mem_002 "supports" bmad_mem_003 0.9

Expected Response: BMAD MEMORY RELATIONSHIP CREATED: bmad_mem_002 (Component composition pattern) SUPPORTS bmad_mem_003 (Button component pattern) with strength 0.9

Relationship saved to:

  • .bmad-memory/storage/pattern/bmad_mem_002.json (updated)
  • .bmad-memory/storage/pattern/bmad_mem_003.json (updated)

This relationship shows how our general BMAD composition pattern supports the specific Button implementation.


### BMAD Code Analysis

/bmad-analyze-file src/components/Button/Button.tsx

Expected Response: BMAD FILE ANALYSIS: src/components/Button/Button.tsx

BMAD Patterns Detected: Component composition (matches bmad_mem_002) TypeScript interfaces (matches bmad_mem_001) Variant-based design (matches bmad_mem_003)

BMAD Compliance Score: 95%

Suggestions:

  • Consider adding BMAD error boundary pattern
  • Document BMAD testing approach for this component

Related BMAD Memories:

  • bmad_mem_001: TypeScript strict mode
  • bmad_mem_002: Component composition
  • bmad_mem_003: Button component pattern

File follows established BMAD methodology well.


### BMAD Project Templates

/bmad-create-template COMPONENT

Expected Response: BMAD COMPONENT TEMPLATE CREATED:

Template saved to: .bmad-memory/templates/component-template.tsx

// BMAD Component Template
// Generated from established BMAD patterns

import React from 'react';

interface {{ComponentName}}Props {
  // Define props following BMAD TypeScript patterns (bmad_mem_001)
}

export const {{ComponentName}}: React.FC<{{ComponentName}}Props> = ({
  // Destructure props
}) => {
  // Component implementation following BMAD composition pattern (bmad_mem_002)
  
  return (
    <div>
      {/* Component JSX */}
    </div>
  );
};

// Export types for composition (BMAD pattern)
export type { {{ComponentName}}Props };

Use this template for consistent BMAD component development.


## BMAD Memory Persistence and Sync

### Export BMAD Memories

/bmad-export

Expected Response: BMAD MEMORY EXPORT CREATED:

Export file: .bmad-memory/exports/bmad-export-20240115.json Export format: Complete project BMAD memory dump

Contents:

  • 5 BMAD memories
  • Memory relationships
  • Project context
  • Usage statistics

Export can be imported into other BMAD projects or shared with team members.


### Import BMAD Memories

/bmad-import .bmad-memory/exports/bmad-export-20240115.json

Expected Response: BMAD MEMORY IMPORT SUCCESSFUL:

Imported:

  • 5 BMAD memories
  • 2 memory relationships
  • Project context: component-library

Conflicts resolved:

  • bmad_mem_003: Merged with existing memory
  • bmad_mem_005: Updated with newer version

BMAD memory system updated with imported knowledge.


### Team BMAD Memory Sharing

```bash
# Share BMAD memories with team via git
git add .bmad-memory/
git commit -m "Add BMAD methodology memories for component patterns"
git push

# Team members get BMAD memories when they pull
git pull
# Cursor AI automatically loads shared BMAD memories

BMAD Integration with Cursor AI Features

BMAD + Cursor Composer

User: "Use Cursor Composer to create a form component following BMAD methodology"

Cursor AI: "/bmad-recall 'component'

Found BMAD patterns:
- Component composition (bmad_mem_002)
- TypeScript interfaces (bmad_mem_001)
- Button component pattern (bmad_mem_003)

I'll use Composer to create a form component following established BMAD patterns.

[Composer creates multiple files following BMAD methodology]

Files created:
- src/components/Form/Form.tsx (following BMAD composition)
- src/components/Form/Form.types.ts (following BMAD TypeScript)
- src/components/Form/Form.hooks.ts (following BMAD patterns)
- src/components/Form/Form.test.tsx (following BMAD testing)

[AUTO-CREATED] bmad_mem_006: PATTERN
CONTENT: BMAD Form component pattern with validation hooks and TypeScript interfaces
IMPORTANCE: 0.8
TAGS: bmad, methodology, form, validation, hooks, typescript

BMAD + Cursor Chat

User: "Explain this code in context of our BMAD methodology"

Cursor AI: "/bmad-recall 'methodology'

Analyzing code against established BMAD patterns:

This code follows several BMAD principles:
1. Component composition (bmad_mem_002) 
2. TypeScript strict typing (bmad_mem_001) 
3. Variant-based design (bmad_mem_003) 

The implementation aligns with our BMAD methodology by:
- Using composition over inheritance
- Maintaining type safety
- Following established patterns

This is a good example of BMAD methodology in practice.

BMAD Best Practices for Cursor AI

1. Initialize BMAD Memory Early

Set up .bmad-memory/ structure at project start

2. Use Descriptive BMAD Memory Content

Include context about why decisions were made

3. Tag BMAD Memories Consistently

Use standard tags: bmad, methodology, component, pattern, etc.

4. Leverage Workspace Integration

Let Cursor AI analyze your codebase for BMAD patterns

5. Create BMAD Templates

Build reusable templates from established BMAD patterns

6. Share BMAD Memories with Team

Commit .bmad-memory/ to version control

7. Regular BMAD Memory Maintenance

Clean up old memories and update patterns

Troubleshooting BMAD Memory in Cursor AI

Issue: BMAD Memory Files Not Created

Solution:

# Check permissions
chmod -R 755 .bmad-memory/

# Verify structure
ls -la .bmad-memory/storage/

# Recreate if needed
mkdir -p .bmad-memory/{storage/{working,decision,solution,learning,pattern,semantic},config,logs,exports}

Issue: BMAD Commands Not Working

Solution: Update .cursor/instructions.md with explicit BMAD command handling:

You MUST respond to these exact BMAD commands:
- /bmad-remember [content] [type] [importance]
- /bmad-recall [query]
- /bmad-memories
- /bmad-status
- /bmad-workspace

Always check .bmad-memory/ folder for existing BMAD memories before responding.

Issue: BMAD Memories Not Persisting

Solution:

/bmad-debug

Expected Response:
BMAD DEBUG INFORMATION:
- Memory folder: .bmad-memory/ 
- Write permissions: 
- Memory index: .bmad-memory/memory-index.json 
- Last write: 2024-01-15T10:30:00Z 

All BMAD memory systems operational.

This implementation guide provides complete BMAD Method Memory Enhancement integration with Cursor AI, enabling persistent, intelligent memory across your development workflow!