{"id":18612496,"url":"https://github.com/alejandro945/cqrs-azure","last_synced_at":"2025-11-03T00:30:25.244Z","repository":{"id":170333141,"uuid":"606614778","full_name":"alejandro945/cqrs-azure","owner":"alejandro945","description":"CQRS stands for Command and Query Responsibility Segregation, a pattern that separates read and update operations for a data store. Implementing CQRS in your application can maximize its performance, scalability, and security.","archived":false,"fork":false,"pushed_at":"2023-02-26T03:45:14.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T02:21:32.675Z","etag":null,"topics":["azure-app-service","azure-application-insights","azure-functions","azure-sql-database","azure-storage","cqrs-pattern","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","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/alejandro945.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":"2023-02-26T02:32:19.000Z","updated_at":"2023-02-26T02:59:44.000Z","dependencies_parsed_at":"2023-07-17T13:22:19.482Z","dependency_job_id":null,"html_url":"https://github.com/alejandro945/cqrs-azure","commit_stats":null,"previous_names":["alejandro945/cqrs-azure"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fcqrs-azure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fcqrs-azure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fcqrs-azure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fcqrs-azure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejandro945","download_url":"https://codeload.github.com/alejandro945/cqrs-azure/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239403660,"owners_count":19632626,"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":["azure-app-service","azure-application-insights","azure-functions","azure-sql-database","azure-storage","cqrs-pattern","terraform"],"created_at":"2024-11-07T03:17:38.125Z","updated_at":"2025-11-03T00:30:25.215Z","avatar_url":"https://github.com/alejandro945.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CQRS Cloud Design pattern 💥\n\nCQRS separates reads and writes into different models, using commands to update data, and queries to read data.\n\n- Commands should be task-based, rather than data centric. (\"Book hotel room\", not \"set ReservationStatus to Reserved\").\n- Commands may be placed on a queue for asynchronous processing, rather than being processed synchronously.\n- Queries never modify the database. A query returns a DTO that does not encapsulate any domain knowledge.\n\nThe models can then be isolated, as shown in the following diagram, although that's not an absolute requirement.\n\n## Automatizing using Terraform\n\n### Install the Azure CLI tool\n\n```bash\ncurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash\n```\n\n### Authenticate using the Azure CLI\n\n```bash\naz login\naz login --use-device-code\n```\n\nYour browser will open and prompt you to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. Also, you can experiment a localhost redirection that will be blocked by firewall policies so in this case use device code command instead.\n\n```json\n[\n  {\n    \"cloudName\": \"AzureCloud\",\n    \"homeTenantId\": \"XXXX\",\n    \"id\": \"XXXX\",\n    \"isDefault\": true,\n    \"managedByTenants\": [],\n    \"name\": \"Azure for Students\",\n    \"state\": \"Enabled\",\n    \"tenantId\": \"XXXX\",\n    \"user\": {\n      \"name\": \"XXXX@u.icesi.edu.co\",\n      \"type\": \"user\"\n    }\n  }\n]\n```\n\nSet the account with the Azure CLI.\n\n```bash\naz account set --subscription \"\u003c\u003cid\u003e\u003e\"\n```\n\n### Create a Service Principal\n\nA Service Principal is an application within Azure Active Directory with the authentication tokens Terraform needs to perform actions on your behalf.\n\n```bash\naz ad sp create-for-rbac --role=\"Contributor\" --scopes=\"/subscriptions/\u003c\u003cid\u003e\u003e\"\n```\n\n```json\n{\n  \"appId\": \"XXXX\",\n  \"displayName\": \"XXXX\",\n  \"password\": \"XXXX\",\n  \"tenant\": \"XXXX\"\n}\n```\n\n### Set your environment variables\n\nHashiCorp recommends setting these values as environment variables rather than saving them in your Terraform configuration.\n\nIn your terminal, set the following environment variables. Be sure to update the variable values with the values Azure returned in the previous command.\n\n```bash\nexport ARM_CLIENT_ID=\"\u003c\u003cappId\u003e\u003e\"\nexport ARM_CLIENT_SECRET=\"\u003c\u003cpassword\u003e\u003e\"\nexport ARM_SUBSCRIPTION_ID=\"\u003c\u003cid\u003e\u003e\"\nexport ARM_TENANT_ID=\"\u003c\u003ctenant\u003e\u003e\"\n```\n\n### Write configuration\n\n#### Terraform Block\n\nThe terraform {} block contains Terraform settings, including the required providers Terraform will use to provision your infrastructure. For each provider, the source attribute defines an optional hostname, a namespace, and the provider type. Terraform installs providers from the Terraform Registry by default. In this example configuration, the azurerm provider's source is defined as hashicorp/azurerm, which is shorthand for registry.terraform.io/hashicorp/azurerm.\n\nYou can also define a version constraint for each provider in the required_providers block. The version attribute is optional, but we recommend using it to enforce the provider version. Without it, Terraform will always use the latest version of the provider, which may introduce **breaking changes**.\n\n#### Providers\n\nThe ```provider``` block configures the specified provider, in this case azurerm. A provider is a plugin that Terraform uses to create and manage your resources. You can define multiple provider blocks in a Terraform configuration to manage resources from different providers.\n\n#### Resource\n\nUse ```resource``` blocks to define components of your infrastructure. A resource might be a physical component such as a server, or it can be a logical resource such as a Heroku application.\n\n### Initialize your Terraform configuration\nInitialize your learn-terraform-azure directory in your terminal. The terraform commands will work with any operating system.\n\n```bash\nterraform init\n```\n\n### Apply and destroy commands 🚦\n\n```bash\nterraform apply\nterraform destroy\n```\n\n### Creation of SQL Sync service\n\n1. In each database create the share schema of the entities\n\n```sql\nCREATE TABLE Persons(\n    ID int NOT NULL,\n    FirstName varchar(255),\n    Age int,\n    PRIMARY KEY (ID)\n);\n```\n\n2. Go to your hub or source database (Write database) [Tutorial](https://learn.microsoft.com/en-us/azure/azure-sql/database/sql-data-sync-sql-server-configure?view=azuresql#add-sync-members).\n\n\n### Upload your code to azure function\n\n```bash\nfunc azure functionapp publish cqrs-command-varela #Inside command app folder\nfunc azure functionapp publish cqrs-query-varela #Inside query app folder\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandro945%2Fcqrs-azure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejandro945%2Fcqrs-azure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandro945%2Fcqrs-azure/lists"}