any2svg / knowledge-base /architecture.md
nbiish
Add Any2SVG - Image to SVG vectorization with MCP server support
bb16d68 unverified
# Any2SVG Architecture
## Overview
Any2SVG is a Gradio 6 application that converts raster images to SVG vector graphics. It's designed to work both as a standalone web application and as an MCP (Model Context Protocol) server for AI agent integration.
## DNA Architecture
The project follows the DNA architecture pattern:
```
any-to-svg/
β”œβ”€β”€ app.py # Main Gradio application
β”œβ”€β”€ dna/
β”‚ β”œβ”€β”€ atoms/ # Core utilities
β”‚ β”‚ └── vectorizer.py # Low-level vtracer wrapper
β”‚ β”œβ”€β”€ molecules/ # Composite components
β”‚ β”‚ └── mcp_handler.py # MCP request processing
β”‚ └── proteins/ # High-level orchestration
β”œβ”€β”€ knowledge-base/ # Documentation
└── output/ # Generated SVG files
```
## Components
### Atoms Layer
- `vectorizer.py`: Core vectorization using vtracer library
- `VectorizerConfig`: Configuration dataclass
- `image_to_svg_string()`: Convert to SVG string
- `image_to_svg_file()`: Convert and save to file
### Molecules Layer
- `mcp_handler.py`: MCP integration
- `process_mcp_request()`: Handle MCP tool calls
- `get_output_directory()`: Manage output paths
### Application Layer
- `app.py`: Gradio interface and MCP server
- Web UI with configurable parameters
- MCP tool endpoint at `/gradio_api/mcp/sse`
## MCP Integration
The application exposes an MCP tool `image_to_svg` that:
1. Accepts image input (URL or base64)
2. Converts to SVG using vtracer
3. Saves to configured output directory
4. Returns file path and SVG content
## Security Considerations
- Input validation on all image uploads
- Sanitized file paths for output
- Environment variable protection for sensitive config
- No arbitrary code execution