A modern, production-ready Minesweeper implementation built with Domain-Driven Design, Clean Architecture, and SOLID principles. This project demonstrates enterprise-level JavaScript development practices using vanilla ES2023+ features.
๐ฎ Live Demo
- ๐ฏ Classic Minesweeper Gameplay - Traditional mine detection game with cascade reveal
- ๐จ Modern UI/UX - Clean, responsive design with theme switching
- โก High Performance - Optimized rendering with strategy patterns
- ๐๏ธ Clean Architecture - DDD with proper layer separation
- ๐ Type Safety - Comprehensive runtime type validation
- ๐ช Multiple Difficulties - Beginner, Intermediate, Expert levels (auto-loads beginner)
- ๐ฑ Responsive Design - Works on desktop and mobile devices
- ๐ Theme Support - Light and dark mode toggle
- โฑ๏ธ Smart Timer - Starts counting only on first cell click
- ๐ฉ Advanced Flagging - Counter can go negative, wrong flags highlighted on game over
- โ Error Visualization - Incorrectly flagged cells shown with red cross after game loss
- โ๏ธ Extensible - Easy to add new features and customizations
This project showcases modern JavaScript architecture following industry best practices:
๐ domain/
โโโ entities/ # Rich domain models (Board, Cell)
โโโ value-objects/ # Immutable data structures (Position, GameConfiguration)
โโโ services/ # Domain logic (GameRules, CellInteractionService)
๐ application/ # Use cases (MinesweeperGameService)
๐ infrastructure/ # Cross-cutting concerns (DI, Events, Timer, GameOverService)
๐ presentation/ # UI layer (Renderers, Strategies)
๐ common/ # Shared utilities (Result, TypeGuards, EventBus)
- ๐ฏ Result Pattern - Functional error handling without exceptions
- ๐ญ Strategy Pattern - Extensible cell rendering strategies
- ๐ Dependency Injection - Loose coupling with IoC container
- ๐ก Event-Driven Architecture - Decoupled communication
- ๐ก๏ธ Type Guards - Runtime type safety validation
- ๐ Immutable State - Predictable state management
- Modern web browser with ES2023+ support
- Local HTTP server (optional, for development)
-
Clone the repository
git clone https://github.com/inflop/minesweeper-js.git cd minesweeper-js
-
Serve the application
# Option 1: Python python3 -m http.server 8000 # Option 2: Node.js npx serve . # Option 3: Open directly open index.html
-
Open in browser
http://localhost:8000
- ๐ฏ Objective: Find all mines without detonating them
- ๐ฑ๏ธ Left Click: Reveal a cell (timer starts on first click)
- ๐ฑ๏ธ Right Click: Flag/unflag a suspected mine
- ๐ข Numbers: Indicate adjacent mine count
- ๐ Win: Reveal all non-mine cells
- ๐ฅ Lose: Click on a mine (wrong flags shown with โ)
- โฑ๏ธ Smart Timer: Only starts counting when you make your first move
- ๐ฉ Flag Counter: Shows remaining mines, can go negative if you over-flag
- โ Wrong Flag Detection: After losing, incorrectly flagged cells are highlighted
- โก Cascade Reveal: Empty cells automatically reveal their neighbors
Level | Size | Mines | Density |
---|---|---|---|
๐ข Beginner | 8ร8 | 10 | 15.6% |
๐ก Intermediate | 16ร16 | 38 | 14.8% |
๐ด Expert | 16ร30 | 72 | 15.0% |
minesweeper-js/
โโโ ๐ app.js # Application bootstrap
โโโ ๐ index.html # Entry point
โโโ ๐ styles.css # Styling
โ
โโโ ๐ domain/ # ๐๏ธ Business Logic
โ โโโ entities/ # Domain entities
โ โโโ value-objects/ # Immutable data
โ โโโ services/ # Domain operations
โ
โโโ ๐ application/ # ๐ฏ Use Cases
โโโ ๐ infrastructure/ # โ๏ธ Technical Services
โโโ ๐ presentation/ # ๐ผ๏ธ UI Layer
โโโ ๐ common/ # ๐ ๏ธ Shared Utilities
// Rich domain entity with business logic
const cell = new Cell('cell_1_1', false, position);
cell.reveal(); // Returns Result<T>
cell.toggleFlag(); // Functional state changes
cell.canBeRevealed(); // Business rule validation
// Value object with domain behavior
const position = new Position(1, 1);
position.isAdjacentTo(other); // Domain operations
position.getNeighborPositions(bounds); // Spatial calculations
// Game orchestration service
const gameService = container.resolve('gameServiceFactory')(config);
const result = gameService.revealCell(position);
result.match({
success: (data) => handleSuccess(data),
failure: (error) => showError(error)
});
// Add new rendering strategy
class SpecialCellStrategy extends CellRenderingStrategy {
canHandle(cell) { return cell.isSpecial; }
render(cell) { return 'โญ'; }
}
// Register in CellRenderer
cellRenderer.addStrategy(new SpecialCellStrategy(), 0);
// Extend GameRules service
class CustomGameRules extends GameRules {
isGameWon(board) {
// Custom win condition logic
return super.isGameWon(board) && this.customCondition(board);
}
}
// Register in ServiceRegistration
container.register('gameRules', () => new CustomGameRules());
// Add custom game over visualization
class CustomGameOverService extends GameOverService {
markCellAsSpecial(cellId) {
// Custom end-game marking logic
this.markCellAsWrongFlag(cellId);
}
}
// Register in DI container
container.register('gameOverService', () => new CustomGameOverService());
The application includes comprehensive error handling and logging:
# Manual testing checklist
- [ ] Game auto-loads with beginner level
- [ ] Timer starts only on first cell click
- [ ] Cell revealing works (with cascade for empty cells)
- [ ] Cell flagging works (counter can go negative)
- [ ] Wrong flags highlighted on game loss (โ)
- [ ] All mines revealed on game loss
- [ ] Game win detection
- [ ] Theme switching (๐/โ๏ธ)
- [ ] All difficulty levels work
- [ ] Responsive design on mobile
This version includes significant enhancements developed with Claude Code:
- โฑ๏ธ Smart Timer - Starts counting only on first cell click (industry standard)
- ๐ฉ Enhanced Flagging - Mine counter can go negative for better UX feedback
- โ Wrong Flag Detection - Visual indicators for incorrectly flagged cells after game loss
- โก Optimized Cascade Reveal - Improved algorithm for revealing empty cell neighbors
- ๐ฎ Auto-Load - Game starts immediately with beginner level for better UX
- ๐ญ Strategy Pattern Enhancement -
WrongFlagStrategy
for game-over visualization - ๐๏ธ Domain Purity - Moved UI concerns from domain to infrastructure (
GameOverService
) - ๐ง Method Decomposition - Split large methods into focused, single-responsibility functions
- ๐ก Event-Driven Improvements - Enhanced event publishing for all game state changes
- ๐ Dependency Injection - Complete IoC container integration throughout the application
- โ 0% Technical Debt - Pure modern architecture
- โ 100% ES2023+ - Latest JavaScript features
- โ SOLID Compliant - All five principles implemented
- โ DDD Architecture - Proper domain modeling
- โ Type Safe - Comprehensive runtime validation
- โ Functional - Result pattern for error handling
- ๐ฏ Single Responsibility - Each class has one clear purpose
- ๐ Immutable State - Predictable state management
- ๐ก๏ธ Error Handling - No uncaught exceptions
- ๐ Self-Documenting - Clear, descriptive naming
- ๐งช Testable Design - Dependency injection throughout
- โก Performance - Efficient algorithms and rendering
Contributions are welcome! This project follows strict architectural principles:
- Domain First - Place business logic in domain layer
- Result Pattern - Return
Result<T>
instead of throwing exceptions - Type Safety - Use TypeGuards for validation
- Immutability - Prefer immutable data structures
- SOLID Principles - Follow all five principles
- No External Dependencies - Vanilla JavaScript only
# 1. Fork the repository
# 2. Create a feature branch
git checkout -b feature/amazing-feature
# 3. Make changes following architecture guidelines
# 4. Test thoroughly
# 5. Create a Pull Request
- ๐ Architecture Guide - Development guidance for Claude Code
- ๐ฏ Clean Architecture - Pure DDD implementation with SOLID principles
- ๐ Modern JavaScript - ES2023+ features, no external dependencies
- ๐๏ธ Extensible Design - Strategy patterns for easy customization
Browser | Version | Status |
---|---|---|
๐ Chrome | 91+ | โ Fully Supported |
๐ฆ Firefox | 89+ | โ Fully Supported |
๐งญ Safari | 14+ | โ Fully Supported |
๐ Edge | 91+ | โ Fully Supported |
Requirements: ES2023+ features including:
- Private class fields (
#field
) - Dynamic imports
- Optional chaining (
?.
) - Nullish coalescing (
??
)
This project is licensed under the MIT License - see the LICENSE file for details.
- ๐ฎ Classic Minesweeper - Inspiration from the timeless game
- ๐๏ธ Clean Architecture - Robert C. Martin's architectural principles
- ๐ฏ Domain-Driven Design - Eric Evans' design philosophy
- โก Modern JavaScript - Latest ECMAScript standards
- ๐ค Claude Code - AI-powered development tool that assisted in implementing advanced features and architectural improvements
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Contact: Create an issue for questions
โญ Star this repository if you find it helpful!
Built with โค๏ธ using modern JavaScript and clean architecture principles
Latest improvements developed with ๐ค Claude Code