# maartenvandiemen/todoitems architecture

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

- Interactive diagram: https://gitdiagram.com/maartenvandiemen/todoitems
- Repository: https://github.com/maartenvandiemen/todoitems

## Overview

##### Project type and purpose
- This is a demo ASP.NET Core 9 “minimal API” project (TodoItems.Api) that exposes HTTP endpoints to manage todo items.
- It uses Entity Framework Core migrations against an Azure SQL Database.
- Infrastructure‐as‐code is defined with Bicep files under the “Deployment” folder.
- CI/CD pipelines are implemented both in GitHub Actions and Azure DevOps to build (with and without Docker), run tests, and deploy to Azure (App Service, SQL, Key Vault, Application Insights).

##### File structure
- Top‐level solution (TodoItems.sln) references two key projects:
- TodoItems.Api – the API service
- TodoItems.Api.IntegrationTests – end‐to‐end tests that spin up a test environment and run against the API
- Deployment – contains Bicep templates for provisioning Azure resources (App Service, SQL, Key Vault, etc.)
- .github & .azuredevops – CI/CD definitions (build, test, deploy workflows) for GitHub Actions and Azure DevOps
- tests/test.http – Postman‐style HTTP requests for smoke/manual testing

##### Key README insights
- The API is containerizable (Dockerfile) but also runnable directly.
- Requires secrets (SA_PASSWORD, AZURE_SQL_USER, Azure service principal) stored as encrypted repository or variable‐group secrets.
- Separate pipelines for “nodocker” and “docker” builds, both culminating in deployment to Azure.
- CI triggers: commits to main branch, pull requests and manual environment deployments.

##### Main components
a. Client (Postman, browser, mobile app, or HTTP test suite) – issues HTTP requests to the API
b. TodoItems.Api – ASP.NET Core minimal API service
c. Azure SQL Database – persistent storage for todo items (EF Core migrations apply schema)
d. Azure App Service – hosts the API (with or without Docker container)
e. Azure Key Vault – stores SQL credentials and other secrets
f. Application Insights – telemetry and logging for the API
g. CI/CD Pipeline – GitHub Actions/Azure DevOps workflows that:
- Build & test the API
- Publish Docker image (optional)
- Deploy Bicep templates (Infrastructure as Code)
- Deploy the API to App Service
h. Integration Test Environment – ephemeral resources spun up by tests (local or in‐cloud)

##### Relationships and interactions
- Client → HTTP → App Service / API
- API → ADO.NET or EF Core → Azure SQL Database
- API → Key Vault SDK → retrieve credentials/secrets at runtime
- API → Application Insights SDK → send telemetry
- CI/CD Pipeline → Bicep CLI → provision/update Azure resources → deploy API image or code
- Integration Tests → spin up test instance of API & DB → execute HTTP calls → validate responses

##### Architectural patterns and principles
- Minimal API – single‐assembly, attribute‐light endpoints
- Layered separation: API layer vs. persistence layer (EF Core migrations in Migrations folder)
- Infrastructure as Code – declarative resource templates (Bicep) versioned alongside code
- CI/CD as code – YAML workflows under .github and .azuredevops
- Containerization – optional Docker image for production parity

