Domain-Driven Design across Go and Node.js services
Domain-Driven Design across Go and Node.js services
The backend of this site is written in Go with DDD and hexagonal layering. The frontends are TypeScript. The same ideas apply on both sides if you keep the boundary between domain and technology explicit.
Bounded contexts first
Split by language of the business, not by database table. This project uses content, portfolio, engagement, identity and analytics. A post title belongs to content; a comment moderation state belongs to engagement.
The Go shape
Dependencies point inward. Domain packages define entities and repository interfaces; infrastructure implements them.
type PostRepository interface {
GetByID(ctx context.Context, id string) (*Post, error)
Save(ctx context.Context, p Post) error
}
Application services orchestrate use cases and own transaction boundaries. HTTP handlers only translate the outside world into commands and back.
The Node.js shape
In TypeScript the same port looks like an interface, with the implementation injected at the composition root.
export interface PostRepository {
getById(id: string): Promise<Post | null>
save(post: Post): Promise<void>
}
Share contracts, not code
Avoid trying to compile one domain model into two languages. Share the API contract — the JSON shapes and event names — and let each runtime own its implementation. Drift becomes visible at the boundary, where it is cheapest to fix.
Key takeaways
DDD is about boundaries and language, not package names. Keep the domain free of framework types in either runtime, and let use cases express what the system actually does.