# kannappansomasundaram1/testingresiliency architecture

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

- Interactive diagram: https://gitdiagram.com/kannappansomasundaram1/testingresiliency
- Repository: https://github.com/kannappansomasundaram1/testingresiliency

## Overview

##### Project type and purpose
- This is a .NET solution (TestingResiliency.sln) demonstrating a resilient HTTP API with fault injection via ToxiProxy and automated chaos tests (SimmyChaosTests).
- Key purpose: show how an ASP.NET Core “Todo” API client experiences downstream failures (latency, resets), use policies (circuit breaker, retries), and verify behavior under load and chaos.

##### File structure
- Top-level solution “TestingResiliency.sln” contains:
- ApiUsingToxiProxy – ASP.NET Core Web API project (Program.cs, appsettings, TodoClient, TodoItem).
- Aspire.AppHost – a reusable app host project with default host configuration and middleware.
- Aspire.ServiceDefaults – a class library for common DI/extension methods (service defaults, resilience pipeline).
- SimmyChaosTests – xUnit test project using Simmy to inject chaos into policies.
- Notice build configs (launchSettings.json, appsettings.{Development}.json), a load test script (loadtest.js), and HTTP query file (WebApplication1.http).

##### README for insights
- API → DummyJson.com
- API → ToxiProxy → DummyJson.com
- Steps to install/run ToxiProxy, create proxy “todo,” inject latency/reset faults, exercise circuit breaker under load (k6), and tests.

##### Main components
a. Backend API (ApiUsingToxiProxy)
- ASP.NET Core application hosted via Aspire.AppHost
- Uses Aspire.ServiceDefaults for default services and resilience pipeline (Polly/Simmy)
- Contains TodoClient which calls external API
b. Resilience Library (Aspire.ServiceDefaults)
- Extension methods registering retry, timeout, circuit-breaker policies
c. Chaos Test Suite (SimmyChaosTests)
- Simmy policies testing pipeline behavior under injected faults
d. ToxiProxy Server
- HTTP/TCP proxy sitting between API and DummyJson.com
- Configured via toxiproxy-cli to induce latency, resets
e. External API (DummyJson.com)
- Upstream service providing /todos endpoints
f. Load-Test Client (k6 / loadtest.js)
- Generates concurrent requests to API to trigger circuit-breaker

##### Relationships and data-flow
- Load-Test → HTTP → API
- API → (over configured HTTP client) → ToxiProxy → DummyJson.com
- SimmyChaosTests → in-process HTTP client pipeline (inject faults via Simmy policies)
- API uses Aspire.ServiceDefaults to wire resilience policies around TodoClient

##### Architectural patterns & design principles
- Layered components: Host, Service Defaults (DI & middleware), Business logic (TodoClient & controllers)
- Dependency Injection & extension-method modules for reuse
- Resilience patterns: retry, timeout, circuit-breaker (Polly + Simmy)
- Separation of concerns: Proxy layer (ToxiProxy) kept external, tests isolated

##### Technology & frameworks
- .NET 7/ASP.NET Core, C#
- Aspire.AppHost (generic host builder)
- Aspire.ServiceDefaults (custom library)
- ToxiProxy server & CLI (Shopify) for network chaos
- Simmy (Chaos injection in Polly pipelines)
- k6 load testing (JavaScript)
- xUnit for SimmyChaosTests

## Diagram (Mermaid)

```mermaid
flowchart TB
  classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px
  classDef external fill:#90EE90,stroke:#000,stroke-width:1px
  classDef test fill:#FFA500,stroke:#000,stroke-width:1px

  subgraph "Test Tools"
    direction TB
    K6["k6 Load Test\n(loadtest.js)"]:::test
    subgraph "SimmyChaosTests"
      PT["PoliciesTest.cs"]:::test
      RPT["ResiliencePipelineTest.cs"]:::test
    end
  end

  subgraph "ApiUsingToxiProxy"
    direction TB
    API_PC["Program.cs"]:::api
    AH_LIB["Aspire.AppHost\n(Program.cs)"]:::api
    SD_LIB["Aspire.ServiceDefaults\n(Extensions.cs)"]:::api
    API_TC["TodoClient.cs"]:::api
    API_TI["TodoItem.cs"]:::api
    API_AS["appsettings.json"]:::api
    API_ASD["appsettings.Development.json"]:::api
    API_LS["Properties/launchSettings.json"]:::api
    API_WA["WebApplication1.http"]:::api
  end

  subgraph "Proxy Layer"
    Toxi["ToxiProxy"]:::external
  end

  subgraph "External API"
    Dummy["DummyJson.com"]:::external
  end

  K6 -->|"HTTPS"| API_PC
  API_PC -->|"Use Host & Setup"| AH_LIB
  AH_LIB -->|"Configure Services"| SD_LIB
  SD_LIB -->|"Wrap HttpClient"| API_TC
  API_TC -->|"HTTP"| Toxi
  Toxi -->|"Forward"| Dummy
  PT -->|"Tests pipeline"| SD_LIB
  RPT -->|"Tests pipeline"| SD_LIB

  click API_PC "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/Program.cs"
  click AH_LIB "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/Aspire.AppHost/Program.cs"
  click SD_LIB "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/Aspire.ServiceDefaults/Extensions.cs"
  click API_TC "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/TodoClient.cs"
  click API_TI "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/TodoItem.cs"
  click API_AS "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/appsettings.json"
  click API_ASD "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/appsettings.Development.json"
  click API_LS "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/Properties/launchSettings.json"
  click API_WA "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/WebApplication1.http"
  click K6 "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/ApiUsingToxiProxy/loadtest.js"
  click PT "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/SimmyChaosTests/PoliciesTest.cs"
  click RPT "https://github.com/kannappansomasundaram1/testingresiliency/blob/main/SimmyChaosTests/ResiliencePipelineTest.cs"
```
