# GDS and SVG Generation Logic Path This document traces the current code path for generating saved layout YAML, layout preview SVG, and downloadable project GDS when the user clicks `Build Layout` or `Build GDS`. Line numbers refer to the files as currently checked in. ## Build-Time Router Gate `python backend/server.py` -> `app.run` starts without importing `mxpic_router`, `mxpic_forge`, Nazca, or gdstk. Login, dashboard, canvas editing, YAML generation, PDK browsing, and project save without preview do not require the external build stack. Build actions validate the external stack on demand: - `Build GDS` -> `backend/gds_builder.py` -> `require_router_stack()`. - `Build Layout` SVG preview -> `backend/routed_layout_preview.py` -> `require_router_stack(require_gdstk=True)`. Important functions: - `ensure_router_path` (`backend/router_dependency.py` line 23) adds the sibling `../mxpic_router` checkout to `sys.path` when present. - `require_router_stack` (`backend/router_dependency.py` line 31) imports `mxpic_router`, `nazca`, and the route backend used by `mxpic_router`. The preferred route backend is `mxpic_forge.Route`; if it is absent, `mxpic_router` falls back to Nazca `interconnects.Interconnect`. `gdstk` is checked only when SVG preview generation requests it. ## Generated Files - Saved cell YAML: `database//layout//.yml` - Path helpers: `user_layout_root`, `project_root`, `cell_file_path` (`backend/server.py` lines 124-137). - Saved layout preview SVG: `database//layout//.svg` - Path helper: `cell_svg_path` (`backend/server.py` lines 140-142). - Optional route sidecar: `database//layout//.routes.yml` - Path helper and writer: `cell_routes_path`, `write_route_points_sidecar` (`backend/server.py` lines 145-175). - Downloadable GDS export: `database/_exports//.gds` - Created by `create_export_path` (`backend/pdk_access.py` lines 53-59). ## Build Layout: Click Button -> YAML -> Router GDS -> SVG Compact path: `Click Build Layout` -> `handleBuildLayout` (`frontend/canvas.html` line 6209) : `buildYamlForPage` (`frontend/canvas.html` line 6141) generates layout YAML -> POST `/api/save-layout` (`frontend/canvas.html` line 6219) -> `save_layout` (`backend/server.py` line 715) writes `.yml` -> `create_routed_layout_svg` (`backend/server.py` line 734) -> `mxpic_router.build_project_gds` generates temporary Nazca GDS -> `gdstk.read_gds` + `write_svg` writes `.svg` -> backend returns `svg_url` -> `openLayoutPreview` (`frontend/canvas.html` line 6183) opens the SVG preview tab. Detailed path: 1. The button is rendered only for non-preview pages: - `