Architecture overview (Model-View-Presenter)¶
Version 4 separates what is computed (model), how it is shown (views) and who decides the order (presenter), with a thin command line on top and a typed configuration underneath.
flowchart TB
cli["CLI - sidenor_ladle.cli<br/>typer: run, step, check, report, config, dev"]
pres["Presenter - sidenor_ladle.presenter<br/>PipelinePresenter: selects, runs, persists, reports"]
model["Model - sidenor_ladle.model<br/>steps 01-13, checks, domain services, I/O,<br/>StepResult, FigureSpec, Workspace"]
view["View - sidenor_ladle.view<br/>ConsoleView, PlotlyFigureFactory,<br/>Markdown / HTML / PDF renderers"]
cfg["Configuration - sidenor_ladle.config<br/>pydantic models, TOML/YAML/JSON loader, .env settings"]
cli --> pres
cli --> cfg
pres --> model
pres --> view
model --> cfg
view -. reads results only .-> model
Responsibilities¶
| Layer | Knows | Never does |
|---|---|---|
| Model | the method: segmentation, features, labels, models; which files a step reads and writes | print, draw, choose the order of the steps |
| View | how to format a StepResult / ReportDocument: plotly, HTML, Markdown, PDF, console |
compute or read data files |
| Presenter | the order of the steps, what is written next to each step, how a report is built | domain logic, drawing |
| CLI | the arguments | anything else: it builds the configuration and calls the presenter |
| Configuration | every parameter, validated | read data |
Main design choices¶
- One class per step (
PipelineStep), registered with@register: adding a step needs no change in the orchestration code.requireslists the steps it reads from. - Domain services are classes configured by their pydantic block (
MaskSegmenter,ShellFeatureExtractor,ThicknessSheetParser...), easy to test in isolation. - Typed contracts between layers:
StepResult,TableSpecandFigureSpecare pydantic models, serialisable to JSON (<key>.result.json), so a report can be rebuilt later and the views never depend on the internals of a step. - Library-independent figures: the model describes a figure (panels, lines, histograms, heat maps, mask outlines); only the view imports plotly.
- Workspace owns the paths and caches the tables read several times in one run
(
images_v2.csvis read by eight steps), always handing out copies. - Efficiency: the configuration is sent once per worker process (initializer)
instead of once per image; processes are started with
forkserver(safe with the threads of the Kaleido server); arrays stay memory-mapped; plotly figures are built once and their PNG exported once per run, through a persistent headless browser. - Reproducibility: computations are line-for-line those of version 3.8.0; the regression test checks the 35 data files of the synthetic run against v3.8.0.
Folder layout¶
sAIfety-UPM/
├── pyproject.toml, poetry.lock Poetry project (package sidenor-ladle, extras, dev/docs groups)
├── .env.example template of the private settings (.env is git-ignored)
├── config/config.toml every parameter, commented
├── src/sidenor_ladle/
│ ├── config/ models.py, loader.py, settings.py
│ ├── model/
│ │ ├── io/ binfile.py, naming.py
│ │ ├── domain/ segmentation, thermal_features, thickness_sheet, enhancement, common
│ │ ├── steps/ base.py + s01 ... s13
│ │ ├── checks/ ladle_numbers, attribution, ladle_identity, data_quality
│ │ ├── results.py, figures.py, workspace.py
│ ├── view/ figures.py, document.py, console.py, renderers/{markdown,html,pdf}.py
│ ├── presenter/ pipeline.py
│ ├── cli/ app.py
│ └── testing/ synthetic.py, compare.py
├── tests/unit, tests/integration pytest (+ data/reference_v3_8_0.json)
├── docs/ this documentation (MkDocs, rendered by GitHub too)
└── .github/workflows/ tests.yml, docs.yml