Skip to content

Add Smithy server code generator for Java, Go, Rust, and C++#960

Closed
aaylward wants to merge 4 commits intomainfrom
claude/smithy-server-generator-32zMD
Closed

Add Smithy server code generator for Java, Go, Rust, and C++#960
aaylward wants to merge 4 commits intomainfrom
claude/smithy-server-generator-32zMD

Conversation

@aaylward
Copy link
Copy Markdown
Collaborator

@aaylward aaylward commented Feb 7, 2026

Summary

This PR introduces a comprehensive Smithy server code generator that creates server implementations from AWS Smithy models for multiple languages (Java, Go, Rust, and C++). The implementation includes core model parsing, code generation utilities, and Bazel build rules for seamless integration.

Key Changes

  • Core Model Representation: Added SmithyModel, Service, Operation, Shape, Member, and Trait classes to represent parsed Smithy models with full support for shapes, operations, traits, and WebSocket operations
  • Code Generation Framework: Implemented CodeGenerator interface and CodeWriter utility class for language-agnostic code generation with proper indentation and formatting support
  • Name Conversion Utilities: Added NameUtils class with conversion functions (camelCase, PascalCase, snake_case, kebab-case) and keyword escaping for Java, Go, Rust, and C++
  • Bazel Build Rules: Created smithy.bzl with rules for smithy_java_server, smithy_go_server, smithy_rust_server, and smithy_cpp_server, plus a combined smithy_server macro for multi-language generation
  • Project Structure: Organized code into core/ (model and utilities), generators/ (language-specific generators), runtime/ (runtime libraries), bazel/ (build rules), and examples/ (sample models)
  • WebSocket Support: Added comprehensive WebSocket trait support including connect, disconnect, message handlers, subscribe, and publish operations
  • Documentation: Included detailed README with usage examples, project structure, generated code patterns, and dependency information

Notable Implementation Details

  • The Trait class provides helper methods for common Smithy traits (HTTP, documentation, validation, WebSocket)
  • CodeWriter supports flexible indentation management with stack-based tracking for nested blocks
  • NameUtils includes comprehensive keyword sets for all four target languages to prevent naming conflicts
  • The Bazel rules use a unified implementation pattern with language-specific configuration through attributes
  • Full support for HTTP protocol traits (method, URI, status codes) and WebSocket bidirectional communication patterns

https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo

claude and others added 4 commits February 4, 2026 14:35
Adds a comprehensive Smithy server code generator that supports multiple
target languages:

- Core: Smithy JSON AST parser and model representation
- Java: Service interfaces, handlers, routers with CompletableFuture
- Go: Interfaces, http.Handler implementations, JSON struct tags
- Rust: Async traits, Axum handlers, Serde derives
- C++: Abstract classes, nlohmann/json serialization

Features:
- Generates structures, enums, unions, and error types
- HTTP trait support for RESTful APIs
- Builder pattern for all structures
- Comprehensive test coverage for all generators
- Bazel build rules (smithy_java_server, etc.)
- Example petstore model

https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
Adds WebSocket support as a custom protocol extension to the Smithy
server generators for Java, Go, Rust, and C++.

New traits (smithy.ws namespace):
- @websocket: Marks a service as WebSocket-based
- @Onconnect: Handler for connection establishment
- @onDisconnect: Handler for connection termination
- @OnMessage: Handler for incoming messages with route parameter
- @subscribe/@publish: For pub/sub patterns

Core changes:
- Service.isWebSocket() to detect WebSocket services
- Operation WebSocket helpers (isWebSocketConnect, getWebSocketRoute, etc.)
- Trait constants for all WebSocket traits

Generator updates:
- Java: WebSocketHandler with session management, message routing, broadcast
- Go: gorilla/websocket handler with session map, broadcast, action routing
- Rust: axum WebSocket with tokio broadcast channels, futures streams
- C++: Abstract WebSocketSession, handler with mutex-protected sessions

Runtime additions (Java):
- WebSocketSession interface with test implementation
- WebSocketMessage with JSON parsing/serialization
- WebSocketHandler interface for lifecycle methods

Example:
- chat.smithy/chat.json: Real-time chat service with rooms, messages

Tests:
- Java: WebSocket service detection, handler generation, runtime classes
- Go: WebSocket handler generation, message routing, broadcast methods

https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
…yed apps

Analyzes MoonBase service patterns across Java, Go, Rust, and C++ domains
and documents gaps between Smithy-generated code and production features:
- Middleware/interceptor chains
- gRPC support
- OpenTelemetry metrics and tracing
- RFC 7807 error handling
- Rate limiting
- Configuration management
- Input validation patterns

https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying moonbase-flippy-mem with  Cloudflare Pages  Cloudflare Pages

Latest commit: dfe7552
Status:🚫  Build failed.

View logs

@aaylward aaylward closed this Feb 14, 2026
@aaylward aaylward deleted the claude/smithy-server-generator-32zMD branch February 14, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants