Generate stunning, professional code screenshots with themes, effects, and customizable styling. Perfect for social media, presentations, documentation, and sharing code snippets.
This project is built as a Model Context Protocol (MCP) server, enabling AI assistants to generate beautiful code screenshots programmatically.
This project is optimized for Railway deployment with Docker.
Quick Deploy:
- Fork this repository
- Connect to Railway
- Set environment variables:
AUTH_TOKEN- Your authentication tokenMY_NUMBER- Your phone number for authenticationLOG_LEVEL- Optional: DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO)
- Deploy!
Included in Deployment:
- β All fonts bundled (Fira Code, JetBrains Mono, Source Code Pro)
- β System dependencies (Tesseract, OpenCV, PIL)
- β Production-ready Docker configuration
- β Automatic environment detection
Run locally:
python main.pyDocker Development:
# Build the Docker image
docker build -t codeshot-mcp .
# Run with Docker
docker run -p 8086:8086 \
-e AUTH_TOKEN=test \
-e MY_NUMBER=123 \
-e LOG_LEVEL=DEBUG \
codeshot-mcpDocker Compose (Optional):
# docker-compose.yml
version: '3.8'
services:
codeshot:
build: .
ports:
- "8086:8086"
environment:
- AUTH_TOKEN=your-token
- MY_NUMBER=your-number
- LOG_LEVEL=INFO
```ippets.
## β¨ Features
- **π¨ Beautiful Themes**: Dracula, Nord, Monokai, GitHub Light, Material, and more
- **πΌοΈ Multiple Frame Styles**: macOS, Windows, Floating, Minimal, or no frame
- **π Rich Backgrounds**: Solid colors, gradients, neon effects, or transparent
- **π Professional Typography**: Fira Code, JetBrains Mono, Source Code Pro fonts
- **β¨ Visual Effects**: Shadows, reflections, rounded corners, border glow
- **π URL Support**: Fetch code directly from GitHub, Gist, or any URL
- **π² Smart Randomization**: Automatic variety when parameters aren't specified
- **β‘ High Performance**: Optimized rendering with modular architecture
## π Quick Start
### System Requirements
- **Python 3.11+**
- **System Dependencies**:
- Tesseract OCR (for text processing)
- OpenCV libraries
- PIL/Pillow (Python Imaging Library)
**Note**: All dependencies are included in the Docker container for deployment.
### Installation
```bash
# Clone the repository
git clone https://github.com/Ayyanaruto/codeshot.git
cd codeshot
# Option 1: Install with pip
pip install -r requirements.txt
# Option 2: Install as package
pip install -e .
# Option 3: Install with uv (recommended)
uv sync
# Set up environment variables
cp .env.example .env
# Edit .env with your AUTH_TOKEN and MY_NUMBEREnvironment Setup:
# Required environment variables
export AUTH_TOKEN="your-secret-token"
export MY_NUMBER="your-phone-number"
# Optional: Set log level
export LOG_LEVEL="INFO" # DEBUG, INFO, WARNING, ERROR, CRITICALStart the Server:
# Start the MCP server
python main.pyThis server provides two main tools:
codeshot- Generate beautiful code screenshots with extensive customization optionsvalidate- Validate configuration and check server status
# Generate a code screenshot
response = await codeshot(
code='''
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
''',
theme="dracula",
frame_style="macos",
background="purple",
font_family="fira-code",
shadow=True,
rounded_corners=True
)
# Or fetch code from a URL
response = await codeshot(
code_url="https://github.com/Ayyanaruto/codeshot/blob/main/main.py",
theme="nord",
frame_style="windows",
background="transparent"
)codeshot/
βββ main.py # MCP server entry point
βββ requirements.txt # Dependencies
βββ pyproject.toml # Project configuration
βββ uv.lock # Dependency lock file
βββ Dockerfile # Docker container configuration
βββ railway.json # Railway deployment config
βββ start.sh # Production startup script
βββ .env.example # Environment variables template
βββ config/ # Configuration and constants
β βββ __init__.py
β βββ constants.py # Theme mappings, color definitions
β βββ logging_config.py # Logging setup
βββ src/ # Core application code
β βββ __init__.py
β βββ core/ # Core functionality
β β βββ __init__.py
β β βββ generator.py # Main screenshot generator
β β βββ renderer.py # Code rendering logic
β βββ utils/ # Utility functions
β β βββ __init__.py
β β βββ validation.py # Parameter validation
β β βββ fonts.py # Font loading utilities
β β βββ http.py # URL fetching
β β βββ backgrounds.py # Background generation
β βββ effects/ # Visual effects
β β βββ __init__.py
β β βββ shadows.py # Shadow effects
β β βββ reflections.py # Reflection effects
β β βββ special.py # Glow, watermarks, etc.
β βββ frames/ # Window frame styles
β βββ __init__.py
β βββ macos.py # macOS window frame
β βββ windows.py # Windows window frame
βββ fonts/ # Font assets
β βββ FiraCode/
β βββ JetBrainsMono/
β βββ SourceCodePro/
βββ tests/ # Test suite
β βββ conftest.py
β βββ test_generator.py
β βββ test_themes.py
βββ logs/ # Application logs
βββ codeshot.log
- dracula - Dark theme with purple accents
- nord - Arctic, north-bluish color palette
- monokai - Classic dark theme with vibrant colors
- material - Google's Material Design dark
- one-dark - Atom's iconic One Dark theme
- gruvbox-dark - Retro groove color scheme
- tokyo-night - A clean, dark theme inspired by Tokyo's night
- catppuccin - Soothing pastel theme for night owls
- github-dark - GitHub's dark theme
- solarized-dark - Precision colors for machines and people
- zenburn - Low-contrast color scheme
- vim - Classic Vim color scheme
- native - Terminal-style theme
- fruity - Colorful syntax highlighting
- cyberpunk - High-contrast neon theme
- github-light - Clean light theme
- solarized-light - Precision colors for machines and people
- vs - Visual Studio light theme
- friendly - Easy on the eyes light theme
- colorful - Vibrant light theme
- gruvbox-light - Light version of the retro groove scheme
- macos - macOS window with traffic light buttons
- windows - Windows window with minimize/maximize/close
- floating - Clean floating frame
- minimal - Minimal border
- none - No frame, just code
- Solid Colors: purple, cyan, orange, pink, green, blue, red, yellow, etc.
- Hex Colors: Any valid hex color code (#1a1a2e, #533483, etc.)
- Special: transparent, neon-purple (with grid effect)
The application uses a modular configuration system:
- config/constants.py - All theme mappings, colors, and settings
- Environment Variables - AUTH_TOKEN and MY_NUMBER for MCP auth
- Font Configuration - Automatic font loading with system fallbacks
# Format code
black src/ config/ main.py
# Sort imports
isort src/ config/ main.py
# Type checking
mypy src/ config/ main.py
# Linting
flake8 src/ config/ main.py
# Run tests
pytestThe codebase follows clean architecture principles:
- Separation of Concerns: Each module has a single responsibility
- Dependency Injection: Core components don't depend on utilities
- Type Safety: Full type annotations with mypy checking
- Error Handling: Comprehensive error handling with fallbacks
- Modularity: Easy to extend with new themes, effects, or frames
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test file
pytest tests/test_generator.pyCodeshot includes a comprehensive logging system for debugging and monitoring:
# Set log level in environment
export LOG_LEVEL=DEBUG # DEBUG, INFO, WARNING, ERROR, CRITICAL- Colored Console Output: Easy-to-read colored logs in terminal
- Rotating Log Files: Automatic log rotation (10MB max, 5 backups)
- Performance Monitoring: Built-in timing for operations
- Module-Specific Logging: Separate loggers for each component
- Error Tracking: Detailed error logging with stack traces
from config.logging_config import get_logger, log_performance
logger = get_logger(__name__)
# Basic logging
logger.info("Starting screenshot generation")
logger.debug("Processing parameters")
logger.error("Something went wrong")
# Performance monitoring
with log_performance(logger, "image generation"):
generate_screenshot()- Default location:
logs/codeshot.log - Automatic rotation when files exceed 10MB
- Configurable via
LOG_FILEenvironment variable
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Bug Reports
- π¬ Discussions
Made with β€οΈ by Ayyan