Genotype
A programming language that transpiles into idiomatic TypeScript, Rust, and Python types, enabling effortless type-safe interop across different programming languages.
Genotype is a specialized programming language designed for teams that work across multiple technology stacks—such as a TypeScript front-end and a Rust back-end. Created by Sasha Koss, it provides a unified way to define data structures and types that can be effortlessly transpiled into idiomatic code for TypeScript, Rust, and Python. By acting as a central source of truth for schemas, it ensures type-safe interop and consistency across heterogeneous environments without forcing developers into a specific ecosystem or heavy runtime overhead.
Genotype allows developers to define complex data structures, including recursive types and generics, in a clean, concise language. These definitions are stored in .type files and processed by the Genotype CLI to generate idiomatic type definitions, interfaces, or schemas in the target languages. It integrates seamlessly with existing workflows by adapting to target-specific idioms, such as Pydantic for Python, Serde for Rust, and Zod for TypeScript, while supporting optional target-specific annotations for fine-tuned control over the generated code.
Some of the key features are:
- Cross-Language Transpilation: Generates idiomatic code for TypeScript, Rust, and Python from a single source of truth.
- Language Support: Includes first-class support for primitives, branded primitives, unions, composite objects, arrays, tuples, and records.
- Recursive Type Support: Handles recursive data structures automatically with necessary target-specific indirection.
- Generic Types: Allows the definition and composition of generic types for maximum reuse.
- AI Agent-Ready: Provides specialized skills, documentation indexes (llms.txt), and code breadcrumbs designed for AI coding assistants.
- Minimal Runtime: Focuses on generating clean, native code rather than imposing an heavy runtime or specific transport format.
- Customizable Annotations: Supports metadata to control serialization behavior or target-specific naming conventions.
Developers use the Genotype CLI (gt) to initialize a project, which generates a genotype.toml configuration file. They then define their data models in .type files within the source directory. Once defined, the gt build command processes these files to generate the corresponding code in the configured output directories for each target language. The CLI also includes commands for managing project skills and integration with development environments, ensuring a streamlined developer experience throughout the software lifecycle.
Some common use cases include:
- Full-Stack Type Safety: Maintaining shared API models between a React front-end and a Rust back-end to prevent runtime serialization errors.
- API Client Generation: Creating consistent client libraries for internal APIs across multiple programming languages simultaneously.
- Data Migration: Facilitating gradual migration between different programming languages or data-handling standards in large systems.
- API Documentation: Using Genotype schemas as a human-readable and machine-processable source of truth for internal data contracts.