I create Hexagonal Architecture based software with TypeScript or C#. The heart of Hexagonal Architecture is the Domain Model.
For example, for a user of application y
, the domain model might look like this:
// typescript
export interface UserEntity {
name: string;
email: string;
email: string;
someFunction(arg: string): something
}
This interface will be the driving force for all user use-cases
, ports
and adaptors
.
How would I model domain objects in a dynamic language like JavaScript?
4
Don’t let a type system interfere with building the concept of a “domain model.” There is no special way to do this in dynamic languages. Focus on the core concept of a domain model — business logic. Organize and group these business functions into modules. Object-oriented languages might call these “classes” or… well… “objects” in the case of JavaScript, because everything is an object in JavaScript. Even classes.
You need to clearly define what the business rules are to begin with. Only then can you organize them into cohesive modules. Use whatever structures the dynamic language has available. Just make sure your “domain model”:
- Enforces rules that must be true regardless of the user interface.
- Does not depend on types defined in other layers of the architecture.
- But may depend on the base level types and data structures inherent to the language.
Otherwise, just write code.