This document provides a comprehensive guide to the typia library codebase for Claude AI developers and contributors. Typia is a TypeScript transformer library that generates super-fast runtime validators and provides advanced features for TypeScript type manipulation.
Typia is a revolutionary TypeScript transformer library that converts pure TypeScript types into runtime functions. It achieves:
- 20,000x faster runtime validation than
class-validator - 200x faster JSON serialization than
class-transformer - Seamless LLM function calling integration (including Claude)
- Protocol Buffer encoding/decoding
- Random data generation
Instead of defining schemas separately, typia uses pure TypeScript types and transforms them at compile-time into optimized runtime functions.
src/
├── transformers/ # TypeScript AST transformation logic
├── programmers/ # Code generation for different features
├── factories/ # Metadata and AST node creation utilities
├── schemas/ # Schema definitions and metadata types
├── tags/ # Validation tag definitions
├── typings/ # TypeScript type utilities
├── utils/ # General utilities
├── executable/ # CLI tools
├── internal/ # Internal implementation details
├── json.ts # JSON schema and serialization
├── llm.ts # LLM function calling (including Claude)
├── protobuf.ts # Protocol Buffer support
├── functional.ts # Functional programming utilities
├── http.ts # HTTP-related functionality
├── misc.ts # Miscellaneous utilities
├── notations.ts # Naming convention transformations
├── reflect.ts # Runtime reflection
└── module.ts # Main export module
Typia provides first-class support for Claude AI through its LLM module (src/llm.ts):
- OpenAI GPT:
IChatGptSchema - Anthropic Claude:
IClaudeSchema⭐ - High-Flyer DeepSeek:
IDeepSeekSchema - Google Gemini:
IGeminiSchema - Meta Llama:
ILlamaSchema
import typia from "typia";
const claudeController = typia.llm.controller<BbsArticleService, "claude">(
"bbs",
new BbsArticleService(),
);
// The controller automatically generates Claude-compatible schemas
const application = claudeController.application;
// Execute functions called by Claude
const result = await claudeController.execute.create(parameters);The heart of typia's compile-time transformation:
CallExpressionTransformer.ts: Transformstypia.xxx()callsFileTransformer.ts: Main file transformation orchestratorNodeTransformer.ts: AST node transformation logicImportTransformer.ts: Handles import transformationsfeatures/: Feature-specific transformers
Code generators for different typia features:
AssertProgrammer.ts: Generates assertion functionsIsProgrammer.ts: Generates type guard functionsValidateProgrammer.ts: Generates validation functionsRandomProgrammer.ts: Generates random data functionsjson/: JSON-related programmersllm/: LLM function calling programmersprotobuf/: Protocol Buffer programmers
Utilities for creating metadata and AST nodes:
MetadataFactory.ts: Creates type metadataJsonMetadataFactory.ts: JSON schema metadataProtobufFactory.ts: Protocol Buffer metadataExpressionFactory.ts: TypeScript expression creationStatementFactory.ts: TypeScript statement creation
Type definitions and metadata structures:
metadata/: Core metadata typesjson/: JSON schema typesprotobuf/: Protocol Buffer schema types
// These functions are transformed at compile-time:
typia.is<T>(input) // Type guard (returns boolean)
typia.assert<T>(input) // Assertion (throws on failure)
typia.validate<T>(input) // Detailed validation
typia.assertGuard<T>(input) // Type assertion guardGenerated Code Example:
// Input: typia.is<string>(input)
// Output: (input) => "string" === typeof inputtypia.json.schema<T>() // Generate JSON schema
typia.json.stringify<T>(obj) // Fast JSON serialization
typia.json.parse<T>(str) // Type-safe JSON parsingtypia.llm.application<Class, Model>() // Generate LLM schemas
typia.llm.controller<Class, Model>() // Create function controller
typia.llm.parameters<P, Model>() // Generate parameter schemas
typia.llm.schema<T, Model>() // Generate type schemastypia.protobuf.message<T>() // Generate .proto message
typia.protobuf.encode<T>(obj) // Encode to Uint8Array
typia.protobuf.decode<T>(buffer) // Decode from Uint8Arraytypia.random<T>(generator?) // Generate random data matching typepnpm install # Install dependencies
pnpm run build # Compile TypeScript and bundle
pnpm run dev # Development mode with watchingpnpm run test # Run all teststest/src/features and test/schemas directories contain extensive test suites with high LOC - be cautious when iterating through them.
pnpm run eslint # Lint code
pnpm run prettier # Format code
pnpm run eslint:fix # Auto-fix lint issues
pnpm run prettier:fix # Auto-format codeTypia analyzes TypeScript types at compile-time using the TypeScript Compiler API.
Types are converted into rich metadata structures that describe validation, serialization, and schema generation requirements.
Programmers generate optimized JavaScript code based on the metadata.
The generated code replaces the original typia.xxx() calls in the AST.
// Generate Claude-compatible function calling schema
const app = typia.llm.application<MyAPI, "claude">();
// The generated schema follows Claude's function calling format
interface ClaudeFunction {
name: string;
description: string;
input_schema: object; // Claude-specific schema format
}- API Controllers: Convert TypeScript classes to Claude function schemas
- Structured Output: Generate schemas for Claude's structured output
- Type Safety: Maintain TypeScript type safety in Claude interactions
- Validation: Validate Claude responses against TypeScript types
- Transformer: Add transformation logic in
src/transformers/features/ - Programmer: Implement code generation in
src/programmers/ - Factory: Add metadata generation in
src/factories/ - Tests: Add comprehensive tests (but be mindful of LOC in test directories)
- Follow TypeScript best practices
- Use the existing ESLint and Prettier configurations
- Document complex transformation logic
- Maintain backward compatibility
- Unit tests for individual components
- Integration tests for complete transformations
- Performance benchmarks for runtime functions
- LLM provider compatibility tests
src/llm.ts- Core LLM functionality and Claude integrationsrc/programmers/llm/- LLM-specific code generationsrc/schemas/json/- JSON schema types used by LLM featuressrc/transformers/features/llm/- LLM transformation logic
- TypeScript types →
MetadataFactory.ts - Metadata → LLM programmers
- Generated code → AST transformation
- Final output → Claude-compatible schemas
- Performance: Typia's transformations happen at compile-time, so runtime performance is exceptional
- Type Safety: Always use TypeScript types as the source of truth
- Schemas: Generated schemas are optimized for each LLM provider's format
- Debugging: Use the
devmode to see generated code during development - Compatibility: Test with multiple LLM providers to ensure broad compatibility
- GitHub Issues: Report bugs and request features
- Discord: Join the community for discussions
- Documentation: Comprehensive guides at typia.io
- Examples: Check the
examples/directory for usage patterns
This documentation serves as a starting point for understanding typia's architecture and Claude AI integration. The codebase is well-structured and heavily documented, making it accessible for contributors and users working with Claude AI function calling features.