{"id":19809506,"url":"https://github.com/space-code/cqrs","last_synced_at":"2025-10-09T03:33:23.133Z","repository":{"id":79213881,"uuid":"592629294","full_name":"space-code/cqrs","owner":"space-code","description":"The Command and Query Responsibility Segregation","archived":false,"fork":false,"pushed_at":"2024-12-25T17:54:31.000Z","size":342,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-09-27T17:36:10.879Z","etag":null,"topics":["cqrs","ios","macos","swift","swift-package-manager","tvos","watchos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/space-code.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-24T06:50:17.000Z","updated_at":"2025-05-24T07:57:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"80131a7d-eb56-4c54-bd92-57fbe374739e","html_url":"https://github.com/space-code/cqrs","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/space-code/cqrs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fcqrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fcqrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fcqrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fcqrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/space-code","download_url":"https://codeload.github.com/space-code/cqrs/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fcqrs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000714,"owners_count":26082911,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","ios","macos","swift","swift-package-manager","tvos","watchos"],"created_at":"2024-11-12T09:17:13.355Z","updated_at":"2025-10-09T03:33:23.110Z","avatar_url":"https://github.com/space-code.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![cqrs: The Command and Query Responsibility Segregation](https://raw.githubusercontent.com/space-code/cqrs/main/Resources/cqrs.png)\n\n\u003ch1 align=\"center\" style=\"margin-top: 0px;\"\u003ecqrs\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/space-code/cqrs/blob/main/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/space-code/cqrs?style=flat\"\u003e\u003c/a\u003e \n\u003ca href=\"https://swiftpackageindex.com/space-code/cqrs\"\u003e\u003cimg alt=\"Swift Compatibility\" src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fcqrs%2Fbadge%3Ftype%3Dswift-versions\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://swiftpackageindex.com/space-code/cqrs\"\u003e\u003cimg alt=\"Platform Compatibility\" src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fcqrs%2Fbadge%3Ftype%3Dplatforms\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://github.com/space-code/cqrs\"\u003e\u003cimg alt=\"CI\" src=\"https://github.com/space-code/cqrs/actions/workflows/ci.yml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/apple/swift-package-manager\" alt=\"CQRS on Swift Package Manager\" title=\"cqrs on Swift Package Manager\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/space-code/cqrs\"\u003e\u003cimg alt=\"CodeCov\" src=\"https://codecov.io/gh/space-code/cqrs/graph/badge.svg?token=TI0NEXLCTX\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n`cqrs` is an implementation of the command and query responsibility segregation in Swift.\n\n- [Usage](#usage)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Communication](#communication)\n- [Contributing](#contributing)\n- [Author](#author)\n- [License](#license)\n\n## Usage\n\n1. `ICommand` and `IQuery` contain data for use by an appropriate handler.\n\nCreate an instance of a command that conforms to `ICommand` or a query that conforms to `IQuery`, respectively:\n```swift\nimport CQRS\n\nfinal class ExampleCommand: ICommand {\n  // MARK: Properties\n \n  let value: Int\n \n  // MARK: Initialization\n  \n  init(value: Int) {\n    self.value = value\n  }\n}\n```\n\n```swift\nimport CQRS\n\nfinal class ExampleQuery: IQueue {\n    typealias Result = Int\n\n    // MARK: Properties\n\n    let value: Int\n\n    // MARK: Initialization\n\n    init(value: Int) {\n        self.value = value\n    }\n}\n```\n\n2. A command handler or a query handler contains the execution logic for a command or a query.\n\nCreate an instance of a command handler that conforms to `ICommandHandler` or a query handler that conforms to `IQueryHandler`, respectively:\n```swift\nimport CQRS\n\nfinal class ExampleCommandHandler: ICommandHandler {\n  typealias Command = ExampleCommand\n\n  // MARK: ICommandHandler\n\n  func execute(command: Command) throws {\n    // write the execution logic here\n  }\n}\n```\n\n```swift\nimport CQRS\n\nfinal class ExampleQueryHandler: IQueryHandler {\n    typealias Query = ExampleQuery\n\n    // MARK: IQueryHandler\n\n    func execute(query: Query) throws -\u003e Query.Result {\n        // write the execution logic here\n    }\n}\n```\n\n3. Register your handler implementation in the container:\n```swift\nimport CQRS\n\nlet container = DependencyContainer()\ncontainer.register { ExampleCommandHandler() }\n```\n\n```swift\nimport CQRS\n\nlet container = DependencyContainer()\ncontainer.register { ExampleQueryHandler() }\n```\n\n4. Create an instance of a `CommandDispatcher` or a `QueryDispatcher` with the created container, like this:\n```swift\nimport CQRS\n\nlet commandDispatcher = CommandDispatcher(container: container)\n```\n\n```swift\nimport CQRS\n\nlet commandDispatcher = QueryDispatcher(container: container)\n```\n\n5. Execute your command on `commandDispatcher` or `queryDispatcher`:\n```swift\nlet command = ExampleCommand()\n\ndo {\n  try commandDispatcher.execute(command: command)\n} catch {\n  // Handle an error.\n}\n```\n\n```swift\nlet query = ExampleCommand()\n\ndo {\n  let result = try queryDispatcher.execute(query: query)\n} catch {\n  // Handle an error.\n}\n```\n\n## Requirements\n- iOS 16.0+ / macOS 13+ / tvOS 16.0+ / watchOS 9.0+\n- Xcode 14.0\n- Swift 5.7\n\n## Installation\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `\ncqrs` does support its use on supported platforms.\n\nOnce you have your Swift package set up, adding `cqrs` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/space-code/cqrs.git\", .upToNextMajor(from: \"1.0.1\"))\n]\n```\n\n## Communication\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n## Contributing\nBootstrapping development environment\n\n```\nmake bootstrap\n```\n\nPlease feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!\n\n## Author\nNikita Vasilev, nv3212@gmail.com\n\n## License\ncqrs is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspace-code%2Fcqrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspace-code%2Fcqrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspace-code%2Fcqrs/lists"}