{"id":16328996,"url":"https://github.com/tokilabs/plow","last_synced_at":"2025-05-02T17:33:31.707Z","repository":{"id":24005844,"uuid":"97770771","full_name":"tokilabs/plow","owner":"tokilabs","description":"Library for building DDD, ES and CQRS projects with TypeScript on Node","archived":false,"fork":false,"pushed_at":"2022-12-07T09:49:59.000Z","size":1113,"stargazers_count":11,"open_issues_count":23,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-11T14:25:08.944Z","etag":null,"topics":["cqrs","cqrs-es","cqrs-framework","ddd","ddd-architecture","ddd-patterns","event-sourcing","framework"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tokilabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-19T23:46:27.000Z","updated_at":"2023-06-02T15:50:10.000Z","dependencies_parsed_at":"2023-01-14T00:12:55.114Z","dependency_job_id":null,"html_url":"https://github.com/tokilabs/plow","commit_stats":null,"previous_names":["cashfarm/plow"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokilabs%2Fplow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokilabs%2Fplow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokilabs%2Fplow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokilabs%2Fplow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokilabs","download_url":"https://codeload.github.com/tokilabs/plow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224324406,"owners_count":17292521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cqrs","cqrs-es","cqrs-framework","ddd","ddd-architecture","ddd-patterns","event-sourcing","framework"],"created_at":"2024-10-10T23:14:38.408Z","updated_at":"2024-11-12T18:10:03.039Z","avatar_url":"https://github.com/tokilabs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Plow\n\nGet the soil read to grow awesomeness :)\n\n## Documentation (Can't call it a proper doc, but here it goes)\n\n### The building blocks\n\n### Domain Events\n\nEvents represent change. Specifically a change that has already happened. They are immutable. Events are used inside Entities\nto apply the change to it's internal state and are propagated throughout the system to notify interested parties that something happened.\n\nHere's is a simple event implementation that represents the fact that a task was completed:\n\n```\nimport { Guid } from '@cashfarm/lang';\nimport { IDomainEvent } from '@cashfarm/plow';\n\n@DomainEvent\nclass TaskCompleted {\n    constructor(\n        public readonly taskId: Guid,\n        public readonly done: boolean\n    ) {}\n}\n```\n\n#### `Entity` and `AggregateRoot\u003cTId\u003e` classes\n\nYou model your domain using Entities and Aggregate Roots (AR). Only AR classes should be used to modify the system state.\nAggregate Roots should protect their internal state, expose semantic methods and modify their internal state by applying\nevents. Here's a simple example of what an AR should look like:\n\n```\nimport { Guid, isEmpty } from '@cashfarm/lang';\nimport { AggregateRoot, Apply, IDomainEvent, Event } from '@cashfarm/plow';\n\nimport { TaskCompleted } from '../events';\n\nclass Task extends AggregateRoot\u003cGuid\u003e {\n    private _description: string;\n    public get description(): string {\n        return this._description;\n    }\n\n    private _done: boolean;\n    public get done(): boolean {\n        return this._done;\n    }\n\n    constructor(desc: string) {\n        if (isEmpty(desc)) {\n            throw new DomainException('Task description cannot be empty');\n        }\n\n        this._desc = desc;\n        this._done = false;\n    }\n\n    public complete() {\n        this.applyChange(new TaskCompleted(true));\n    }\n\n    public [Apply(TaskCompleted)](evt: TaskCompleted) {\n        this._done = evt.done;\n    }\n}\n```\n\n### Repositories\n\nRepositories are how we call the classes that permanently store aggregate roots.\nIf you are using [GetEventStore](http://geteventstore.com) to store your aggregates, all you\nneed to do is extend the class `EventSourcedRepositoryOf\u003cTAggregate, TAggtId\u003e`;\n\nIf you are using Plow's container, you can simply inject `IEventStore` and `IEventBus` as\nthey are already configured in the inversify container.\n\n```\nexport class TaskRepository extends EventSourcedRepositoryOf\u003cTask, Guid\u003e {\n  constructor(\n    @inject(IEventStore) protected storage: IEventStore,\n    @inject(IEventBus) eventBus: IEventBus\n  ) {\n    super(storage, Campaign, eventBus);\n  }\n}\n```\n\n### Projections\n\nA projection class implements methods that handle events with the intent of projecting the data to\na read model. The read model is a denormalized databsed optimized for reading.\n\nHere's an example of a projection that sums up the number of completed tasks\n\n```\nimport { Handle } from '@cashfarm/plow';\n\nimport { TaskCompleted } from '../events';\n\n@Projection(TaskCompleted) // This decorator will register the projection in the event bus\nexport class TaskProjections {\n  constructor(\n      @inject(TaskStore) private tasks: TaskStore,\n      @inject(UserStore) private users: UserStore) {}\n\n  public [Handle(TaskCompleted)](event: TaskCompleted): void {\n    debug('Running projection for TaskCompleted');\n    const task = this.tasks.findById(event.taskId);\n    const user = this.users.findById(task.userId);\n\n    user.completedTasks += 1;\n\n    this.users.update(user);\n  }\n}\n```\n\n## Changelog\n\n### 0.4\n\n- Plow now has an internal inversify container for dependency injection\n- Use `@Projection`, `@Controller` and `@DomainEvent` to register the respective classes\n- No need for `[Symbol.EventLoader]()` and `[Symbol.MAPPER]()` methods\n\n## Roadmap\n\n### Sometime\n\n- create a generator (yeoman or vscode) to generate boilerplates for:\n    - Stores and Repositories\n    - events\n    - AggregateRoots\n    - Endpoints\n    - Projections\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokilabs%2Fplow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokilabs%2Fplow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokilabs%2Fplow/lists"}