##### Relevant technologies, frameworks, libraries
- .NET 9, ASP.NET Core minimal APIs
- Entity Framework Core (Migrations)
- Docker (optional)
- Azure Bicep (IaC)
- GitHub Actions & Azure DevOps pipelines
- Azure App Service, Azure SQL, Key Vault, Application Insights

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client (HTTP Test Suite)"]:::external
    click Client "https://github.com/maartenvandiemen/todoitems/blob/main/tests/test.http"

    %% Azure Subscription Boundary
    subgraph "Azure Subscription"
        direction TB
        API["TodoItems.Api\nASP.NET Core 9"]:::compute
        click API "https://github.com/maartenvandiemen/todoitems/blob/main/TodoItems.Api/Program.cs"
        AS["Azure App Service"]:::compute
        SQL["Azure SQL Database"]:::datastore
        click SQL "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/sql.bicep"
        KV["Azure Key Vault"]:::service
        click KV "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/keyVault.bicep"
        AI["Application Insights"]:::service
        click AI "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/applicationInsights.bicep"
    end

    %% Deployment IaC
    subgraph "IaC (Deployment)" 
        direction TB
        B_sql["sql.bicep"]:::pipeline
        click B_sql "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/sql.bicep"
        B_app["appService.bicep"]:::pipeline
        click B_app "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/appService.bicep"
        B_mainDocker["main.docker.webapp.bicep"]:::pipeline
        click B_mainDocker "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/main.docker.webapp.bicep"
        B_mainNoDocker["main.nodocker.webapp.bicep"]:::pipeline
        click B_mainNoDocker "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/main.nodocker.webapp.bicep"
        B_kv["keyVault.bicep"]:::pipeline
        click B_kv "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/keyVault.bicep"
        B_ai["applicationInsights.bicep"]:::pipeline
        click B_ai "https://github.com/maartenvandiemen/todoitems/blob/main/Deployment/applicationInsights.bicep"
    end

    %% CI/CD Control Plane
    subgraph "CI/CD Control Plane"
        direction TB
        subgraph "GitHub Actions"
            direction TB
            GH_build["build.yml"]:::pipeline
            click GH_build "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/build.yml"
            GH_docker["main.docker.yml"]:::pipeline
            click GH_docker "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/main.docker.yml"
            GH_nodocker["main.nodocker.yml"]:::pipeline
            click GH_nodocker "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/main.nodocker.yml"
            GH_deployDB["deploy_db.yml"]:::pipeline
            click GH_deployDB "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/deploy_db.yml"
            GH_smoke["smoketests.yml"]:::pipeline
            click GH_smoke "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/smoketests.yml"
            GH_create["create_env.yml"]:::pipeline
            click GH_create "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/create_env.yml"
            GH_delete["delete_env.yml"]:::pipeline
            click GH_delete "https://github.com/maartenvandiemen/todoitems/blob/main/.github/workflows/delete_env.yml"
        end
        subgraph "Azure DevOps"
            direction TB
            AZ_build["build.yml"]:::pipeline
            click AZ_build "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/build.yml"
            AZ_docker["main.docker.yml"]:::pipeline
            click AZ_docker "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/main.docker.yml"
            AZ_nodocker["main.nodocker.yml"]:::pipeline
            click AZ_nodocker "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/main.nodocker.yml"
            AZ_deployNoDocker["deploy.nodocker.yml"]:::pipeline
            click AZ_deployNoDocker "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/deploy.nodocker.yml"
            AZ_deploySQL["deploy.sql.yml"]:::pipeline
            click AZ_deploySQL "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/deploy.sql.yml"
            AZ_create["create_env.yml"]:::pipeline
            click AZ_create "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/create_env.yml"
            AZ_smoke["smoketests.yml"]:::pipeline
            click AZ_smoke "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/smoketests.yml"
            AZ_generic["generic.yml"]:::pipeline
            click AZ_generic "https://github.com/maartenvandiemen/todoitems/blob/main/.azuredevops/generic.yml"
        end
    end

    %% Integration Test Environment
    subgraph "Integration Test Environment" 
        direction TB
        style Integration Test Environment stroke-dasharray: 5 5
        IT["Integration Tests\n(TodoItems.Api.IntegrationTests)"]:::test
        click IT "https://github.com/maartenvandiemen/todoitems/blob/main/TodoItems.Api.IntegrationTests/TodoItems.Api.IntegrationTests.csproj"
    end

    %% Connections - Data Plane
    Client -->|"HTTP Request"| API
    API -->|"ADO.NET/EF Core"| SQL
    API -->|"Key Vault SDK"| KV
    API -->|"App Insights SDK"| AI
    API -->|"(Hosted on)"| AS

    %% Connections - IaC
    B_sql -->|"provisions"| SQL
    B_app -->|"provisions"| AS
    B_mainDocker -->|"provisions"| AS
    B_mainNoDocker -->|"provisions"| AS
    B_kv -->|"provisions"| KV
    B_ai -->|"provisions"| AI

    %% Connections - CI/CD
    GH_build -->|"triggers IaC"| B_sql
    GH_build -->|"triggers IaC"| B_app
    GH_docker -->|"docker build"| B_mainDocker
    GH_nodocker -->|"code deploy"| B_mainNoDocker
    GH_deployDB -->|"migrations"| SQL
    AZ_build -->|"triggers IaC"| B_sql
    AZ_build -->|"triggers IaC"| B_app
    AZ_docker -->|"docker build"| B_mainDocker
    AZ_nodocker -->|"code deploy"| B_mainNoDocker
    AZ_deploySQL -->|"migrations"| SQL

    %% Connections - Integration Tests
    IT -->|"HTTP Calls"| API
    IT -->|"DB Validation"| SQL

    classDef compute fill:#D6E9FF,stroke:#339,stroke-width:1px
    classDef datastore fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px
    classDef service fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px
    classDef pipeline fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
    classDef external fill:#ECEFF1,stroke:#607D8B,stroke-width:1px
    classDef test fill:#FFEBEE,stroke:#C62828,stroke-width:1px
```
