# azure-samples/contoso-real-estate architecture

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

- Interactive diagram: https://gitdiagram.com/azure-samples/contoso-real-estate
- Repository: https://github.com/azure-samples/contoso-real-estate

## Overview

##### Project type and purpose
- This is a monorepo JavaScript reference architecture for a cloud‑native real estate application showcasing micro‑frontends and microservices on Azure. It includes:
- Frontends: Angular “portal”, Next.js “blog”
- Headless CMS: Strapi (“blog‑cms”)
- Backend services: Azure Functions (“api”), Fastify Stripe webhook (“stripe”), real‑time notifications (“notifications”)
- E2E and developer docs (“testing”, “docs”)
- Infrastructure defined in Bicep under `infra/`

##### File structure
- Top‑level:
- `.azdo/`, `.github/`, `infra/` for pipelines and Bicep modules
- `packages/` as npm workspaces containing each service or app
- `assets/`, `docs/`, `scripts/`
- Each `packages/*` folder follows a clear pattern: code, configuration, environment samples, Dockerfiles or function.json
- `infra/` subdivided into `core/` modules (compute, storage, database, pubsub, security) and `app/` modules for each component

##### Key architecture notes from README
- Uses Azure Static Web Apps for Angular portal
- Azure Container Apps for Next.js blog, Strapi CMS, Stripe service
- Azure Functions behind API Management for the portal API
- Databases: Cosmos DB (Mongo API) for portal, PostgreSQL for CMS, Blob Storage for assets
- Azure Event Grid / Web Pub-Sub for real‑time notifications
- CI/CD via Azure Developer CLI and GitHub Actions

##### Main components & their interactions
a. Frontend tier
- Portal (Angular) → Static Web Apps
- Blog (Next.js) → Container App
- CMS Admin (Strapi) → Container App
b. API tier
- Portal API → Azure Functions behind API Management
- Stripe webhook → Fastify in Container App
- Notifications service → Node server in Container/App Service + Web Pub‑Sub
c. Data tier
- Portal data → Cosmos DB (Mongo API)
- CMS data → Azure Database for PostgreSQL
- Media/uploads → Azure Blob Storage
d. Integration & messaging
- Stripe service → invokes Functions via APIM for payment validation
- Strapi → reads/writes PostgreSQL, stores files in Blob
- Event Grid/Web Pub‑Sub → push real‑time events to portal
e. DevOps & infra
- Bicep modules provisioning resources
- GitHub Actions/Azure DevOps pipelines for CI/CD

##### Architectural patterns & principles
- Micro‑frontends & microservices: separate deployable units per domain
- Serverless (Azure Functions) for stateless APIs
- Containerized services (Container Apps) for stateful or longer‑running processes
- API Gateway (APIM) for unified API surface, routing & policies
- Infrastructure as code (Bicep) organizing core vs. app modules
- Monorepo with npm workspaces for consistent dependency management

a. Sketch the Internet layer: three entry points (portal.contoso.com, blog.contoso.com, cms.contoso.com).
b. Azure Static Web App under portal, Azure Container App under blog and CMS.
h. Component with labels and annotate technologies (Angular, Next.js, Strapi, Fastify, Node.js).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User / Internet Layer
    subgraph "User / Internet"
        PortalBrowser["Browser: portal.contoso.com"]:::frontend
        BlogBrowser["Browser: blog.contoso.com"]:::frontend
        CMSBrowser["Browser: cms.contoso.com"]:::frontend
    end

    %% API Gateway Layer
    subgraph "API Gateway"
        APIM["Azure API Management"]:::infra
    end

    %% Compute Layer
    subgraph "Compute"
        SWA["Angular Portal\n(Static Web Apps)"]:::frontend
        BlogCA["Next.js Blog\n(Container App)"]:::frontend
        CMSCA["Strapi CMS\n(Container App)"]:::frontend
        Func["Portal API\n(Azure Functions)"]:::compute
        StripeCA["Stripe Webhook\n(Fastify Container)"]:::compute
        Notifications["Notifications Service\n(Container App)"]:::compute
    end

    %% Messaging / Events Layer
    subgraph "Messaging / Events"
        EventGrid["Azure Event Grid / Web Pub-Sub"]:::messaging
    end

    %% Data Layer
    subgraph "Data Tier"
        Cosmos["Cosmos DB\n(Mongo API)"]:::database
        Postgres["Azure Database\nfor PostgreSQL"]:::database
        Blob["Azure Blob Storage"]:::database
    end

    %% DevOps & Infra Layer
    subgraph "DevOps & Infra"
        E2E["E2E Tests (Playwright)"]:::infra
        Docs["Developer & Scenario Docs"]:::infra
        Azdo["Azure DevOps Pipelines"]:::infra
        GH["GitHub Actions"]:::infra
        InfraApp["Bicep Modules (app)"]:::infra
        InfraCore["Bicep Modules (core)"]:::infra
    end

    %% Connections
    PortalBrowser --> SWA
    BlogBrowser --> BlogCA
    CMSBrowser --> CMSCA

    SWA --> APIM
    BlogCA --> CMSCA
    CMSCA --> Postgres
    CMSCA --> Blob

    APIM --> Func
    Func --> Cosmos

    StripeCA --> APIM
    StripeCA --> Func

    Notifications --> EventGrid
    EventGrid --> SWA

    %% DevOps & Infra Relationships
    E2E --> SWA
    E2E --> BlogCA
    Docs --> SWA
    Docs --> CMSCA
    Azdo --> InfraApp
    Azdo --> InfraCore
    GH --> InfraApp
    GH --> InfraCore

    %% Click Events
    click SWA "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/portal"
    click BlogCA "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/blog"
    click CMSCA "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/blog-cms"
    click Func "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/api"
    click StripeCA "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/stripe"
    click Notifications "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/notifications"
    click E2E "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/testing/e2e"
    click Docs "https://github.com/azure-samples/contoso-real-estate/tree/main/packages/docs"
    click Azdo "https://github.com/azure-samples/contoso-real-estate/tree/main/.azdo/pipelines"
    click GH "https://github.com/azure-samples/contoso-real-estate/tree/main/.github/workflows"
    click InfraApp "https://github.com/azure-samples/contoso-real-estate/tree/main/infra/app"
    click InfraCore "https://github.com/azure-samples/contoso-real-estate/tree/main/infra/core"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,color:#0366d6;
    classDef compute fill:#d1e7dd,stroke:#198754,color:#198754;
    classDef database fill:#fff3cd,stroke:#ffcd39,color:#bb7000;
    classDef messaging fill:#e2d5f7,stroke:#6f42c1,color:#6f42c1;
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#495057;
```
