Pikru Codebase Organization
Top-Level Structure
src/ - Main pikru library (parsing and rendering)
crates/ - Supporting crates
vendor/pikchr-c/ - Original C implementation and test files
examples/ - Example programs
tests/ - Integration tests
Main Library (src/)
Entry Point
src/lib.rs - Public API, exports key types and functions
Parsing
src/parse.rs - Parser implementation (statement parsing, token handling)
src/ast.rs - AST types (Statement, Expr, ObjectClass, etc.)
src/types.rs - Core types (ClassName, Direction, EdgePoint, etc.)
Rendering
src/render/mod.rs - Main renderer logic
- Object placement and geometry
- Text positioning (ljust/rjust logic at lines 1265-1550)
- Variable scope and context management
src/render/eval.rs - Expression evaluation (positions, scalars, variables)
src/render/svg.rs - SVG generation (converts shapes to SVG elements)
src/render/geometry.rs - Shape geometry (boxes, circles, paths, files)
src/render/shapes.rs - Shape rendering (specific shape implementations)
src/render/types.rs - Render types (PObject, Style, PositionedText, etc.)
src/render/path_builder.rs - Path construction (line/arrow building)
src/render/context.rs - Render context (variable scopes, state)
src/render/defaults.rs - Default values (line width, font size, etc.)
Error Handling
src/errors.rs - Error types and reporting
src/macros.rs - Helper macros
Supporting Crates
crates/pikru-compare/
SVG comparison utilities for testing
src/lib.rs - Core comparison logic
compare_outputs() - Main comparison function
CompareResult::is_match() - Determines if test passes
- Handles error matching, SVG parsing, tolerance
- Used by: test harness, MCP server
crates/pikru-mcp/
MCP server for test running
src/tools.rs - MCP tool implementations
run_pikru_test() - Run single test, returns comparison
list_pikru_tests() - List available tests
debug_pikru_test() - Run with trace output
src/main.rs - MCP server entry point
Test Files
Location
vendor/pikchr-c/tests/*.pikchr - Test input files from C implementation
Categories
test01-test81 - Numbered feature tests
autochop*.pikchr - Arrow chopping tests
- Other specialized tests
Common Debugging Paths
Text Positioning Issues
- Check
src/render/mod.rs:1265-1550 - ljust/rjust calculation
- Check
src/render/svg.rs:294 - Text anchor assignment
- Check
src/render/types.rs - PositionedText structure
Rendering Issues
- Check
src/render/shapes.rs - Shape-specific rendering
- Check
src/render/geometry.rs - Geometric calculations
- Check
src/render/svg.rs - SVG element generation
Parsing Issues
- Check
src/parse.rs - Parser logic
- Check
src/ast.rs - AST node definitions
Test Comparison Issues
- Check
crates/pikru-compare/src/lib.rs - Comparison logic
- Check tolerance constants (FLOAT_TOLERANCE, SIMILARITY_THRESHOLD)
Key Code References (cref comments)
Many functions include // cref: comments pointing to the original C implementation:
- Format:
// cref: function_name (pikchr.c:line_number)
- Use these to cross-reference with C implementation when debugging
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: codebase-layout3description: Codebase organization for pikru. Use when you need to find where specific functionality lives. Use when this capability is needed.4---56# Pikru Codebase Organization78## Top-Level Structure910- `src/` - Main pikru library (parsing and rendering)11- `crates/` - Supporting crates12- `vendor/pikchr-c/` - Original C implementation and test files13- `examples/` - Example programs14- `tests/` - Integration tests1516## Main Library (`src/`)1718### Entry Point19- `src/lib.rs` - Public API, exports key types and functions2021### Parsing22- `src/parse.rs` - **Parser implementation** (statement parsing, token handling)23- `src/ast.rs` - **AST types** (Statement, Expr, ObjectClass, etc.)24- `src/types.rs` - **Core types** (ClassName, Direction, EdgePoint, etc.)2526### Rendering27- `src/render/mod.rs` - **Main renderer logic**28 - Object placement and geometry29 - Text positioning (**ljust/rjust logic at lines 1265-1550**)30 - Variable scope and context management31- `src/render/eval.rs` - **Expression evaluation** (positions, scalars, variables)32- `src/render/svg.rs` - **SVG generation** (converts shapes to SVG elements)33- `src/render/geometry.rs` - **Shape geometry** (boxes, circles, paths, files)34- `src/render/shapes.rs` - **Shape rendering** (specific shape implementations)35- `src/render/types.rs` - **Render types** (PObject, Style, PositionedText, etc.)36- `src/render/path_builder.rs` - **Path construction** (line/arrow building)37- `src/render/context.rs` - **Render context** (variable scopes, state)38- `src/render/defaults.rs` - **Default values** (line width, font size, etc.)3940### Error Handling41- `src/errors.rs` - Error types and reporting42- `src/macros.rs` - Helper macros4344## Supporting Crates4546### `crates/pikru-compare/`47**SVG comparison utilities for testing**48- `src/lib.rs` - Core comparison logic49 - `compare_outputs()` - **Main comparison function**50 - `CompareResult::is_match()` - Determines if test passes51 - Handles error matching, SVG parsing, tolerance52- Used by: test harness, MCP server5354### `crates/pikru-mcp/`55**MCP server for test running**56- `src/tools.rs` - MCP tool implementations57 - `run_pikru_test()` - Run single test, returns comparison58 - `list_pikru_tests()` - List available tests59 - `debug_pikru_test()` - Run with trace output60- `src/main.rs` - MCP server entry point6162## Test Files6364### Location65`vendor/pikchr-c/tests/*.pikchr` - Test input files from C implementation6667### Categories68- `test01`-`test81` - Numbered feature tests69- `autochop*.pikchr` - Arrow chopping tests70- Other specialized tests7172## Common Debugging Paths7374### Text Positioning Issues751. Check `src/render/mod.rs:1265-1550` - ljust/rjust calculation762. Check `src/render/svg.rs:294` - Text anchor assignment773. Check `src/render/types.rs` - PositionedText structure7879### Rendering Issues801. Check `src/render/shapes.rs` - Shape-specific rendering812. Check `src/render/geometry.rs` - Geometric calculations823. Check `src/render/svg.rs` - SVG element generation8384### Parsing Issues851. Check `src/parse.rs` - Parser logic862. Check `src/ast.rs` - AST node definitions8788### Test Comparison Issues891. Check `crates/pikru-compare/src/lib.rs` - Comparison logic902. Check tolerance constants (FLOAT_TOLERANCE, SIMILARITY_THRESHOLD)9192## Key Code References (cref comments)9394Many functions include `// cref:` comments pointing to the original C implementation:95- Format: `// cref: function_name (pikchr.c:line_number)`96- Use these to cross-reference with C implementation when debugging9798---99> Converted and distributed by [TomeVault](https://tomevault.io/claim/bearcove) — claim your Tome and manage your conversions.100<!-- tomevault:4.0:skill_md:2026-04-11 -->