# azure-samples/dapr-store architecture

> Architecture diagram of the GitHub repository azure-samples/dapr-store, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure-samples/dapr-store
- Repository: https://github.com/azure-samples/dapr-store

## Overview

##### Project Type & Purpose
- Dapr Store is a full-stack, microservices-based online store demonstrator built with Go microservices and a Vue.js single-page app, all orchestrated via Dapr.
- It shows key Dapr building blocks: service invocation, state management (Redis), pub/sub messaging, output bindings, and middleware.

##### File Structure Highlights
- **cmd/**: Four Go microservices (`cart`, `orders`, `products`, `users`) plus `frontend-host`. Each has `main.go`, `routes.go`, `spec/`, `impl/`, and `mock/`.
- **web/frontend/**: Vue.js SPA source, components, services, views, tests.
- **api/**: HTTP client test scripts, OpenAPI, TypeSpec, JSON schemas.
- **components/** & **deploy/**: Dapr component YAMLs, Helm charts, Kubernetes Bicep templates, Azure Container App configs.
- **build/** & **scripts/**: Dockerfiles, compose files, helper scripts for local/dev setups.

##### README Insights
- Confirms a monorepo using “Go Standard Project Layout”.
- Services interact via Dapr sidecar HTTP calls—automated mTLS, retries, discovery.
- State store is Redis; pub/sub topic (`orders-queue`) decouples cart → orders; output bindings for blob storage and SendGrid.

a. **Main Components**
- **Client Layer**: Browser running Vue SPA → served by `frontend-host` service
- **API Gateway**: NGINX reverse proxy (with Dapr sidecar)
- **Microservices** (each with its own Dapr sidecar):
- Cart service
- Orders service
- Products service
- Users service
- **Dapr Runtime**: Sidecar per service exposing `/v1.0/` APIs
- **State Store**: Redis (Dapr state component)
- **Pub/Sub Broker**: (e.g. Redis PubSub or Azure Service Bus)
- **Output Binding Targets**: Azure Blob, SendGrid
- **CI/CD & Deployment**: GitHub Actions, Helm/Kubernetes, Azure Container Apps

b. **Relationships & Interactions**
- User → (HTTP) → NGINX Gateway → Dapr sidecar → target service via Dapr Service Invocation
- Cart service:
- Reads/writes Cart state → Dapr State API → Redis
- Validates via Dapr Service Invocation → Products service
- Publishes new orders → Dapr Pub/Sub → orders-queue topic
- Orders service:
- Subscribes to orders-queue → Dapr Pub/Sub
- Persists orders → Dapr State API → Redis
- Optionally writes reports → Blob binding
- Sends emails → SendGrid binding
- Users service: state via Dapr State API → Redis
- Products service: internal SQLite DB (no Dapr state), invoked via Dapr Service Invocation
- Frontend-host: serves SPA static files; `/config` endpoint supplies runtime config

c. **Architectural Patterns & Principles**
- Microservices per bounded context
- Sidecar pattern (Dapr) to offload service-to-service concerns
- Event-driven communication with pub/sub for loose coupling
- API Gateway for unified ingress, auth enforcement, and routing
- Declarative infra with Helm charts, Bicep, and Dapr component YAML

d. **Key Technologies/Frameworks**
- Go + go-rest-api starter kit
- Vue.js SPA (Vue Router, Vite, Vitest)
- Dapr building blocks: Service Invocation, State, Pub/Sub, Bindings, Middleware
- Redis (state + pub/sub)
- SQLite (products catalog)
- NGINX as API gateway
- Kubernetes/Helm & Azure Container Apps

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["User<br/>Browser"]:::client
        SPA["Vue.js SPA"]:::client
        FrontendHost["frontend-host Service<br/>(/config endpoint)"]:::gateway
        SidecarFH["Dapr Sidecar"]:::sidecar
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        direction TB
        APIGateway["NGINX API Gateway"]:::gateway
        SidecarGW["Dapr Sidecar"]:::sidecar
    end

    %% Service Mesh
    subgraph "Microservices"
        direction TB
        subgraph "Cart Service"
            direction TB
            CartSvc["Cart Service"]:::service
            SidecarCart["Dapr Sidecar"]:::sidecar
        end
        subgraph "Orders Service"
            direction TB
            OrdersSvc["Orders Service"]:::service
            SidecarOrders["Dapr Sidecar"]:::sidecar
        end
        subgraph "Products Service"
            direction TB
            ProductsSvc["Products Service"]:::service
            SidecarProducts["Dapr Sidecar"]:::sidecar
            SQLiteDB["SQLite DB"]:::data
        end
        subgraph "Users Service"
            direction TB
            UsersSvc["Users Service"]:::service
            SidecarUsers["Dapr Sidecar"]:::sidecar
        end
    end

    %% Dapr Components
    subgraph "Dapr Components"
        direction TB
        RedisState["Redis State Store"]:::data
        RedisPubSub["Redis Pub/Sub"]:::data
        BlobBinding["Blob Storage Binding"]:::external
        EmailBinding["SendGrid Binding"]:::external
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        direction TB
        HelmChart["Helm Chart"]:::infra
        ContainerApp["Container Apps Bicep"]:::infra
        Compose["Docker Compose"]:::infra
        CIWorkflows["GitHub Actions"]:::infra
    end

    %% Client interactions
    Browser -->|HTTP| APIGateway
    APIGateway -->|dapr invoke| SidecarGW
    SidecarGW -->|invoke frontend-host| SidecarFH
    SidecarFH -->|serves SPA| SPA

    %% API Gateway to services
    SidecarGW -->|invoke Cart| SidecarCart
    SidecarGW -->|invoke Orders| SidecarOrders
    SidecarGW -->|invoke Products| SidecarProducts
    SidecarGW -->|invoke Users| SidecarUsers

    %% Cart service flows
    SidecarCart -->|invoke Products| SidecarProducts
    CartSvc -->|state API| SidecarCart
    SidecarCart -->|state| RedisState
    CartSvc -->|publish order| SidecarCart
    SidecarCart -->|pub/sub| RedisPubSub

    %% Orders service flows
    RedisPubSub -->|subscribe| SidecarOrders
    SidecarOrders -->|deliver event| OrdersSvc
    OrdersSvc -->|state API| SidecarOrders
    SidecarOrders -->|state| RedisState
    OrdersSvc -->|output binding| BlobBinding
    OrdersSvc -->|output binding| EmailBinding

    %% Products service flows
    ProductsSvc -->|direct DB| SQLiteDB

    %% Users service flows
    UsersSvc -->|state API| SidecarUsers
    SidecarUsers -->|state| RedisState

    %% CI/CD links
    HelmChart --> ContainerApp
    Compose --> HelmChart
    CIWorkflows --> Compose

    %% Click events
    click SPA "https://github.com/azure-samples/dapr-store/tree/main/web/frontend/"
    click FrontendHost "https://github.com/azure-samples/dapr-store/blob/main/cmd/frontend-host/main.go"
    click APIGateway "https://github.com/azure-samples/dapr-store/blob/main/scripts/local-gateway/gateway.conf"
    click CartSvc "https://github.com/azure-samples/dapr-store/tree/main/cmd/cart/"
    click OrdersSvc "https://github.com/azure-samples/dapr-store/tree/main/cmd/orders/"
    click ProductsSvc "https://github.com/azure-samples/dapr-store/tree/main/cmd/products/"
    click UsersSvc "https://github.com/azure-samples/dapr-store/tree/main/cmd/users/"
    click RedisState "https://github.com/azure-samples/dapr-store/blob/main/components/statestore.yaml"
    click RedisPubSub "https://github.com/azure-samples/dapr-store/blob/main/components/pubsub.yaml"
    click BlobBinding "https://github.com/azure-samples/dapr-store/blob/main/components/orders-report.yaml.sample"
    click EmailBinding "https://github.com/azure-samples/dapr-store/blob/main/components/orders-email.yaml.sample"
    click HelmChart "https://github.com/azure-samples/dapr-store/tree/main/deploy/helm/daprstore/"
    click ContainerApp "https://github.com/azure-samples/dapr-store/tree/main/deploy/container-app/"
    click Compose "https://github.com/azure-samples/dapr-store/blob/main/build/compose.yaml"
    click CIWorkflows "https://github.com/azure-samples/dapr-store/tree/main/.github/workflows/"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef gateway fill:#A9DFBF,stroke:#145A32,color:#0B5345
    classDef service fill:#F5B041,stroke:#7D6608,color:#512E5F
    classDef sidecar fill:#ABEBC6,stroke:#1D8348,color:#154360
    classDef data fill:#D7BDE2,stroke:#6C3483,color:#4A235A
    classDef external fill:#F5CBA7,stroke:#A04000,color:#512E5F
    classDef infra fill:#E5E7E9,stroke:#566573,color:#1C2833
```
