A collection of interactive examples demonstrating software design patterns implemented with React, TypeScript, and modern state management libraries.
Traffic Light State Machine - Interactive traffic light simulation using XState for managing complex state transitions.
- Location:
/traffic-light
- Features: Automatic cycling, manual controls, visual feedback
- Technologies: XState, React Hooks
src/
├── components/
│ └── LandingPage.tsx # Main landing page with example links
├── traffic-light/
│ ├── TrafficLight.tsx # Traffic light component
│ ├── TrafficLight.css # Traffic light specific styles
│ ├── TrafficLightPage.tsx # Page wrapper for traffic light example
│ └── trafficLightMachine.ts # XState machine definition
├── App.tsx # Main app with routing
├── App.css # Global styles (landing page, navigation)
└── main.tsx # Application entry point
- React 19 - UI framework
- TypeScript - Type safety
- XState - State machine library
- React Router - Client-side routing
- Vite - Build tool and dev server
- pnpm - Package manager
- Node.js (version 20.19+ or 22.12+)
- pnpm
# Install dependencies
pnpm install
# Start development server
pnpm dev
# Build for production
pnpm build
# Preview production build
pnpm preview
# Run linting
pnpm lint
The application will be available at http://localhost:5173/
To add a new design pattern example:
- Create a new folder under
src/
(e.g.,src/observer-pattern/
) - Create your components and logic files
- Create a page component (e.g.,
ObserverPatternPage.tsx
) - Add a route in
App.tsx
- Add a card to the landing page in
LandingPage.tsx
This project serves as a learning resource for design patterns in React. Feel free to contribute additional examples or improvements!