| name | sdd-implement |
| description | Implementation guidelines for SDD workflow. Use when implementing features, applying TDD, checking security, or ensuring code quality. Invoked via /sdd-implement <feature-name>. Use when this capability is needed. |
| metadata | {"author":"yi-john-huang"} |
SDD Implementation Guidelines
Execute implementation following TDD methodology, SOLID principles, and security best practices.
Prerequisites
Before implementing:
- Tasks must be approved (use
sdd-status to verify)
- Review tasks in
.spec/specs/{feature}/tasks.md
- Understand the design in
.spec/specs/{feature}/design.md
Implementation Workflow
Step 1: Load Context
- Use
sdd-status MCP tool to verify all phases approved
- Read the tasks document for current implementation
- Identify the next task to implement
Step 2: Execute TDD Cycle
For each task:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 1. RED: Write Failing Test ā
ā - Define expected behavior ā
ā - Run test, confirm it FAILS ā
ā ā
ā 2. GREEN: Write Minimal Code ā
ā - Just enough to pass the test ā
ā - No extra features ā
ā - Run test, confirm it PASSES ā
ā ā
ā 3. REFACTOR: Improve Code ā
ā - Clean up without changing behavior ā
ā - Run tests, confirm still PASSING ā
ā ā
ā REPEAT for each test case ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Step 3: Apply SOLID Principles
S - Single Responsibility Principle
class UserValidator {
validate(user: User): ValidationResult { ... }
}
class UserRepository {
save(user: User): Promise<void> { ... }
}
class UserManager {
validate(user: User) { ... }
save(user: User) { ... }
sendEmail(user: User) { ... }
generateReport() { ... }
}
O - Open/Closed Principle
interface PaymentProcessor {
process(amount: number): Promise<Result>;
}
class StripeProcessor implements PaymentProcessor { ... }
class PayPalProcessor implements PaymentProcessor { ... }
class PaymentService {
process(type: string, amount: number) {
if (type === 'stripe') { ... }
else if (type === 'paypal') { ... }
}
}
L - Liskov Substitution Principle
class Bird {
move(): void { }
}
class Sparrow extends Bird {
move(): void { this.fly(); }
}
class Penguin extends Bird {
move(): void { this.walk(); }
}
class Bird {
fly(): void { ... }
}
class Penguin extends Bird {
fly(): void { throw new Error("Can't fly!"); }
}
I - Interface Segregation Principle
interface Readable {
read(): Data;
}
interface Writable {
write(data: Data): void;
}
class FileHandler implements Readable, Writable { ... }
class ReadOnlyFile implements Readable { ... }
interface FileOperations {
read(): Data;
write(data: Data): void;
delete(): void;
execute(): void;
}
D - Dependency Inversion Principle
interface IUserRepository {
findById(id: string): Promise<User>;
}
class UserService {
constructor(private repo: IUserRepository) {}
}
class UserService {
private repo = new PostgresUserRepository();
}
Step 4: Security Checklist (OWASP Top 10)
Before marking implementation complete, verify:
1. Broken Access Control
2. Cryptographic Failures
3. Injection
4. Insecure Design
5. Security Misconfiguration
6. Vulnerable Components
7. Authentication Failures
8. Software Integrity
9. Logging & Monitoring
10. SSRF (Server-Side Request Forgery)
Step 5: Code Quality Standards
Naming
const userEmail = user.email;
function calculateTotalPrice(items: Item[]): number { ... }
const e = user.email;
function calc(i: any): any { ... }
Comments
const result = await retryWithBackoff(fetchData);
const user = getUser(id);
Error Handling
class UserNotFoundError extends Error {
constructor(userId: string) {
super(`User with ID ${userId} not found`);
this.name = 'UserNotFoundError';
}
}
throw new Error('Error');
Step 6: Update Task Status
After implementing each task:
- Mark task as complete in tasks.md
- Verify test coverage >= 80%
- Run
sdd-quality-check MCP tool on new code
MCP Tool Integration
| Tool | When to Use |
|---|
sdd-status | Check all phases approved before implementing |
sdd-spec-impl | Execute specific tasks with TDD |
sdd-quality-check | Validate code quality after implementation |
Definition of Done
Steering Document References
Apply these steering documents during implementation:
| Document | Purpose | Key Application |
|---|
.spec/steering/tdd-guideline.md | Test-Driven Development | Follow Red-Green-Refactor cycle for all code |
.spec/steering/principles.md | SOLID, DRY, KISS, YAGNI | Apply SOLID principles, keep code simple and focused |
.spec/steering/owasp-top10-check.md | Security checklist | Verify all OWASP Top 10 security requirements before completion |
Critical Implementation Rules:
- TDD First: Never write production code without a failing test
- SOLID Always: Apply all five principles (SRP, OCP, LSP, ISP, DIP)
- Security Required: Complete OWASP checklist before marking done
Common Anti-Patterns to Avoid
| Anti-Pattern | Problem | Solution |
|---|
| God Class | Class does too much | Split by responsibility |
| Feature Envy | Method uses another class's data extensively | Move method to that class |
| Primitive Obsession | Using primitives for domain concepts | Create value objects |
| Magic Numbers | Unexplained numeric literals | Use named constants |
| Deep Nesting | Multiple levels of if/loops | Extract methods, early returns |
| Long Methods | Methods doing too much | Split into smaller methods |
Converted and distributed by TomeVault ā claim your Tome and manage your conversions.