A comprehensive web-based combat simulator for Dungeons & Dragons 5th Edition, featuring AI-driven combat, party management, encounter building, and detailed analytics.
- Turn-based combat simulation with initiative tracking
- AI-driven decision making for both party and monster actions
- Spell casting system with damage calculation and saving throws
- Combat logging with detailed round-by-round analysis
- Multiple victory conditions and combat end detection
- Pre-built party templates (Classic Adventurers, Arcane Strikeforce, etc.)
- Character customization with class-specific abilities
- Level progression and spell slot management
- Party composition analysis and optimization suggestions
- Custom encounter creation with monster selection
- Pre-built encounter templates for quick setup
- Encounter balance calculation using D&D 5e guidelines
- Challenge Rating (CR) filtering and monster search
- Encounter difficulty warnings and recommendations
- RESTful API for programmatic access
- Open5e API integration for spell and monster data
- Local data fallback when external APIs are unavailable
- Rate limiting and security protection
- Comprehensive API documentation
- Database query optimization with indexing and caching
- Performance monitoring and metrics collection
- Error tracking and alerting system
- Health check endpoints for monitoring
- Load testing capabilities
- Input validation and sanitization
- CSRF protection for all forms
- Rate limiting to prevent abuse
- Security headers (HSTS, CSP, XSS protection)
- Non-root Docker containers
- Production deployment with Fly.io
- Python 3.11+
- Docker (optional, for containerized deployment)
- Fly.io CLI (for production deployment)
-
Clone the repository
git clone <repository-url> cd dnd5e_combat_sim
-
Set up virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Initialize database
python scripts/init_db.py
-
Run the application
python app.py
-
Access the application Open http://localhost:5000 in your browser
# Build and run with Docker Compose
docker-compose up --build
# The application will be available at http://localhost:5000-
Select a Party
- Choose from pre-built party templates
- Each party has different character compositions and strategies
-
Create an Encounter
- Use pre-built encounter templates for quick setup
- Or create custom encounters by selecting monsters
- View encounter balance and difficulty warnings
-
Run Simulation
- Start the combat simulation
- Watch real-time combat progress
- AI handles all decision-making for both sides
-
Review Results
- Detailed combat log with all actions
- Statistics and analytics
- Export results for further analysis
- Filter monsters by Challenge Rating (CR)
- Mix different monster types
- Balance encounters for your party level
# Get all monsters
curl http://localhost:5000/api/monsters
# Get monsters by CR
curl http://localhost:5000/api/monsters?cr=1/4
# Check encounter balance
curl -X POST http://localhost:5000/api/encounter/balance \
-H "Content-Type: application/json" \
-d '{"monsters": [{"name": "Goblin", "hp": 7, "ac": 15, "cr": "1/4"}], "party_level": 5, "party_size": 4}'dnd5e_combat_sim/
├── app.py # Main Flask application
├── models/ # Data models and business logic
│ ├── character.py # Character class and abilities
│ ├── monster.py # Monster class and actions
│ ├── combat.py # Combat simulation engine
│ ├── spells.py # Spell system and casting
│ └── db.py # Database management
├── controllers/ # Application controllers
│ ├── encounter_controller.py
│ ├── simulation_controller.py
│ └── results_controller.py
├── utils/ # Utility modules
│ ├── api_client.py # External API integration
│ ├── exceptions.py # Custom exception classes
│ ├── logging.py # Logging configuration
│ └── monitoring.py # Performance monitoring
├── data/ # Static data files
│ ├── parties.json # Party templates
│ ├── monsters.json # Monster data
│ └── spells.json # Spell data
├── templates/ # HTML templates
├── static/ # CSS, JS, and static assets
├── tests/ # Test suite
├── scripts/ # Deployment and utility scripts
├── docs/ # Documentation
└── requirements.txt # Python dependencies
- Initiative System: Roll-based initiative with tie-breaking
- Action Resolution: Attack rolls, saving throws, damage calculation
- AI Strategy: Context-aware decision making for both parties
- State Management: Efficient combat state tracking and caching
- SQLite: Lightweight, file-based database
- Optimized Queries: Indexed queries for performance
- Connection Pooling: Efficient database connection management
- Migration System: Schema versioning and updates
- Open5e API: External spell and monster data
- Fallback System: Local data when APIs are unavailable
- Caching: Response caching for performance
- Error Handling: Graceful degradation on API failures
-
Install Fly.io CLI
# macOS brew install flyctl # Linux curl -L https://fly.io/install.sh | sh
-
Authenticate and deploy
fly auth login fly deploy
-
Set environment variables
fly secrets set SECRET_KEY=your-production-secret-key fly secrets set DATABASE_URL=sqlite:////data/app.db
# Build production image
docker build -t dnd5e-combat-sim .
# Run with production settings
docker run -p 5000:5000 -e FLASK_ENV=production dnd5e-combat-sim| Variable | Description | Default |
|---|---|---|
FLASK_ENV |
Flask environment | development |
SECRET_KEY |
Flask secret key | dev-secret-key |
DATABASE_URL |
Database connection | sqlite:///data/app.db |
PYTHONUNBUFFERED |
Python output buffering | 1 |
# Unit tests
pytest tests/ -v
# Performance tests
BENCHMARK=1 pytest tests/test_performance.py -v
# Load tests
locust -f tests/test_load.py --host=http://localhost:5000- Unit Tests: Individual component testing
- Integration Tests: End-to-end workflow testing
- Performance Tests: Response time and throughput testing
- Load Tests: Concurrent user simulation
- Security Tests: Input validation and security measures
- Endpoint:
/healthz - Response:
okwith 200 status - Monitoring: 30-second intervals
- Response Times: Tracked for all endpoints
- Error Rates: Monitored and alerted
- System Resources: CPU, memory, disk usage
- User Analytics: Privacy-compliant usage statistics
- Application Logs: Structured logging with levels
- Error Tracking: Detailed error context and stack traces
- Performance Logs: Slow query and operation tracking
- Access Logs: Request/response logging
- Fork the repository
- Create a feature branch
git checkout -b feature/your-feature-name
- Make your changes
- Add tests for new functionality
- Run the test suite
pytest tests/ -v
- Submit a pull request
- Python: PEP 8 compliance
- Type Hints: Used throughout the codebase
- Documentation: Docstrings for all functions and classes
- Error Handling: Comprehensive exception handling
# Set up development environment
source scripts/env_setup.sh
# Run tests
pytest tests/ -v
# Start development server
python app.py
# Run performance benchmarks
BENCHMARK=1 pytest tests/test_performance.py -v- API Documentation: Complete API reference
- Deployment Guide: Production deployment instructions
- User Guide: End-user documentation
- Developer Guide: Development setup and guidelines
- Issues: Report bugs via GitHub issues
- Discussions: Use GitHub discussions for questions
- Documentation: Check the
docs/directory - Examples: See
tests/for usage examples
When reporting bugs, please include:
- Environment: OS, Python version, dependencies
- Steps to reproduce: Detailed reproduction steps
- Expected behavior: What should happen
- Actual behavior: What actually happened
- Logs: Relevant error logs and stack traces
This project is licensed under the MIT License - see the LICENSE file for details.
- D&D 5e Rules: Based on the official D&D 5e ruleset
- Open5e API: External data source for spells and monsters
- Flask: Web framework for the application
- Community: Contributors and testers
- Multiplayer Support: Real-time collaborative combat
- Character Builder: Visual character creation interface
- Campaign Management: Long-term campaign tracking
- Mobile App: Native mobile application
- Advanced AI: Machine learning for better combat decisions
- Mod Support: Plugin system for custom content
- Database Optimization: Query performance improvements
- Caching Layer: Redis integration for better performance
- Async Processing: Background task processing
- CDN Integration: Static asset optimization
Happy adventuring! 🐉⚔️