SME Analyzer
The SME (Subject Matter Expert) Analyzer (xylem-sme-analyzer) is a lightweight Python FastAPI microservice that converts DXF CAD drawings to clipped, print-ready PDF documents.
Purpose
When survey maps or floorplans need to be shared as PDFs, this service:
- Reads the DXF file using ezdxf
- Renders the drawing as SVG
- Clips to a specified viewport or boundary
- Converts SVG → PDF using CairoSVG
- Returns the final PDF file
Architecture
xylem-sme-analyzer/
├── app/
│ ├── main.py # FastAPI application + endpoints
│ ├── converter.py # Core DXF → SVG → PDF conversion logic
│ └── __init__.py
├── pyproject.toml # Dependencies (managed by uv)
└── uv.lock # Lock file
API Endpoints
| Method | Path | Description |
|---|---|---|
POST | /convert | Convert a DXF file to PDF |
GET | /health | Health check |
Convert Endpoint
POST /convert
Content-Type: multipart/form-data
Parameters:
- file: DXF file (multipart upload)
- clip_bounds: Optional viewport bounds for clipping
- page_size: Output PDF page size (A4, A3, etc.)
Returns the generated PDF as a file download.
Dependencies
| Package | Purpose |
|---|---|
fastapi | API framework |
uvicorn | ASGI server |
ezdxf | DXF file reading and parsing |
cairosvg | SVG → PDF rendering |
shapely | Geometry clipping operations |
System Dependency
| Package | Install | Purpose |
|---|---|---|
libcairo2 | sudo apt install libcairo2-dev | Required by cairocffi / cairosvg for SVG rendering |
Conversion Pipeline
Input DXF File
│
▼
┌─────────────────────────┐
│ 1. Parse DXF (ezdxf) │
│ - Read entities │
│ - Extract geometry │
│ - Get layer info │
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ 2. Render to SVG │
│ - Convert entities │
│ - Apply styles │
│ - Set viewport │
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ 3. Clip (Shapely) │
│ - Apply clip bounds │
│ - Trim to viewport │
└───────────┬─────────────┘
│
▼
┌─────────────────────────┐
│ 4. SVG → PDF (CairoSVG) │
│ - Render to PDF │
│ - Set page size │
└───────────┬─────────────┘
│
▼
Output PDF File
Deployment
| Property | Value |
|---|---|
| Domain | sme.xylem.city |
| Port | 4802 |
| Process Manager | PM2 |
| SSL | Let's Encrypt via Certbot |
# Install dependencies
uv sync
# Start server
uv run uvicorn app.main:app --host 0.0.0.0 --port 4802 --timeout-keep-alive 300
# Or via PM2
pm2 restart xylem-sme-analyzer
Integration
The backend calls the SME Analyzer when it needs to generate PDFs from DXF files:
Backend (NestJS) ──POST /convert──▶ SME Analyzer (FastAPI)
(DXF file) │
▼
◀──── PDF response ──── Converted PDF
This is used in the convertToPdf.ts utility in the backend, called from the survey-maps and catalog modules.