A production-ready, enterprise-grade Kotlin service that transforms code snippets into beautiful, syntax-highlighted images. Built with comprehensive security, intelligent caching, and performance optimizations.
Code Snapper API provides a robust REST endpoint that converts any code into professionally styled PNG images with enterprise-level security and performance. Perfect for documentation, presentations, automated workflows, and high-traffic applications.
macOS Style - Authentic macOS window design with traffic light controls and native styling Material Design - Google Material Design 3 compliant with verified accessibility standards
- Rate Limiting: 30 requests/minute, 300/hour per IP with intelligent concurrency controls
 - CORS Protection: Secure cross-origin policies (no more 
anyHost()vulnerabilities) - Request Monitoring: Comprehensive security event logging and metrics
 - Input Validation: Robust validation with structured error responses
 
- Intelligent Caching: SHA-256 keyed cache with TTL expiration and LRU eviction
 - Concurrency Management: Semaphore-based limits prevent resource exhaustion
 - Memory Optimization: Efficient ByteArray handling and cleanup
 - Response Times: Typical 150-700ms for image generation
 
POST /snap
GET /health      # Health check endpoint
GET /metrics     # Performance metrics (if monitoring enabled)
{
  "code": "fun hello() = println(\"Hello World!\")",
  "language": "kotlin",
  "designSystem": "material",
  "title": "My Code Example"
}{
  "code": "class Example { fun demo() = println(\"Advanced!\") }",
  "language": "kotlin",
  "preset": "presentation",
  "designSystem": "macos",
  "backgroundTheme": "darcula",
  "fontSize": 16
}Returns a high-quality PNG image with proper syntax highlighting, professional styling, and optimized caching headers.
- Dual Design Systems: Choose between macOS or Material Design aesthetics
 - Smart Auto-sizing: Automatically calculates optimal dimensions for your content
 - Custom Titles: Add meaningful titles to your code windows
 - Background Themes: Eight carefully curated themes (darcula, monokai, atom, etc.)
 - Syntax Highlighting: Support for 24+ programming languages
 - Accessibility Compliant: WCAG AA standards met in Material Design mode
 
- Production-Ready: Built with Clean Architecture principles
 - Security First: Rate limiting, CORS protection, input validation
 - High Performance: Intelligent caching reduces server load by up to 80%
 - Monitoring: Built-in metrics and security event logging
 - Scalable: Designed for high-concurrency production environments
 - Fault Tolerant: Comprehensive error handling and graceful degradation
 
Choose from optimized presets for common use cases:
"default"- Balanced settings for general use"presentation"- Large, clear images perfect for presentations"compact"- Smaller images optimized for documentation"light"- Light theme with minimal styling
Built following Clean Architecture principles with:
- Domain Layer: Core business logic and interfaces
 - Infrastructure Layer: External service implementations
 - Use Cases: Application-specific business rules
 - Dependency Injection: Koin-based IoC container
 - Testing: 100% coverage with integration tests
 
- Response Time: 150-700ms typical
 - Throughput: 30 requests/minute per IP, scalable to thousands/hour
 - Cache Hit Rate: Up to 80% for repeated requests
 - Memory Usage: Optimized with automatic cleanup
 - Uptime: Production-ready with comprehensive monitoring
 
- 30 requests per minute per IP
 - 300 requests per hour per IP
 - 10 concurrent requests maximum
 - Automatic cleanup and memory management
 
- Whitelist-based origin control
 - No wildcard (
*) origins allowed - Secure headers and credentials handling
 - 24-hour cache for preflight requests
 
- Code length limits (50KB max)
 - Language whitelist validation
 - Theme and preset validation
 - Structured error responses with security codes
 
| Parameter | Type | Description | Default | 
|---|---|---|---|
code | 
string | The code content to render | Required | 
language | 
string | Programming language | Required | 
designSystem | 
string | "macos" or "material" | "macos" | 
preset | 
string | Preset configuration | null | 
theme | 
string | Syntax highlighting theme | "darcula" | 
backgroundTheme | 
string | Background theme | "darcula" | 
title | 
string | Window title | null | 
fontSize | 
number | Font size (8-72) | 14 | 
width | 
number | Custom width | Auto | 
height | 
number | Custom height | Auto | 
Popular Languages: kotlin, java, swift, python, typescript, javascript, go, rust Web Technologies: html, css, json, yaml, xml System Languages: c, cpp, shell, sql Others: ruby, php, scala, groovy, dart, markdown
darcula Classic IntelliJ dark theme chatgpt5 Modern blue-green gradient solarized_dark Developer favorite with warm accents nord Cool Arctic blues and grays one_dark VS Code inspired theme cyberpunk Electric purple and pink gradients sunset Warm orange to pink gradient ocean Deep blue gradient depths
Use a preset to quickly apply a base layout (you can still override width, height, colors, etc.).
| Preset | Description | 
|---|---|
default | 
Standard dark configuration | 
light | 
Light background + dark text | 
presentation | 
1920x1080, larger font (24px), extra padding | 
compact | 
800x600, smaller font (14px), reduced padding | 
Example:
{
  "code": "println(\"Hello\")",
  "language": "kotlin",
  "preset": "presentation",
  "designSystem": "material"
}./gradlew runThe API will be available at http://localhost:8081
# Run all tests
./test-automation.sh
# Check Material Design compliance
./test-material-design.sh
# Code quality checks
./gradlew codeQualityPresets in test data:
The JSON samples under docs/testing now demonstrate different scenarios via the preset parameter:
- 5-line samples: 
compact(macOS) andlight(Material) - 15-line samples: 
default(both design systems) - 30-line samples: 
presentation(both design systems) When adding new test fixtures prefer using a preset for baseline sizing, then override only what is necessary (e.g. width/height/fontSize) to keep fixtures concise. 
Code Snapper API is packaged as a Docker container for easy, zero-ops deployment. Pull the official image or build your own:
# Pull latest release
docker pull ghcr.io/raquezha/codesnapper:latest
# Run locally
docker run -p 8081:8081 ghcr.io/raquezha/codesnapper:latestAlternatively, download the JAR and run directly:
java -jar codesnapper-<version>.jarPlanned improvements include:
- Unit and integration tests for all endpoints
 - Download/preview URL functionality
 - Rate limiting and usage tracking
 - Interactive frontend playground
 - Pastebin-style history for saved snippets