{"id":13847437,"url":"https://github.com/hardyscc/nestjs-cqrs-starter","last_synced_at":"2025-04-05T09:07:29.326Z","repository":{"id":36997910,"uuid":"253257569","full_name":"hardyscc/nestjs-cqrs-starter","owner":"hardyscc","description":"NestJS CQRS Microservices Starter Project","archived":false,"fork":false,"pushed_at":"2024-03-28T04:03:30.000Z","size":4897,"stargazers_count":399,"open_issues_count":6,"forks_count":55,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-12T18:24:49.811Z","etag":null,"topics":["apollo","cqrs","ddd","event-sourcing","eventstore","federation","graphql","microservices","nestjs","nodejs","typegraphql","typeorm"],"latest_commit_sha":null,"homepage":null,"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/hardyscc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-05T14:44:16.000Z","updated_at":"2024-10-09T10:05:36.000Z","dependencies_parsed_at":"2024-10-25T18:28:45.199Z","dependency_job_id":"00f75dc9-bf20-4701-9f64-0d6db86d24ce","html_url":"https://github.com/hardyscc/nestjs-cqrs-starter","commit_stats":{"total_commits":1028,"total_committers":6,"mean_commits":"171.33333333333334","dds":"0.024319066147859947","last_synced_commit":"dd4886c552fa100c6f6b35794cfc07e0e97366b2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-cqrs-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-cqrs-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-cqrs-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-cqrs-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardyscc","download_url":"https://codeload.github.com/hardyscc/nestjs-cqrs-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312078,"owners_count":20918344,"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":["apollo","cqrs","ddd","event-sourcing","eventstore","federation","graphql","microservices","nestjs","nodejs","typegraphql","typeorm"],"created_at":"2024-08-04T18:01:20.542Z","updated_at":"2025-04-05T09:07:29.292Z","avatar_url":"https://github.com/hardyscc.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# NestJS CQRS Microservices Starter\n\n## Description\n\nA starter project featuring an advanced microservice pattern with GraphQL, based on Domain-Driven Design (DDD) using the command query responsibility segregation (CQRS) design pattern.\n\n## Technologies\n\n- [GraphQL](https://graphql.org/)\n- [Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction/)\n- [NestJS](https://docs.nestjs.com/)\n- [NestJS GraphQL](https://docs.nestjs.com/graphql/quick-start)\n- [NestJS Federation](https://docs.nestjs.com/graphql/federation)\n- [NestJS TypeORM](https://docs.nestjs.com/techniques/database)\n- [NestJS CQRS](https://docs.nestjs.com/recipes/cqrs)\n- [NestJS Event Store](https://github.com/juicycleff/nestjs-event-store)\n\n## Installation\n\n**Please use the `nest-v7` branch, the `master` branch still not working properly.**\n\n```bash\ngit clone -b nest-v7 https://github.com/hardyscc/nestjs-cqrs-starter.git \u003cYour_Project_Name\u003e\ncd \u003cYour_Project_Name\u003e\n\nnpm install\n```\n\n## Usage\n\n### Start MySQL\n\nStart MySQL docker instance.\n\n```bash\ndocker run -d -e \"MYSQL_ROOT_PASSWORD=Admin12345\" -e \"MYSQL_USER=usr\" -e \"MYSQL_PASSWORD=User12345\" -e \"MYSQL_DATABASE=development\" -e \"MYSQL_AUTHENTICATION_PLUGIN=mysql_native_password\" -p 3306:3306 --name some-mysql bitnami/mysql:8.0.19\n```\n\nConnect using MySQL docker instance command line.\n\n```bash\ndocker exec -it some-mysql mysql -uroot -p\"Admin12345\"\n```\n\nCreate the Databases for testing\n\n```sql\nCREATE DATABASE service_user;\nGRANT ALL PRIVILEGES ON service_user.* TO 'usr'@'%';\n\nCREATE DATABASE service_account;\nGRANT ALL PRIVILEGES ON service_account.* TO 'usr'@'%';\nFLUSH PRIVILEGES;\n```\n\nClean up all data if needed to re-testing again\n\n```sql\nDELETE FROM service_account.ACCOUNT;\nDELETE FROM service_user.USER;\n```\n\n### Start EventStore\n\n```bash\ndocker run --name some-eventstore -d -p 2113:2113 -p 1113:1113 eventstore/eventstore:release-5.0.9\n```\n\nCreate the Persistent Subscriptions\n\n```bash\ncurl -L -X PUT \"http://localhost:2113/subscriptions/%24svc-user/account\" \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Basic YWRtaW46Y2hhbmdlaXQ=\" \\\n  -d \"{}\"\n\ncurl -L -X PUT \"http://localhost:2113/subscriptions/%24svc-account/user\" \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Basic YWRtaW46Y2hhbmdlaXQ=\" \\\n  -d \"{}\"\n```\n\n### Start the microservices\n\n```bash\n# Start the user service\nnest start service-user\n\n# Start the account service\nnest start service-account\n\n# start the gateway\nnest start gateway\n```\n\n## Testing\n\nGoto GraphQL Playground - http://localhost:3000/graphql\n\n### Create a user with a default saving account\n\n```graphql\nmutation {\n  createUser(input: { name: \"John\" }) {\n    id\n    name\n  }\n}\n```\n\nOR\n\n```bash\ncurl -X POST -H 'Content-Type: application/json' \\\n-d '{\"query\": \"mutation { createUser(input: { name: \\\"John\\\" }) { id name } }\"}' \\\nhttp://localhost:3000/graphql\n```\n\nYou should see something like this\n\n1. Under `service-user` console\n\n   ```sql\n   Async CreateUserHandler... CreateUserCommand\n   query: START TRANSACTION\n   query: INSERT INTO `USER`(`id`, `name`, `nickName`, `status`) VALUES (?, ?, DEFAULT, DEFAULT) -- PARAMETERS: [\"4d04689b-ef40-4a08-8a27-6fa420790ddb\",\"John\"]\n   query: SELECT `User`.`id` AS `User_id`, `User`.`status` AS `User_status` FROM `USER` `User` WHERE `User`.`id` = ? -- PARAMETERS: [\"4d04689b-ef40-4a08-8a27-6fa420790ddb\"]\n   query: COMMIT\n   Async ActivateUserHandler... ActivateUserCommand\n   query: UPDATE `USER` SET `status` = ? WHERE `id` IN (?) -- PARAMETERS: [\"A\",\"4d04689b-ef40-4a08-8a27-6fa420790ddb\"]\n   ```\n\n1. under `service-account` console\n\n   ```sql\n   Async CreateAccountHandler... CreateAccountCommand\n   query: START TRANSACTION\n   query: INSERT INTO `ACCOUNT`(`id`, `name`, `balance`, `userId`) VALUES (?, ?, DEFAULT, ?) -- PARAMETERS: [\"57c3cc9e-4aa9-4ea8-8c7f-5d4653ee709f\",\"Saving\",\"4d04689b-ef40-4a08-8a27-6fa420790ddb\"]\n   query: SELECT `Account`.`id` AS `Account_id`, `Account`.`balance` AS `Account_balance` FROM `ACCOUNT` `Account` WHERE `Account`.`id` = ? -- PARAMETERS: [\"57c3cc9e-4aa9-4ea8-8c7f-5d4653ee709f\"]\n   query: COMMIT\n   ```\n\n### Query the users\n\n```graphql\nquery {\n  users {\n    id\n    name\n    accounts {\n      id\n      name\n      balance\n    }\n  }\n}\n```\n\nOR\n\n```bash\ncurl -X POST -H 'Content-Type: application/json' \\\n-d '{\"query\": \"query { users { id name accounts { id name balance } } }\"}' \\\nhttp://localhost:3000/graphql\n```\n\nOutput :\n\n```JSON\n{\n  \"data\": {\n    \"users\": [\n      {\n        \"id\": \"4d04689b-ef40-4a08-8a27-6fa420790ddb\",\n        \"name\": \"John\",\n        \"accounts\": [\n          {\n            \"id\": \"57c3cc9e-4aa9-4ea8-8c7f-5d4653ee709f\",\n            \"name\": \"Saving\",\n            \"balance\": 0\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardyscc%2Fnestjs-cqrs-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardyscc%2Fnestjs-cqrs-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardyscc%2Fnestjs-cqrs-starter/lists"}