An interactive web application for exploring and learning Gang of Four design patterns through live code examples and detailed explanations.
Deployment URL: https://design-pattern-visualizer.pages.dev
-
14 Design Patterns - Complete coverage of essential Gang of Four patterns
- 5 Creational Patterns
- 5 Structural Patterns
- 4 Behavioral Patterns
-
Interactive Code Editor - Edit and run TypeScript code directly in your browser
- Powered by CodeMirror 6
- Syntax highlighting
- Real-time code execution
- Console output capture
-
Comprehensive Documentation - Each pattern includes:
- Intent and motivation
- Structure and participants
- Pros and cons
- Implementation tips
- Real-world use cases
- Interactive code examples
-
Modern Design - Clean, professional interface
- Dark/Light theme toggle
- Responsive layout
- Smooth animations
- Accessible (WCAG 2.1 AA)
- Next.js 15 - React framework with App Router and Server Components
- React 19 - UI library
- TypeScript - Type safety and better DX
- Tailwind CSS - Utility-first CSS framework
- CodeMirror 6 - Modern code editor
- @codemirror/lang-javascript - JavaScript/TypeScript language support
- next-themes - Zero-flash dark mode with localStorage persistence
- Lucide React - Beautiful icon library
- clsx + tailwind-merge - Utility class management
- Node.js 18+ and npm
- Clone the repository:
git clone https://github.com/yourusername/design-pattern-visualizer.git
cd design-pattern-visualizer- Install dependencies:
npm install- Run the development server:
npm run dev- Open http://localhost:3000 in your browser
npm run build
npm startRun tests with Vitest:
# Run tests
npm test
# Run tests with UI
npm run test:ui
# Run tests with coverage
npm run test:coverageRun E2E tests with Playwright:
# Install Playwright browsers (first time only)
npx playwright install
# Run E2E tests
npm run test:e2e
# Run E2E tests with UI
npm run test:e2e:uiThe project includes:
- Unit tests for utility functions
- Component tests for UI components
- Integration tests for pattern data
- E2E tests for user flows
- Singleton - Ensures a class has only one instance
- Factory Method - Defines an interface for creating objects
- Builder - Separates object construction from representation
- Abstract Factory - Creates families of related objects
- Prototype - Creates objects by cloning prototypes
- Decorator - Attaches additional responsibilities dynamically
- Adapter - Converts one interface to another
- Composite - Composes objects into tree structures
- Facade - Provides a unified interface to a subsystem
- Proxy - Provides a surrogate for another object
- Observer - Defines one-to-many dependencies between objects
- Strategy - Defines a family of interchangeable algorithms
- Command - Encapsulates requests as objects
- State - Alters behavior when internal state changes
design-pattern-visualizer/
├── app/ # Next.js app directory
│ ├── layout.tsx # Root layout with theme provider
│ ├── page.tsx # Home page
│ ├── patterns/ # Pattern pages
│ └── globals.css # Global styles
├── components/ # React components
│ ├── ui/ # Reusable UI components
│ ├── layout/ # Layout components
│ ├── pattern/ # Pattern-specific components
│ └── code/ # Code editor components
├── lib/ # Utility libraries
│ ├── patterns/ # Pattern data and definitions
│ └── utils.ts # Utility functions
├── types/ # TypeScript type definitions
└── public/ # Static assets
Light Mode:
- Background: Warm gray (#FAFAF9)
- Foreground: Deep charcoal (#18181B)
- Primary: Teal (#0D9488)
- Secondary: Amber (#F59E0B)
- Accent: Purple (#7C3AED)
Dark Mode:
- Background: Rich dark (#0F0F12)
- Foreground: Soft white (#F5F5F6)
- Primary: Bright teal (#14B8A6)
- Secondary: Gold (#FCD34D)
- Accent: Vivid purple (#A78BFA)
- Font Family: Inter (headings and body)
- Code Font: JetBrains Mono
- Clear hierarchy with meaningful size scales
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Design patterns from "Design Patterns: Elements of Reusable Object-Oriented Software" by the Gang of Four
- Built with modern web technologies and best practices
- Inspired by the need for interactive learning resources
This application has been security audited. Key security features:
- ✅ Content Security Policy (CSP) headers
- ✅ Code execution sandbox with timeout
- ✅ Input sanitization for console output
- ✅ Rate limiting for code execution
- ✅ Security headers (X-Frame-Options, X-Content-Type-Options, etc.)
- ✅ No user data collection or tracking
See SECURITY.md for the full security review.
The application is configured for deployment to Cloudflare Pages.
- Push your code to GitHub
- Connect repository to Cloudflare Pages
- Configure build settings:
- Build command:
npm run build - Build directory:
out
- Build command:
- Deploy!
See DEPLOYMENT.md for detailed deployment instructions.
The app is configured for static export:
npm run build # Creates 'out' directory with static files- Add more patterns (Template Method, Iterator, Mediator, etc.)
- Add pattern comparison feature
- Add pattern search and filtering
- Add code sharing functionality
- Add more interactive visualizations
- Add WebAssembly sandbox for safer code execution
- Add performance monitoring
- Add SEO optimizations
If you find this project helpful, please consider giving it a star on GitHub!