Skip to content
/ rimo Public

Rimo is an extensible set of utilities that helps you to build rich domain data models with TypeScript.

License

Notifications You must be signed in to change notification settings

thiagozf/rimo

Repository files navigation

rimo banner


Build rich domain models with Rimo!
Rimo is a set of utilities that helps you to implement a clean architecture in TypeScript.


Created by Thiago Zanivan and maintained with ❤️ by an amazing community.

Usage

import { AggregageRoot } from 'rimo'

// Create an aggregate root
class User extends AggregateRoot<{ email: string }> {
  get email() {
    return this.props.email
  }
}

// Define inputs and/or outputs
class CreateUserInput {
  @IsNotEmpty()
  @IsEmail()
  email!: string

  static populate = (data: any) => {
    return Object.assign(new CreateUserInput(), data)
  }
}

// Create a use case
import { CommandHandler, Use } from 'rimo'

class CreateUserCommand implements CommandHandler<CreateUserInput, User> {
  @Use(ValidateCommand)
  async handle(input: CreateUserInput): Promise<User> {
    const user: User = new User(input)
    // persist user, do other stuff
    return user
  }
}

// Keep your use cases clean with the help of middlewares
// to do things like validation
import { Middleware } from 'rimo'

class ValidateCommand implements Middleware<CreateUserInput> {
  async use(event: CreateUserInput) {
    const errors = await validate(event)
    if (errors.length > 0) {
      throw new Error('validation error')
    }
  }
}

// Use the stupid simple, yet powerful, pub/sub mechanism that Rimo
// provides to keep your application components nicely decoupled!
import { AfterCommand, CommandRunner } from 'rimo'

class CreateUserSubscriber {
  @AfterCommand(CreateUserCommand)
  async afterCreateUser(user: User, runner: CommandRunner) {
    // SendWelcomeEmail is another use case
    await runner.run(SendWelcomeEmail, user)
  }
}

Credits

Thanks goes to these wonderful people (emoji key):


Thiago Zanivan

💻 🔧

This project follows the all-contributors specification. Contributions of any kind are welcome!

About

Rimo is an extensible set of utilities that helps you to build rich domain data models with TypeScript.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published