You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This task implements a comprehensive refactoring exercise (11.2.5) that synthesizes Repository Pattern, Service Layer, and Strategy Pattern. Students refactor a TypeScript e-commerce order processing system with intentional anti-patterns into clean, SOLID-compliant architecture.
Complete exercise documentation with phase-by-phase instructions
📋 Specification Context
Project Overview
This specification defines the remaining Design Patterns subsections for Chapter 11 (Application Development) of the DevOps Bootcamp. Task 4.0 is the capstone exercise that synthesizes learning from Data Layer Patterns (11.2.2), Business Logic Patterns (11.2.3), Classical GoF Patterns (11.2.4), and SOLID Principles (11.2.1).
User Story
US-5: Applying Multiple Patterns in Realistic Refactoring
As a bootcamp apprentice learning design patterns, I want to refactor a poorly-structured application using Repository, Service Layer, and Strategy patterns so that I can understand how patterns work together to solve real architectural problems.
US-5.1: Identifying Anti-Patterns
As a developer learning SOLID principles, I want guidance on identifying code smells and violations so that I can recognize similar issues in production codebases.
US-5.2: Preserving Behavior Through Refactoring
As a developer refactoring legacy code, I want comprehensive tests that validate behavior so that I can safely restructure code without breaking functionality.
Functional Requirements
ID
Requirement
U5-FR1
The system shall provide starter application code with deliberately introduced design issues including: God Object pattern, if/else chains for payment/shipping, direct database queries, and SOLID violations (SRP, OCP, DIP)
U5-FR2
The application shall implement e-commerce order processing domain with realistic entities: Order, OrderItem, Product, Customer, Payment (CreditCard/PayPal/Bitcoin), Shipping (Standard/Express/Overnight), and Inventory
U5-FR3
The system shall include comprehensive automated tests using Jest and Supertest that validate business behavior and must pass before and after refactoring without modification
U5-FR4
The system shall provide analysis guide (analysis-guide.md) helping students identify specific anti-patterns with line numbers, metrics collection, SOLID violations, and phase-by-phase refactoring roadmap
U5-FR5
The system shall include instructions for students to create refactoring plan specifying interfaces to define, patterns to apply, and implementation order
U5-FR6
The system shall guide students to apply Strategy Pattern for payment/shipping (eliminates if/else chains), Repository Pattern for data access (abstracts SQLite), and Service Layer for business logic (separates from HTTP)
U5-FR7
The system shall include git workflow guidelines with commit message templates documenting refactoring decisions and pattern applications
U5-FR8
The system shall provide reference solution showing refactored implementation with Strategy interfaces, Repository interfaces, Service classes, and thin HTTP layer
U5-FR9
The exercise shall be self-directed with students working in starter/ directory and comparing to solution/ directory
U5-FR10
The implementation shall document research decision to build custom application (vs. adapting OSS project) based on pedagogical control, licensing freedom, and integration with bootcamp conventions
✅ Acceptance Criteria (Proof Artifacts)
The following artifacts must exist and be verified for task completion:
Documentation:docs/11-application-development/11.2.5-refactoring-exercise.md exists with complete instructions including front-matter, 5-phase structure (Analysis/Planning/Implementation/Verification/Comparison), setup steps, success criteria, and reflection questions
Research Notes:examples/ch11/refactoring-exercise/research-notes.md documents OSS project evaluation and justification for building custom application
Starter Application:examples/ch11/refactoring-exercise/starter/ contains TypeScript application with package.json, tsconfig.json, jest.config.js, src/routes.ts (450-line God Object), database.ts, types.ts, and schema.sql
Behavior-Based Tests:examples/ch11/refactoring-exercise/starter/tests/ contains order-creation.test.ts, payment.test.ts, inventory.test.ts that validate business outcomes (not implementation)
Starter README:examples/ch11/refactoring-exercise/starter/README.md includes setup instructions, npm commands, testing steps, and Your Task section
Analysis Guide:examples/ch11/refactoring-exercise/analysis-guide.md includes metrics collection, SOLID violation checklist with line numbers, code smell identification, testability assessment, and refactoring roadmap
Solution Application:examples/ch11/refactoring-exercise/solution/ contains refactored implementation with strategies/payment/, strategies/shipping/, repositories/, services/, routes/, and factories/
4.1 Research open-source e-commerce TypeScript/Node.js applications evaluating 3-5 candidates using scoring rubric: Technical Fit (40pts: TypeScript native, clear anti-patterns, 500-2000 LOC, testable), Educational Fit (30pts: readable, real-world scenarios, clear refactoring opportunities), Practical (30pts: permissive license, minimal dependencies, maintained)
4.2 Create examples/ch11/refactoring-exercise/research-notes.md documenting evaluated projects with GitHub URLs, anti-patterns identified, scoring, and final decision rationale (recommended: build custom application for pedagogical control, licensing freedom, and bootcamp integration)
Starter Application Tasks
4.3 Create starter application structure in examples/ch11/refactoring-exercise/starter/ with package.json (express, sqlite3, typescript, jest, supertest, ts-jest dependencies), tsconfig.json (strict mode), jest.config.js (ts-jest preset), schema.sql (products, customers, orders, order_items tables with seed data)
4.4 Create starter/src/ with index.ts (Express server setup), routes.ts (450-line God Object with all business logic), database.ts (SQLite connection), types.ts (Product, Customer, Order, OrderItem, CreateOrderRequest interfaces)
4.5 Implement anti-patterns in routes.ts: POST /orders handler with direct validation (lines 15-25), direct SQLite db.run() calls (lines 30-110), if/else chains for payment types - credit_card (3% fee), paypal (3.5% fee), bitcoin ($1.50 flat fee) (lines 50-70), if/else chains for shipping methods - standard ($5.99, 7 days), express ($12.99, 3 days), overnight ($24.99, 1 day) (lines 75-90), inventory decrement logic mixed with order creation (lines 95-110)
4.6 Create behavior-based test suite in starter/tests/ with order-creation.test.ts (POST /orders with valid data, total calculation verification, validation error cases), payment.test.ts (credit card 3% fee test, PayPal 3.5% fee test, Bitcoin $1.50 flat fee test, invalid payment type rejection), inventory.test.ts (insufficient stock rejection, stock decrement after order, multiple items in single order)
4.7 Create starter/README.md with sections: Overview (e-commerce order processing with intentional anti-patterns), Setup (npm install, npm run db:init, npm run dev), Running Tests (npm test), Testing API (curl example for POST /orders), Your Task (reference analysis-guide.md, follow refactoring roadmap), Success Criteria (tests pass, routes.ts <50 lines, can add Apple Pay with one file, can test without database)
4.8 Create analysis-guide.md with Step 1: Initial Assessment (metrics collection commands for LOC/function count, architecture diagram exercise), Step 2: SOLID Principle Violations (SRP checklist for routes.ts with 7+ reasons to change, OCP exercise for adding Apple Pay requiring modification, DIP assessment showing sqlite3.Database concrete dependency), Step 3: Code Smells (God Object checklist, if/else type checking locations, missing abstraction layers), Step 4: Testability Analysis (requirements for testing with Express server and SQLite), Step 5: Refactoring Roadmap (Phase 1: Interfaces, Phase 2: Strategies, Phase 3: Repositories, Phase 4: Service Layer, Phase 5: Simplify Routes), Step 6: Verification (after refactoring checklist with success metrics)
4.10 Create Repository Pattern implementation in solution/src/repositories/ with IOrderRepository.ts (create, findById, addItems, updateStatus methods), OrderRepository.ts (SQLite implementation with Database injection), IProductRepository.ts (findById, updateStock, checkStock methods), ProductRepository.ts (SQLite implementation)
4.11 Create Service Layer in solution/src/services/ with ValidationService.ts (validateOrderRequest with business rule checks), InventoryService.ts (checkAvailability, decrementStock using ProductRepository), OrderService.ts (createOrder orchestrating validation, inventory, payment strategy, shipping strategy, repository operations)
4.12 Create Factory Pattern in solution/src/factories/ with PaymentStrategyFactory.ts (getStrategy method returning IPaymentStrategy, registerStrategy for extension), ShippingStrategyFactory.ts (getStrategy method returning IShippingStrategy)
4.13 Create thin HTTP layer in solution/src/routes/orderRoutes.ts (20-line file with single POST /orders handler that parses request, calls orderService.createOrder(), formats response, handles errors)
4.14 Create dependency injection wiring in solution/src/index.ts (instantiate Database, create repositories with db injection, create factories, create services with dependency injection, create routes with service injection, wire to Express app)
4.15 Copy test suite from starter to solution solution/tests/ (SAME test files: order-creation.test.ts, payment.test.ts, inventory.test.ts with NO modifications demonstrating behavior preservation)
4.16 Create solution/README.md with Architecture Overview (before: routes.ts → SQLite, after: routes → OrderService → Repositories/Strategies), Pattern Applications (Strategy Pattern: eliminates if/else chains, shows OCP with Apple Pay extension, Repository Pattern: abstracts data access, shows DIP with PostgreSQL swap example, Service Layer: separates concerns, shows SRP with testability), Before/After Metrics (routes.ts: 450 lines → 20 lines, largest function: 100 lines → <30 lines, files: 4 → 20+, to add Apple Pay: modify 3 files → create 1 file)
4.18 Write exercise documentation with Overview (synthesis of 11.2.2-11.2.4 patterns), Learning Objectives (identify SOLID violations, apply Repository/Service Layer/Strategy patterns, verify behavior preservation, measure refactoring success), Prerequisites (links to 11.2.1-11.2.4), Domain Description (e-commerce order processing features and starter architecture diagram)
4.19 Write Phase 1: Code Analysis section (Task 1.1: Complete analysis-guide.md with metrics and line numbers, Task 1.2: Draw architecture diagram showing dependencies, Task 1.3: Document changes required to add Apple Pay)
4.20 Write Phase 2: Planning Your Refactoring section (Task 2.1: Define interfaces for IPaymentStrategy, IShippingStrategy, IOrderRepository, IProductRepository, Task 2.2: Plan refactoring order with rationale, Task 2.3: Set up directory structure with mkdir commands)
4.21 Write Phase 3: Implementation section (Task 3.1-3.6: Step-by-step implementation of Strategy Pattern for payments/shipping, Repository Pattern for data access, Service Layer for business logic, thin routes, and dependency injection wiring with test-your-progress checkpoints)
4.22 Write Phase 4: Verification section (Task 4.1: Run tests and verify behavior preserved, Task 4.2: Compare before/after metrics, Task 4.3: Extension Test for adding Apple Pay, Task 4.4: Testability Assessment with unit test challenge)
4.24 Add Git Workflow section (recommended commit strategy: 8 commits from initial to final, commit message guidelines with refactor: prefix, SOLID principles applied, patterns introduced, benefits, tests status)
4.25 Add Success Criteria checklist (tests pass, routes.ts <50 lines, can add Apple Pay with one file, can test OrderService without database, no if/else chains, business logic separated from data access and HTTP)
4.26 Add Reflection Questions section (5 questions: before vs after improvements, complexity trade-offs justification, real-world applications, pattern selection guidance, testing impact)
4.27 Add Additional Challenges section (Challenge 1: Add Apple Pay with 4% fee, Challenge 2: Add discount strategy system, Challenge 3: Swap to PostgreSQL by creating PostgresOrderRepository, Challenge 4: Add API versioning /api/v2/orders reusing OrderService)
4.28 Verify starter application: Run cd examples/ch11/refactoring-exercise/starter && npm install && npm test confirming all tests pass with exit code 0 demonstrating baseline functionality
4.29 Verify solution application: Run cd examples/ch11/refactoring-exercise/solution && npm install && npm test confirming all tests pass with same test files demonstrating behavior preservation and successful refactoring
4.30 Verify extension scenario: Create solution/src/strategies/payment/ApplePayPayment.ts implementing IPaymentStrategy with 4% fee, register in PaymentStrategyFactory, run tests confirming zero modifications to existing files required demonstrating Open/Closed Principle
📁 Relevant Files
Files to Create
Research & Analysis
examples/ch11/refactoring-exercise/research-notes.md - OSS project evaluation and custom build decision rationale
examples/ch11/refactoring-exercise/analysis-guide.md - Structured guide for identifying anti-patterns and SOLID violations with refactoring roadmap
Starter Application
examples/ch11/refactoring-exercise/starter/package.json - Node.js dependencies and scripts
Front-Matter: Include YAML metadata with category: Software Development, estReadingMinutes: 20, exercises with 180-minute estimate and TypeScript/Design Patterns technologies
Technologies: Use TypeScript, Design Patterns, SQLite as technology tags
Header Levels: Use H2 (##) for phase navigation (Phase 1: Analysis, Phase 2: Planning, etc.), H3 (###) for tasks within phases
Code Examples: Use fenced code blocks with typescript/bash language tags, show before/after comparisons where appropriate
Cross-References: Link to 11.2.1 (SOLID Principles), 11.2.2 (Repository Pattern), 11.2.3 (Service Layer), 11.2.4 (Strategy Pattern)
Exercise Structure: Use task-based structure (Task 1.1, Task 1.2) with clear deliverables and checkpoints
Testing Standards
Behavior-Based Testing: Tests must validate business outcomes, not implementation details
Test Preservation: Exact same test files must work with both starter and solution demonstrating behavior preservation
Test Organization: Group by feature (order-creation.test.ts, payment.test.ts, inventory.test.ts), not by pattern
Setup/Teardown: Use beforeEach to reset SQLite database ensuring test isolation
Pattern Application Standards
Strategy Pattern: Must have interface (IPaymentStrategy, IShippingStrategy), 3+ concrete implementations, Factory for creation, demonstrate extension without modification (Apple Pay test)
Repository Pattern: Must have interface (IOrderRepository, IProductRepository), SQLite implementation with database injection, demonstrate swappability in README
Service Layer: Must orchestrate domain logic, use dependency injection for repositories/strategies, separate from HTTP concerns, demonstrate testability without Express
Thin HTTP Layer: Routes must be <30 lines per handler, only handle request/response, delegate all logic to services
🔗 Related Documentation
Full Spec:docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.md
Copy the content from this file (starting from "## 🎯 Task Overview")
Paste into the issue body
Set title: "Task 4.0: Integrated Refactoring Exercise (11.2.5)"
Add labels: documentation, enhancement
📊 Research Decision Summary
OSS Project Evaluation
Evaluated approach: Research TypeScript/Node.js e-commerce projects on GitHub using search queries targeting MERN/MEAN tutorials, Express API examples, and course repositories with anti-patterns.
Reproducible and Maintainable: Can create progressive difficulty versions and update as patterns evolve
Alternative Considered: Adapting OSS MERN/MEAN e-commerce tutorials with monolithic structure Rejected Because: Would require extensive modification (~8 hours) to introduce specific anti-patterns, unclear licensing for educational adaptation, inconsistent with bootcamp quality standards
GitHub Search Strategy Documented: research-notes.md includes comprehensive GitHub search queries and evaluation rubric for future reference if OSS alternative becomes viable
GitHub Issue: Task 4.0 - Integrated Refactoring Exercise (11.2.5)
🎯 Task Overview
Task ID: 4.0
Parent Spec:
docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.mdStatus: Ready for Implementation
Estimated Time: 8-12 hours
This task implements a comprehensive refactoring exercise (11.2.5) that synthesizes Repository Pattern, Service Layer, and Strategy Pattern. Students refactor a TypeScript e-commerce order processing system with intentional anti-patterns into clean, SOLID-compliant architecture.
Key Deliverables:
📋 Specification Context
Project Overview
This specification defines the remaining Design Patterns subsections for Chapter 11 (Application Development) of the DevOps Bootcamp. Task 4.0 is the capstone exercise that synthesizes learning from Data Layer Patterns (11.2.2), Business Logic Patterns (11.2.3), Classical GoF Patterns (11.2.4), and SOLID Principles (11.2.1).
User Story
US-5: Applying Multiple Patterns in Realistic Refactoring
As a bootcamp apprentice learning design patterns, I want to refactor a poorly-structured application using Repository, Service Layer, and Strategy patterns so that I can understand how patterns work together to solve real architectural problems.
US-5.1: Identifying Anti-Patterns
As a developer learning SOLID principles, I want guidance on identifying code smells and violations so that I can recognize similar issues in production codebases.
US-5.2: Preserving Behavior Through Refactoring
As a developer refactoring legacy code, I want comprehensive tests that validate behavior so that I can safely restructure code without breaking functionality.
Functional Requirements
✅ Acceptance Criteria (Proof Artifacts)
The following artifacts must exist and be verified for task completion:
docs/11-application-development/11.2.5-refactoring-exercise.mdexists with complete instructions including front-matter, 5-phase structure (Analysis/Planning/Implementation/Verification/Comparison), setup steps, success criteria, and reflection questionsexamples/ch11/refactoring-exercise/research-notes.mddocuments OSS project evaluation and justification for building custom applicationexamples/ch11/refactoring-exercise/starter/contains TypeScript application with package.json, tsconfig.json, jest.config.js, src/routes.ts (450-line God Object), database.ts, types.ts, and schema.sqlexamples/ch11/refactoring-exercise/starter/tests/contains order-creation.test.ts, payment.test.ts, inventory.test.ts that validate business outcomes (not implementation)examples/ch11/refactoring-exercise/starter/README.mdincludes setup instructions, npm commands, testing steps, and Your Task sectionexamples/ch11/refactoring-exercise/analysis-guide.mdincludes metrics collection, SOLID violation checklist with line numbers, code smell identification, testability assessment, and refactoring roadmapexamples/ch11/refactoring-exercise/solution/contains refactored implementation with strategies/payment/, strategies/shipping/, repositories/, services/, routes/, and factories/examples/ch11/refactoring-exercise/solution/README.mdexplains architecture changes, pattern applications (Strategy/Repository/Service Layer), and before/after comparisonscd starter && npm testpasses all tests demonstrating baseline functionalitycd solution && npm testpasses all tests with same test files demonstrating behavior preservation📝 Sub-tasks
Research and Decision Tasks
examples/ch11/refactoring-exercise/research-notes.mddocumenting evaluated projects with GitHub URLs, anti-patterns identified, scoring, and final decision rationale (recommended: build custom application for pedagogical control, licensing freedom, and bootcamp integration)Starter Application Tasks
examples/ch11/refactoring-exercise/starter/with package.json (express, sqlite3, typescript, jest, supertest, ts-jest dependencies), tsconfig.json (strict mode), jest.config.js (ts-jest preset), schema.sql (products, customers, orders, order_items tables with seed data)starter/src/with index.ts (Express server setup), routes.ts (450-line God Object with all business logic), database.ts (SQLite connection), types.ts (Product, Customer, Order, OrderItem, CreateOrderRequest interfaces)routes.ts: POST /orders handler with direct validation (lines 15-25), direct SQLite db.run() calls (lines 30-110), if/else chains for payment types - credit_card (3% fee), paypal (3.5% fee), bitcoin ($1.50 flat fee) (lines 50-70), if/else chains for shipping methods - standard ($5.99, 7 days), express ($12.99, 3 days), overnight ($24.99, 1 day) (lines 75-90), inventory decrement logic mixed with order creation (lines 95-110)starter/tests/with order-creation.test.ts (POST /orders with valid data, total calculation verification, validation error cases), payment.test.ts (credit card 3% fee test, PayPal 3.5% fee test, Bitcoin $1.50 flat fee test, invalid payment type rejection), inventory.test.ts (insufficient stock rejection, stock decrement after order, multiple items in single order)starter/README.mdwith sections: Overview (e-commerce order processing with intentional anti-patterns), Setup (npm install, npm run db:init, npm run dev), Running Tests (npm test), Testing API (curl example for POST /orders), Your Task (reference analysis-guide.md, follow refactoring roadmap), Success Criteria (tests pass, routes.ts <50 lines, can add Apple Pay with one file, can test without database)analysis-guide.mdwith Step 1: Initial Assessment (metrics collection commands for LOC/function count, architecture diagram exercise), Step 2: SOLID Principle Violations (SRP checklist for routes.ts with 7+ reasons to change, OCP exercise for adding Apple Pay requiring modification, DIP assessment showing sqlite3.Database concrete dependency), Step 3: Code Smells (God Object checklist, if/else type checking locations, missing abstraction layers), Step 4: Testability Analysis (requirements for testing with Express server and SQLite), Step 5: Refactoring Roadmap (Phase 1: Interfaces, Phase 2: Strategies, Phase 3: Repositories, Phase 4: Service Layer, Phase 5: Simplify Routes), Step 6: Verification (after refactoring checklist with success metrics)Reference Solution Tasks
examples/ch11/refactoring-exercise/solution/with src/strategies/payment/ (IPaymentStrategy.ts interface, CreditCardPayment.ts, PayPalPayment.ts, BitcoinPayment.ts implementations), src/strategies/shipping/ (IShippingStrategy.ts interface, StandardShipping.ts, ExpressShipping.ts, OvernightShipping.ts implementations)solution/src/repositories/with IOrderRepository.ts (create, findById, addItems, updateStatus methods), OrderRepository.ts (SQLite implementation with Database injection), IProductRepository.ts (findById, updateStock, checkStock methods), ProductRepository.ts (SQLite implementation)solution/src/services/with ValidationService.ts (validateOrderRequest with business rule checks), InventoryService.ts (checkAvailability, decrementStock using ProductRepository), OrderService.ts (createOrder orchestrating validation, inventory, payment strategy, shipping strategy, repository operations)solution/src/factories/with PaymentStrategyFactory.ts (getStrategy method returning IPaymentStrategy, registerStrategy for extension), ShippingStrategyFactory.ts (getStrategy method returning IShippingStrategy)solution/src/routes/orderRoutes.ts(20-line file with single POST /orders handler that parses request, calls orderService.createOrder(), formats response, handles errors)solution/src/index.ts(instantiate Database, create repositories with db injection, create factories, create services with dependency injection, create routes with service injection, wire to Express app)solution/tests/(SAME test files: order-creation.test.ts, payment.test.ts, inventory.test.ts with NO modifications demonstrating behavior preservation)solution/README.mdwith Architecture Overview (before: routes.ts → SQLite, after: routes → OrderService → Repositories/Strategies), Pattern Applications (Strategy Pattern: eliminates if/else chains, shows OCP with Apple Pay extension, Repository Pattern: abstracts data access, shows DIP with PostgreSQL swap example, Service Layer: separates concerns, shows SRP with testability), Before/After Metrics (routes.ts: 450 lines → 20 lines, largest function: 100 lines → <30 lines, files: 4 → 20+, to add Apple Pay: modify 3 files → create 1 file)Documentation and Verification Tasks
docs/11-application-development/11.2.5-refactoring-exercise.mdwith front-matter (category: Software Development, estReadingMinutes: 20, exercises: [{name: Integrated Refactoring Exercise, description: Refactor e-commerce application using patterns, estMinutes: 180, technologies: [TypeScript, Design Patterns]}])cd examples/ch11/refactoring-exercise/starter && npm install && npm testconfirming all tests pass with exit code 0 demonstrating baseline functionalitycd examples/ch11/refactoring-exercise/solution && npm install && npm testconfirming all tests pass with same test files demonstrating behavior preservation and successful refactoringsolution/src/strategies/payment/ApplePayPayment.tsimplementing IPaymentStrategy with 4% fee, register in PaymentStrategyFactory, run tests confirming zero modifications to existing files required demonstrating Open/Closed Principle📁 Relevant Files
Files to Create
Research & Analysis
examples/ch11/refactoring-exercise/research-notes.md- OSS project evaluation and custom build decision rationaleexamples/ch11/refactoring-exercise/analysis-guide.md- Structured guide for identifying anti-patterns and SOLID violations with refactoring roadmapStarter Application
examples/ch11/refactoring-exercise/starter/package.json- Node.js dependencies and scriptsexamples/ch11/refactoring-exercise/starter/tsconfig.json- TypeScript configuration (strict mode)examples/ch11/refactoring-exercise/starter/jest.config.js- Jest testing configurationexamples/ch11/refactoring-exercise/starter/schema.sql- SQLite database schema and seed dataexamples/ch11/refactoring-exercise/starter/README.md- Setup instructions and Your Task sectionexamples/ch11/refactoring-exercise/starter/src/index.ts- Express server setupexamples/ch11/refactoring-exercise/starter/src/routes.ts- God Object with all business logic (450 lines)examples/ch11/refactoring-exercise/starter/src/database.ts- SQLite connection setupexamples/ch11/refactoring-exercise/starter/src/types.ts- TypeScript interfacesexamples/ch11/refactoring-exercise/starter/tests/order-creation.test.ts- Order workflow testsexamples/ch11/refactoring-exercise/starter/tests/payment.test.ts- Payment processing testsexamples/ch11/refactoring-exercise/starter/tests/inventory.test.ts- Inventory management testsSolution Application - Strategies
examples/ch11/refactoring-exercise/solution/src/strategies/payment/IPaymentStrategy.ts- Payment strategy interfaceexamples/ch11/refactoring-exercise/solution/src/strategies/payment/CreditCardPayment.ts- Credit card implementation (3% fee)examples/ch11/refactoring-exercise/solution/src/strategies/payment/PayPalPayment.ts- PayPal implementation (3.5% fee)examples/ch11/refactoring-exercise/solution/src/strategies/payment/BitcoinPayment.ts- Bitcoin implementation ($1.50 flat fee)examples/ch11/refactoring-exercise/solution/src/strategies/shipping/IShippingStrategy.ts- Shipping strategy interfaceexamples/ch11/refactoring-exercise/solution/src/strategies/shipping/StandardShipping.ts- Standard shipping ($5.99, 7 days)examples/ch11/refactoring-exercise/solution/src/strategies/shipping/ExpressShipping.ts- Express shipping ($12.99, 3 days)examples/ch11/refactoring-exercise/solution/src/strategies/shipping/OvernightShipping.ts- Overnight shipping ($24.99, 1 day)Solution Application - Repositories
examples/ch11/refactoring-exercise/solution/src/repositories/IOrderRepository.ts- Order repository interfaceexamples/ch11/refactoring-exercise/solution/src/repositories/OrderRepository.ts- SQLite order repository implementationexamples/ch11/refactoring-exercise/solution/src/repositories/IProductRepository.ts- Product repository interfaceexamples/ch11/refactoring-exercise/solution/src/repositories/ProductRepository.ts- SQLite product repository implementationSolution Application - Services
examples/ch11/refactoring-exercise/solution/src/services/OrderService.ts- Business logic orchestrationexamples/ch11/refactoring-exercise/solution/src/services/ValidationService.ts- Input validationexamples/ch11/refactoring-exercise/solution/src/services/InventoryService.ts- Stock managementSolution Application - Factories & Infrastructure
examples/ch11/refactoring-exercise/solution/src/factories/PaymentStrategyFactory.ts- Creates payment strategiesexamples/ch11/refactoring-exercise/solution/src/factories/ShippingStrategyFactory.ts- Creates shipping strategiesexamples/ch11/refactoring-exercise/solution/src/routes/orderRoutes.ts- Thin HTTP layer (20 lines)examples/ch11/refactoring-exercise/solution/src/index.ts- Dependency injection wiringexamples/ch11/refactoring-exercise/solution/src/database.ts- SQLite connectionexamples/ch11/refactoring-exercise/solution/src/domain/types.ts- TypeScript interfacesexamples/ch11/refactoring-exercise/solution/package.json- Same dependencies as starterexamples/ch11/refactoring-exercise/solution/tsconfig.json- Same config as starterexamples/ch11/refactoring-exercise/solution/jest.config.js- Same config as starterexamples/ch11/refactoring-exercise/solution/schema.sql- Same schema as starterexamples/ch11/refactoring-exercise/solution/README.md- Architecture explanation and pattern applicationsexamples/ch11/refactoring-exercise/solution/tests/order-creation.test.ts- SAME tests as starterexamples/ch11/refactoring-exercise/solution/tests/payment.test.ts- SAME tests as starterexamples/ch11/refactoring-exercise/solution/tests/inventory.test.ts- SAME tests as starterDocumentation
docs/11-application-development/11.2.5-refactoring-exercise.md- Main exercise documentation with 5-phase structureFiles to Reference
docs/11-application-development/11.2.1-solid-principles.md- SOLID principles foundation (for cross-references)docs/11-application-development/11.2.2-data-layer-patterns.md- Repository Pattern coverage (Task 1.0)docs/11-application-development/11.2.3-business-logic-patterns.md- Service Layer Pattern coverage (Task 2.0)docs/11-application-development/11.2.4-classical-patterns.md- Strategy Pattern coverage (Task 3.0)examples/ch11/solid-exercises/exercise-1-srp/- Example of existing refactoring exercise structureexamples/ch11/example1/- Example of "before" monolithic structureexamples/ch11/example2/- Example of "after" layered structure🎓 Repository Standards
Code Example Standards
Documentation Standards
TypeScript,Design Patterns,SQLiteas technology tags##) for phase navigation (Phase 1: Analysis, Phase 2: Planning, etc.), H3 (###) for tasks within phasesTesting Standards
Pattern Application Standards
🔗 Related Documentation
docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.mddocs/specs/01-spec-design-patterns-section/01-tasks-design-patterns-section.mdCLAUDE.md(repository root)STYLE.md(repository root)🤖 AI Agent Instructions
Implementation Approach
Quality Checklist
cd starter && npm test→ exit 0cd solution && npm test→ exit 0Common Pitfalls to Avoid
Dependencies
Success Criteria
This task is complete when:
npm testpasses in both starter/ and solution/ directories📋 How to Create This Issue
Option 1: Using GitHub CLI (Recommended)
Option 2: Manual Creation
documentation,enhancement📊 Research Decision Summary
OSS Project Evaluation
Evaluated approach: Research TypeScript/Node.js e-commerce projects on GitHub using search queries targeting MERN/MEAN tutorials, Express API examples, and course repositories with anti-patterns.
Evaluation Criteria:
Decision: Build Custom Application
Rationale:
Alternative Considered: Adapting OSS MERN/MEAN e-commerce tutorials with monolithic structure
Rejected Because: Would require extensive modification (~8 hours) to introduce specific anti-patterns, unclear licensing for educational adaptation, inconsistent with bootcamp quality standards
GitHub Search Strategy Documented: research-notes.md includes comprehensive GitHub search queries and evaluation rubric for future reference if OSS alternative becomes viable