Skip to content

TypeSpec-Go Emitter - Project Structure and Architecture DiscussionΒ #2

@LarsArtmann

Description

@LarsArtmann

TypeSpec-Go Emitter - Project Structure and Architecture Discussion

🎯 Executive Summary

This issue defines the comprehensive project architecture for the TypeSpec-Go emitter, based on the complete emitter specification in doc/emitter.md. We need to establish a modern, scalable foundation using Mise task runner and TypeSpec emitter patterns.

πŸ“‹ Current State

  • βœ… Complete specification exists (doc/emitter.md)
  • βœ… Basic project structure (README, LICENSE, .gitignore)
  • ❌ Zero implementation - greenfield project
  • ❌ No development environment setup
  • ❌ No build system or testing framework

πŸ—οΈ Proposed Architecture

Option 1: Standard TypeSpec Emitter + Mise (RECOMMENDED)

typespec-go/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # Main exports
β”‚   β”œβ”€β”€ emitter.ts            # Core $onEmit function  
β”‚   β”œβ”€β”€ options.ts            # Configuration interface
β”‚   β”œβ”€β”€ lib.ts               # Utility functions
β”‚   β”œβ”€β”€ generators/
β”‚   β”‚   β”œβ”€β”€ models.ts        # Model/struct generation
β”‚   β”‚   β”œβ”€β”€ enums.ts         # Enum generation
β”‚   β”‚   β”œβ”€β”€ unions.ts        # Union/sealed interface
β”‚   β”‚   β”œβ”€β”€ operations.ts    # Service interface generation
β”‚   β”‚   └── utils.ts         # Helper functions
β”‚   β”œβ”€β”€ decorators/
β”‚   β”‚   └── go-decorators.ts # Go-specific decorators
β”‚   └── types/
β”‚       └── go-types.ts      # Type definitions
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ basic.test.ts
β”‚   β”œβ”€β”€ models.test.ts
β”‚   β”œβ”€β”€ enums.test.ts
β”‚   └── fixtures/
β”‚       β”œβ”€β”€ petstore/
β”‚       β”‚   └── main.tsp
β”‚       └── generated/            # Test output
β”œβ”€β”€ mise-tasks/              # Executable task scripts
β”‚   β”œβ”€β”€ build
β”‚   β”œβ”€β”€ test
β”‚   β”œβ”€β”€ lint
β”‚   └── dev
β”œβ”€β”€ mise.toml               # Mise configuration
β”œβ”€β”€ package.json            # npm dependencies only
β”œβ”€β”€ tsconfig.json
└── README.md

Why This Architecture Wins:

  1. TypeSpec Compliance - Follows official emitter patterns exactly
  2. Mise-Driven - Modern task management, no npm scripts
  3. Scalable - Clear separation of concerns
  4. Maintainable - Easy to extend and test
  5. Professional - Uses industry best practices

πŸ”§ Key Technology Decisions

Mise Task Runner

  • βœ… Replaces package.json scripts entirely
  • βœ… Task dependencies and conditional execution
  • βœ… Environment management and tool versioning
  • βœ… Source-based builds (only rebuild when needed)
  • βœ… Monorepo-ready for future scaling

TypeScript/Node.js Emitter

  • βœ… Official TypeSpec emitter patterns
  • βœ… AssetEmitter architecture
  • βœ… ESM modules and modern toolchain
  • βœ… Comprehensive testing with Vitest

Package Structure

# mise.toml
min_version = "2025.11.2"

[env]
NODE_ENV = "{{ env.NODE_ENV | default(value='development') }}"
PROJECT_NAME = "{{ config_root | basename }}"

[tools]
node = "lts"
typescript = "latest"
"npm:@typespec/compiler" = "latest"
"npm:@typespec/emitter-framework" = "latest"
"npm:vitest" = "latest"
"npm:eslint" = "latest"
"npm:prettier" = "latest"

[tasks.build]
description = "Build TypeScript to dist/"
sources = ["src/**/*.ts"]
outputs = ["dist/**"]
run = "tsc"

[tasks.test]
description = "Run test suite"
depends = ["build"]
run = "vitest run"

[tasks.lint]
description = "Run ESLint"
run = "eslint src/ test/ --max-warnings=0"

[tasks.dev]
description = "Development with watch mode"
run = "tsc --watch"

πŸ“Š Implementation Phases

Phase 1: Foundation (Critical Path)

  1. Initialize project with Mise and TypeScript
  2. Create basic emitter skeleton extending AssetEmitter
  3. Set up testing framework with TypeSpec integration
  4. Implement namespace-to-package mapping
  5. Basic model generation (struct generation)

Phase 2: Core Features (High Impact)

  1. Enum generation (string + iota strategies)
  2. Union generation (sealed interface pattern)
  3. Operation/service generation
  4. Go-specific decorators (@go.name, @go.package)
  5. Comprehensive testing with real examples

Phase 3: Advanced Features (Professional Polish)

  1. HTTP handler generation
  2. Validation logic (@minlength, @maxlength, etc.)
  3. Advanced TypeSpec features (template models, composition)
  4. Performance optimization and benchmarks
  5. Documentation and examples

🎯 Immediate Action Items

Priority 1: Project Setup

  • Create mise.toml with tasks and tool configuration
  • Initialize package.json with TypeSpec dependencies
  • Set up TypeScript configuration
  • Create basic emitter skeleton
  • Set up testing framework

Priority 2: Core Implementation

  • Implement namespace-to-package mapping
  • Create model struct generation
  • Add enum generation logic
  • Create union/sealed interface generation
  • Add basic operation support

Priority 3: Advanced Features

  • Implement Go-specific decorators
  • Add HTTP handler generation
  • Create comprehensive test suite
  • Add performance benchmarks
  • Create documentation and examples

πŸ€” Open Questions

Critical Blocker:

What is the exact TypeSpec emitter development pattern?

We need to understand:

  • How to extend @typespec/compiler with emitter classes
  • Standard project structure for TypeSpec emitters
  • Integration with TypeSpec CLI (tsp compile)
  • Core TypeScript dependencies and development patterns

Architecture Questions:

  1. Monorepo vs single package? - Start single, scale to monorepo later?
  2. Testing strategy? - How to integrate TypeSpec compilation in tests?
  3. Performance considerations? - Large TypeSpec files, memory usage?
  4. Error handling? - Diagnostic reporting, user experience?

πŸš€ Success Criteria

MVP Success:

  • βœ… Compiles basic TypeSpec to Go models/enums
  • βœ… Integrates with TypeSpec CLI
  • βœ… Has comprehensive test coverage
  • βœ… Follows emitter specification exactly

Production Success:

  • βœ… Handles complex TypeSpec features (unions, operations, decorators)
  • βœ… Generates production-ready Go code
  • βœ… Has real-world examples and documentation
  • βœ… Performance suitable for large projects

πŸ“š References

🏷️ Labels

  • architecture
  • project-structure
  • mise
  • typescript
  • typespec
  • foundation
  • good-first-issue

🎯 Call to Action

This issue is ready for immediate implementation. We have:

  • βœ… Complete specification to follow
  • βœ… Clear architecture defined
  • βœ… Modern tooling selected
  • βœ… Implementation phases outlined

Next Steps:

  1. Approve this architecture πŸ‘/πŸ‘Ž
  2. Resolve the TypeSpec emitter pattern question
  3. Begin Phase 1 implementation

Ready to build the best TypeSpec-Go emitter in the ecosystem! πŸš€

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions