This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Baboon is a Domain Modeling Language (DML) compiler with schema evolution support. It compiles .baboon domain model files to multiple target languages (Scala, C#, Python, Rust, TypeScript, Kotlin, Java, Dart, Swift) with automatic JSON and UEBA codec generation.
This project uses mudyla for build orchestration.
# Format code
mdl :fmt
# Build the compiler native executable
mdl :build
# Run the full test suite
mdl :build :test
# Run specific test suites independently:
# - Regular ADT tests
mdl :build :test-gen-regular-adt :test-cs-regular :test-scala-regular :test-rust-regular :test-typescript-regular :test-kotlin-regular :test-kotlin-kmp-regular :test-java-regular :test-dart-regular :test-swift-regular
# - Wrapped ADT tests
mdl :build :test-gen-wrapped-adt :test-cs-wrapped :test-scala-wrapped :test-rust-wrapped :test-typescript-wrapped :test-kotlin-wrapped :test-kotlin-kmp-wrapped :test-java-wrapped :test-dart-wrapped :test-swift-wrapped
# - Manual/compatibility tests
mdl :build :test-gen-manual :test-gen-compat-scala :test-gen-compat-cs :test-gen-compat-rust :test-gen-compat-typescript :test-gen-compat-kotlin :test-gen-compat-kotlin-kmp :test-gen-compat-java :test-gen-compat-dart :test-gen-compat-swift :test-manual-cs :test-manual-scala :test-manual-rust :test-manual-typescript :test-manual-kotlin :test-manual-kotlin-kmp :test-manual-java :test-manual-dart :test-manual-swift
# Run complete build pipeline (format, build, test)
mdl :full-build
# Create distribution packages
mdl :build :mkdist# Compile the project
sbt compile
# Build native executable
sbt GraalVMNativeImage/packageBin
# Clean build
sbt clean compile
# Run all tests
sbt test
# Run specific test
sbt "testOnly *SpecificTestSpec"# Example compilation command
baboon \
--model-dir ./src/test/resources/baboon/ \
--meta-write-evolution-json baboon-meta.json \
--lock-file=./target/baboon.lock \
:cs \
--output ./output/cs \
:scala \
--output ./output/scala \
:rust \
--output ./output/rust \
:typescript \
--output ./output/ts \
:kotlin \
--output ./output/kotlin \
:java \
--output ./output/java \
:dart \
--output ./output/dart \
:swift \
--output ./output/swift-
Parser (
parser/package)- Parses
.baboonfiles using FastParse - Main entry:
BaboonParser.scala - Produces raw AST representations
- Parses
-
Type System (
typer/package)- Converts raw AST to typed AST
- Handles type resolution, inheritance, and validation
- Key classes:
BaboonTyper.scala,TypePasses.scala
-
Validators (
validator/package)- Ensures model consistency
- Checks evolution compatibility
- Validates foreign type mappings
-
Code Generators (
translator/package)csharp/- C# code generation with advanced deduplicationscala/- Scala code generationpython/- Python code generationrust/- Rust code generation with native types, serde derive, and custom UEBA binary codecstypescript/- TypeScript code generation with function-based JSON/UEBA codecskotlin/- Kotlin code generation with Jackson JSON codecs and UEBA binary codecsjava/- Java code generation with Jackson JSON codecs and UEBA binary codecsdart/- Dart code generation with dart:convert JSON codecs and UEBA binary codecsswift/- Swift code generation with JSONSerialization JSON codecs and UEBA binary codecs- Each generator produces source files, codec implementations and conversions from lower versions to higher ones
-
Runtime Support (
src/main/resources/baboon-runtime/)- Contains runtime libraries copied to generated code
- Separate implementations for each target language
Baboon files support:
- Structural inheritance: Using
+(union),-(subtraction),^(intersection) - Type categories: DTOs, ADTs, enums, foreign types, type aliases
- Collections: Lists, sets, dictionaries, options
- Annotations:
@root(entry points);: derived[json],: derived[ueba](request codecs) - Evolution: Automatic schema migration where possible
-
Multi-stage Compilation:
- Parse → Raw AST → Typed AST → Validated Model → Generated Code
- Each stage uses separate data structures for type safety
-
Dependency Injection:
- Uses distage for wiring components
- Allows easy testing and modularity
-
Codec Generation:
- Generates both JSON and custom binary (UEBA) codecs
- JSON: Circe (Scala), Newtonsoft.Json (C#), serde (Rust), Jackson (Kotlin, Java), dart:convert (Dart), JSONSerialization (Swift), custom (Python, TypeScript)
- Supports automatic evolution between versions
-
CLI Design:
- Multi-modal CLI with language-specific options
- Uses decline for command parsing
- Unit tests for individual components
- Integration tests with full compilation cycles
- Generated code tests in
test/cs-stub/,test/sc-stub/,test/py-stub/,test/rs-stub/,test/ts-stub/,test/kt-stub/,test/jv-stub/,test/dt-stub/, andtest/sw-stub/ - Cross-platform compatibility tests in
test/conv-test-{cs,sc,py,rs,ts,kt,jv,dt,sw}/(verifies JSON/UEBA interop across all languages) - Evolution tests validating schema migration
Parallel Test Execution: Test actions test-gen-regular-adt and test-gen-wrapped-adt can run in parallel. Each action:
- Creates an isolated temporary directory under
target/(test-regular/ortest-wrapped/) - Copies stub projects (excluding generated files and build artifacts) via rsync
- Generates code into the isolated directory
- Subsequent test actions run in these isolated directories
- Root Types: Only types marked with
@rootor transitively referenced by roots are included in output - Foreign Types: Require manual codec implementation in target languages
- Evolution: Not all schema changes are automatically evolvable
- Deduplication: C# generator performs sophisticated deduplication to reduce code size