# Technical Specifications This document provides detailed technical specifications for tdom-path. ## Architecture Overview ### Component Diagram ```mermaid graph TD A[tdom-path] --> B[webpath.py] A --> C[tree.py] B --> D[make_path] B --> E[Path Resolution] C --> F[make_path_nodes] C --> G[render_path_nodes] C --> H[Tree Transformation] C --> I[Render Strategies] ``` ### Core Components 1. **Path Resolution Module** (`webpath.py`) - `make_traversable()`: Core path resolution function - Path type detection (package vs relative) - Package path parsing and resolution - Module-relative path calculation 2. **Tree Transformation Module** (`tree.py`) - `make_path_nodes()`: Tree rewriting with Traversable - `render_path_nodes()`: Final rendering with string paths - `@path_nodes` decorator: Automatic transformation - Tree walking and traversal utilities 3. **Data Structures** - `TraversableElement`: Element with Traversable attributes - `AssetReference`: Asset metadata for build tools - `RenderStrategy` protocol: Extensible rendering interface ## Performance Specifications ### Target Performance Metrics | Operation | Target Time | Target Throughput | Memory Budget | |-----------|-------------|-------------------|---------------| | `make_traversable()` | < 50 μs | > 20,000 ops/s | < 100 KB | | `make_path_nodes()` | < 5 ms (100 components) | > 200 ops/s | < 10 MB | | `render_path_nodes()` | < 2 ms (100 components) | > 500 ops/s | < 5 MB | | `_walk_tree()` | < 1 ms (100 components) | > 1,000 ops/s | < 1 MB | ### Scalability Requirements - **Component Count**: Linear scaling up to 10,000 components - **Tree Depth**: Support for 20+ levels of nesting - **Concurrency**: Thread-safe operations for parallel processing - **Memory**: Efficient memory usage for large component trees ## API Contracts ### Function Signatures ```python def make_traversable(component: Any, asset: str) -> Traversable: ... def make_path_nodes(target: Node, component: Any) -> Node: ... def render_path_nodes(tree: Node, target: PurePosixPath, strategy: RenderStrategy | None = None) -> Node: ... def path_nodes(func_or_method: Callable[P, R]) -> Callable[P, R]: ... ``` ### Error Handling - **FileNotFoundError**: Raised when assets don't exist - **TypeError**: Raised for invalid component types - **ModuleNotFoundError**: Raised for missing packages - **ImportError**: Raised for package import issues ### Type Safety - Comprehensive type hints using PEP 604 syntax - IDE autocomplete support - Static type checking with `ty` - Runtime type validation where appropriate ## Path Resolution Specifications ### Package Path Format ``` package:resource/path ``` - **Package**: Python package name (dotted names supported) - **Resource Path**: Path within package resources - **Separator**: Colon (`:`) character - **Examples**: `mypackage:static/styles.css`, `my.package:images/logo.png` ### Relative Path Formats 1. **Plain**: `static/styles.css` 2. **Explicit Current**: `./static/styles.css` 3. **Parent Directory**: `../shared/common.css` ### Path Detection Algorithm ```python def _detect_path_type(asset: str) -> Literal["package", "relative"]: return "package" if ":" in asset else "relative" ``` ## Tree Transformation Specifications ### Element Processing Rules 1. **`` elements**: Transform `href` attributes 2. **`