How codegen-sh/pink works
Project type and purpose
• This is an open-source, multi-crate Rust library and CLI tool (“Pink”) that implements a multi-lingual type analysis and refactoring engine.
• It provides build-time code generators (CST, AST, Python bindings) and run-time components (core SDK, incremental analyzer, CLI, Python FFI).
File structure
• Top-level crates:
– codegen-sdk-common, codegen-sdk-cst, codegen-sdk-ast, codegen-sdk-resolution
– codegen-sdk-cst-generator, codegen-sdk-ast-generator, codegen-bindings-generator
– codegen-sdk-analyzer
– languages/* (one crate per target language)
– bindings/python (Python FFI)
– src/main.rs (Pink CLI binary)
• Configuration and tooling:
– Cargo.toml, rust-toolchain, CI workflows, Insta snapshot tests, Netlify docs.
Extract architectural insights from the README
• Core pattern: modular monorepo with separation of concerns by crate.
• Build-time pipeline: generate CST → generate AST/queries → generate language bindings → compile language crates.
• Run-time pipeline: CLI or Python binding loads parsed caches → uses analyzer for incremental computation.
Main components
a. Build-time code generators (three crates)
• codegen-sdk-cst-generator
• codegen-sdk-ast-generator
• codegen-bindings-generator
b. Core library crates (Rust)
• codegen-sdk-common
• codegen-sdk-cst
• codegen-sdk-ast
• codegen-sdk-resolution
c. Language-specific crates
• languages/codegen-sdk-* (go, java, typescript, etc.)
d. Run-time engine
• codegen-sdk-analyzer
• Pink CLI (src/main.rs)
• Python binding (bindings/python)
e. External tools and services
• Cargo build, GitHub Actions CI, Insta snapshot testing
Relationships and interactions
• codegen-sdk-common feeds into cst, ast, resolution crates.
• codegen-sdk-cst and common feed into ast generator and ast crate.
• codegen-sdk-resolution uses ast and common.
• language crates depend on common + generated AST/CST.
• analyzer depends on all core crates.
• CLI binary uses analyzer and core crates.
• Python binding wraps core crates via FFI and exposes a Python API.
Architectural patterns and design principles
• Modular crate-per-responsibility design for isolation, parallel compilation, and testability.
• Build-time code generation pipeline decoupled from run-time analysis engine.
• Incremental re-computation pattern in codegen-sdk-analyzer for performance.
• FFI boundary between Rust core and Python.
• Clear labels (crate names, generator names, binary names)