Skip to main content

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:

  1. Reads the DXF file using ezdxf
  2. Renders the drawing as SVG
  3. Clips to a specified viewport or boundary
  4. Converts SVG → PDF using CairoSVG
  5. 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​

MethodPathDescription
POST/convertConvert a DXF file to PDF
GET/healthHealth 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​

PackagePurpose
fastapiAPI framework
uvicornASGI server
ezdxfDXF file reading and parsing
cairosvgSVG → PDF rendering
shapelyGeometry clipping operations

System Dependency​

PackageInstallPurpose
libcairo2sudo apt install libcairo2-devRequired 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​

PropertyValue
Domainsme.xylem.city
Port4802
Process ManagerPM2
SSLLet'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.