Architecture

PlotSmith follows a strict 4-layer architecture with clear boundaries between layers. This design ensures separation of concerns, testability, and maintainability.

Layer 1: Data and Representations

Location: plotsmith.objects

This layer defines immutable dataclasses that represent plot-ready data and plot specifications. No matplotlib imports are allowed in this layer.

View Objects:

Validators: plotsmith.objects.validate contains validation functions that check shapes and alignment of view objects.

Layer 2: Primitives

Location: plotsmith.primitives

This layer defines the drawing API. It can import matplotlib and must accept only Layer 1 objects. All matplotlib calls are encapsulated here.

Drawing Functions:

Styling Helpers:

Labeling Helpers:

Layer 3: Tasks

Location: plotsmith.tasks

Tasks translate user intent into Layer 1 objects and a FigureSpec. Tasks can import pandas and numpy, but not matplotlib. Tasks can only import Layer 1 objects.

Task Classes:

  • plotsmith.tasks.TimeseriesPlotTask - Convert time series data to views

  • plotsmith.tasks.BacktestPlotTask - Convert backtest results to views

  • plotsmith.tasks.HistogramPlotTask - Convert data to histogram views

  • plotsmith.tasks.BarPlotTask - Convert data to bar views

  • plotsmith.tasks.HeatmapPlotTask - Convert data to heatmap views

  • plotsmith.tasks.ResidualsPlotTask - Convert residuals to views

Layer 4: Workflows

Location: plotsmith.workflows

Workflows provide one-call entry points for users. Workflows can import matplotlib. They call tasks, then primitives, then save or show plots.

Workflow Functions:

Public API

The public API is defined in plotsmith/__init__.py and exports only:

  • Workflow functions

  • View objects (for type hints)

  • Styling helpers

All other modules are internal and should not be imported directly.