# jpsca/jinjax architecture

> Architecture diagram of the GitHub repository jpsca/jinjax, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jpsca/jinjax
- Repository: https://github.com/jpsca/jinjax

## Overview

Jinjax is a Python library for writing server-side HTML components as Jinja templates and invoking them like tags. The main workflow is a template with component tags, JinjaX’s preprocessing into catalog calls, then Catalog’s component lookup and rendering. Component metadata and HTML attribute handling support that path; Catalog also gathers and emits component assets, and can configure middleware for serving them. The README establishes the tag-based usage, but some internal calls and asset-serving details are unsampled, so those links are omitted or marked unverified.

Main entry points: [`src/jinjax/catalog.py`](https://github.com/jpsca/jinjax/blob/main/src/jinjax/catalog.py) (Catalog), [`src/jinjax/component.py`](https://github.com/jpsca/jinjax/blob/main/src/jinjax/component.py) (Component metadata), [`src/jinjax/jinjax.py`](https://github.com/jpsca/jinjax/blob/main/src/jinjax/jinjax.py) (Tag preprocessor), [`src/jinjax/middleware.py`](https://github.com/jpsca/jinjax/blob/main/src/jinjax/middleware.py) (Asset middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_template_runtime["Template runtime"]
  node_jinja_templates["Component templates"]
  node_jinjax_extension["Tag preprocessor<br/>[jinjax.py]"]
end

subgraph group_component_rendering["Component rendering"]
  node_catalog["Catalog<br/>[catalog.py]"]
  node_component["Component metadata<br/>[component.py]"]
  node_html_attrs["HTML attributes<br/>[html_attrs.py]"]
end

subgraph group_assets_delivery["Assets and delivery"]
  node_asset_middleware["Asset middleware<br/>[middleware.py]"]
end

subgraph group_support["Runtime support"]
  node_exceptions["Runtime exceptions<br/>[exceptions.py]"]
  node_utils["Shared utilities<br/>[utils.py]"]
end

node_template_author(("Template author"))
node_jinja["Jinja2"]
node_whitenoise["WhiteNoise"]

node_template_author -->|"writes"| node_jinja_templates
node_jinja_templates -.->|"preprocessed by"| node_jinjax_extension
node_jinjax_extension -->|"dispatches calls"| node_catalog
node_catalog -.->|"loads and renders"| node_component
node_catalog -.->|"uses attributes"| node_html_attrs
node_catalog -->|"configures environment"| node_jinja
node_component -->|"raises errors"| node_exceptions
node_component -->|"uses helpers"| node_utils
node_catalog -->|"registers asset files"| node_asset_middleware
node_asset_middleware -->|"extends when available"| node_whitenoise

click node_jinjax_extension "https://github.com/jpsca/jinjax/blob/main/src/jinjax/jinjax.py"
click node_catalog "https://github.com/jpsca/jinjax/blob/main/src/jinjax/catalog.py"
click node_component "https://github.com/jpsca/jinjax/blob/main/src/jinjax/component.py"
click node_html_attrs "https://github.com/jpsca/jinjax/blob/main/src/jinjax/html_attrs.py"
click node_asset_middleware "https://github.com/jpsca/jinjax/blob/main/src/jinjax/middleware.py"
click node_exceptions "https://github.com/jpsca/jinjax/blob/main/src/jinjax/exceptions.py"
click node_utils "https://github.com/jpsca/jinjax/blob/main/src/jinjax/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_jinja_templates,node_jinjax_extension toneBlue
class node_catalog,node_component,node_html_attrs toneAmber
class node_asset_middleware toneMint
class node_exceptions,node_utils toneRose
class node_template_author,node_jinja,node_whitenoise toneIndigo
```

## Components

### Template runtime

- **Component templates**
- [Tag preprocessor](https://github.com/jpsca/jinjax/blob/main/src/jinjax/jinjax.py): `src/jinjax/jinjax.py`

### Component rendering

- [Catalog](https://github.com/jpsca/jinjax/blob/main/src/jinjax/catalog.py): `src/jinjax/catalog.py`
- [Component metadata](https://github.com/jpsca/jinjax/blob/main/src/jinjax/component.py): `src/jinjax/component.py`
- [HTML attributes](https://github.com/jpsca/jinjax/blob/main/src/jinjax/html_attrs.py): `src/jinjax/html_attrs.py`

### Assets and delivery

- [Asset middleware](https://github.com/jpsca/jinjax/blob/main/src/jinjax/middleware.py): `src/jinjax/middleware.py`

### Runtime support

- [Runtime exceptions](https://github.com/jpsca/jinjax/blob/main/src/jinjax/exceptions.py): `src/jinjax/exceptions.py`
- [Shared utilities](https://github.com/jpsca/jinjax/blob/main/src/jinjax/utils.py): `src/jinjax/utils.py`

### Other components

- **Template author**
- **Jinja2**
- **WhiteNoise**

## Connections

- Template author → Component templates: writes (evidence: `README.md`)
- Component templates → Tag preprocessor: preprocessed by
- Tag preprocessor → Catalog: dispatches calls (evidence: `src/jinjax/jinjax.py`)
- Catalog → Component metadata: loads and renders (evidence: `src/jinjax/catalog.py`)
- Catalog → HTML attributes: uses attributes (evidence: `src/jinjax/catalog.py`)
- Catalog → Jinja2: configures environment (evidence: `src/jinjax/catalog.py`)
- Component metadata → Runtime exceptions: raises errors (evidence: `src/jinjax/component.py`)
- Component metadata → Shared utilities: uses helpers (evidence: `src/jinjax/component.py`)
- Catalog → Asset middleware: registers asset files (evidence: `src/jinjax/catalog.py`)
- Asset middleware → WhiteNoise: extends when available (evidence: `src/jinjax/middleware.py`)
