Design document
This document expands the architecture diagram into modules, describes the code repository, defines the data the system exchanges, and records why we chose this design over others.
1. Expanded architecture
- ui/builder to API interface
- ui/optimize to API interface
- ui/results to API interface
- API interface to Mock client: dev
- API interface to HTTP client: real
- HTTP client to service/: HTTP + JSON
- service/ to LieOptics: Python calls
- electron/ to service/: starts / stops
- API interface to electron/: save / open (IPC)
Each box above is a module in the repository. Responsibilities:
| Module | Language | Component | Responsibility |
|---|---|---|---|
| ui/builder | TypeScript | Renderer UI | Lens element form and layout canvas; edits the in-memory lens model. |
| ui/results | TypeScript | Renderer UI | Aberration coefficient table, spot diagram, and phase-space plots. |
| ui/optimize | TypeScript | Renderer UI | Optimization bounds, run, progress, and cancel controls. |
| api | TypeScript | API client | Typed interface plus mock and HTTP implementations, so the real backend can replace the mock. |
| electron | TypeScript | Electron shell | Window management, save/load dialogs, starting and stopping the Python service. |
| service | Python | Thin Python service | Exposes analyze, optimize, and spot-diagram endpoints that call LieOptics. |
2. Code repository
Team repository. The repository README covers installing dependencies, running the app against the mock API, and running it against the real backend.
| Language | Implements |
|---|---|
| TypeScript (React) | Renderer UI and typed API client |
| TypeScript (Node) | Electron main process: windows, file access, service launch |
| Python | Thin service wrapping LieOptics (the LieOptics package itself is the client's) |
3. Data definitions
LensElement — One lens in the system.
| Field | Type | Meaning |
|---|---|---|
id | string | Stable identifier used by the UI. |
radius | number | Curvature radius of the surface. |
thickness | number | Distance to the next element. |
glassIndex | number | Refractive index of the glass. |
LensSystem — A complete design; also the saved-file format (JSON).
| Field | Type | Meaning |
|---|---|---|
version | number | File format version for future migration. |
name | string | User-visible title. |
elements | LensElement[] | Ordered front to back. |
fieldAngles | number[] | Field angles analyzed; three by default. |
AnalysisResult — Returned by an analyze request.
| Field | Type | Meaning |
|---|---|---|
coefficients | { name: string; value: number }[] | Aberration coefficients. |
spots | { fieldAngle: number; points: [number, number][] }[] | Spot-diagram points per field angle. |
OptimizationRequest — Sent to start an optimization.
| Field | Type | Meaning |
|---|---|---|
system | LensSystem | Starting design. |
variables | { elementId: string; parameter: string; min: number; max: number }[] | Which parameters vary and their bounds. |
Field names are the front end's own contract. The Python service maps them onto the LieOptics classes, so a change in LieOptics touches only that mapping.
4. Design rationale
- Route everything through one typed API layer. It isolates the client's backend from the UI, lets us build and test against a mock first, and satisfies the no-backend-changes constraint.
- Electron desktop shell. Cross-platform, offline, and native file access with skills the team already has.
- Save designs as a single JSON file. Human-readable, easy to version-control and share, simple to validate.
Rejected approaches
- Python-native GUI (PyQt/Tkinter). Team lacks the experience, and interactive plots and a canvas builder would cost more effort.
- Pure web app with a hosted backend. No native file access and the client would need to host the backend.
- Rewriting LieOptics analysis in JavaScript. Duplicates the client's work and breaks the no-modification constraint.
- Direct in-process calls from the UI to Python. Couples the UI to backend internals and prevents mock-first development.
Related documents
- Specifications
- Platform selection
- Architecture diagram
- User manual: not yet written.
- Test plan: not yet written.