# undertakerprog/speedtest architecture

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

- Interactive diagram: https://gitdiagram.com/undertakerprog/speedtest
- Repository: https://github.com/undertakerprog/speedtest

## Overview

##### Project Overview & Type
- The SpeedTest project is a multi-faceted application that includes both a full-stack ASP.NET backend (Web API) and a WPF-based Desktop client.
- Its primary purpose is to provide various network tests – managing server lists, measuring ping values, determining user and server locations, and testing download speeds.
- The README highlights robust backend API endpoints (with Swagger documentation) along with a desktop user interface. Docker and Redis are used for containerization and caching support, respectively.

##### Analyzing the File Structure
- Top-level Directories/Projects:
- Desktop: Contains the WPF-based desktop application including its UI pages (XAML files and code-behind), models, helpers, and service layers for local tests.
- Web: Contains the ASP.NET backend project, organized into subdirectories for controllers (named “Сontroller”), services, models, and caching (using Redis).
- Infrastructure: A separate library (class library) that encapsulates file operations and other foundational helpers, which may be shared across projects.
- WebTest: Contains MSTest-based tests for API endpoints, service logic, and models, ensuring that the API behaves as expected.
- Additional files: Docker configuration files (docker-compose.yml, Dockerfile) for running the project in containers and CI/CD configuration files for automated builds (under .github/workflows).

##### Main Components in the Architecture
a. Desktop Client:
- Built with WPF, responsible for allowing users to perform speed tests, select servers, and monitor speeds.
- Interfaces with the backend APIs for performing tests.
b. ASP.NET Backend (Web API):
- Exposes endpoints grouped by functionality: Location, Ping, Server management, and SpeedTest.
- Implements key business logic for determining the best or nearest server, running speed tests, and caching responses.
- Uses Swagger for auto-generated API documentation.
c. Infrastructure Library:
- Provides common functionalities (e.g., file reading) to be utilized by one or more of the other projects.
d. Redis Caching:
- Acts as a caching layer to store and quickly retrieve data (e.g., server-city details).
- Configured in appsettings and tested via endpoints.
e. Testing Layer:
- The WebTest project provides automated tests to validate controllers and service logic.
f. Docker & CI/CD Integration:
- Dockerfiles and Docker Compose configuration facilitate containerized deployment.
- CI/CD workflows (as found in .github/workflows) automate build and deployment processes.

##### Relationships & Interactions
- The Desktop application communicates with the ASP.NET backend via HTTP calls – consuming endpoints for speed tests, server selections, and more.
- The Web API interacts with Redis for caching efficient results, especially for retrieving server data quickly.
- The Infrastructure project serves as a shared library used by the Desktop and potentially the Web API.
- Unit and integration tests in the WebTest project verify the correctness of business logic and API endpoints.

##### Important Architectural Patterns/Design Principles
- Separation of Concerns: The front end (TUI in WPF) is separate from the backend logic which is structured into controllers, models, and services.
- Layered Architecture / MVC (for the Web API): Controllers forward requests to corresponding services, and responses are packaged with clearly defined models.
- Dependency Injection & Interface-Driven Design: Both the API and the desktop client use service abstractions (like ILocationService, IPingService, etc.) to decouple components.
- Containerization: Docker is used to package and deploy the application, aiding scalability and simplified environment setup.

##### Technology Highlights
- ASP.NET for backend endpoint implementation along with Swagger for documentation.
- WPF for the Desktop client interface.
- Redis for caching to improve performance and reduce load times.
- MSTest for unit testing ensuring the application’s robustness.
- Docker/Docker Compose for containerized deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Desktop Client
    subgraph "Desktop Client"
        UI["WPF Desktop Application (UI & Logic)"]:::ui
    end

    %% Web API Backend
    subgraph "ASP.NET Core Web API"
        Controller["Controllers (Location, Ping, Server, SpeedTest)"]:::backend
        Service["Services"]:::backend
        Model["Models"]:::backend
        Swagger["Swagger Documentation"]:::backend
        AppSettings["appsettings.json (Redis Config)"]:::backend
    end

    %% Shared Infrastructure Library
    subgraph "Shared Infrastructure"
        InfraProj["Infrastructure Library (Infrastructure.csproj)"]:::lib
        FileReader["FileReader.cs"]:::lib
        IFileReader["IFileReader.cs"]:::lib
    end

    %% Redis Caching
    subgraph "Redis Cache"
        CacheInterface["IRedisCacheService.cs"]:::cache
        CacheService["RedisCacheService.cs"]:::cache
        RedisConfig["appsettings.json (Redis Config)"]:::cache
    end

    %% Testing Layer
    subgraph "Automated Tests"
        Tests["WebTest (MSTest)"]:::test
    end

    %% Deployment & CI/CD
    subgraph "Deployment"
        Dockerfile["Dockerfile"]:::deploy
        DockerCompose["docker-compose.yml"]:::deploy
        CICD["GitHub Actions Workflows"]:::deploy
    end

    %% Connections
    UI -- "HTTPRequest" --> Controller
    Controller -- "calls" --> Service
    Service -- "uses" --> Model
    Service -- "calls" --> CacheService
    Service -- "uses" --> InfraProj
    Service -- "uses" --> FileReader
    Service -- "uses" --> IFileReader
    Tests -- "validates" --> Controller

    %% Deployment integration
    Dockerfile --- Controller
    DockerCompose --- Controller
    DockerCompose --- CacheService
    CICD --- Dockerfile

    %% Redis config integration
    AppSettings --- RedisConfig

    %% Desktop-to-WebAPI
    UI --- Controller

    %% Styles
    classDef ui fill:#fce5cd,stroke:#d35400,stroke-width:2px;
    classDef backend fill:#d6eaf8,stroke:#2980b9,stroke-width:2px;
    classDef lib fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef cache fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef test fill:#fdebd0,stroke:#e67e22,stroke-width:2px;
    classDef deploy fill:#ebdef0,stroke:#8e44ad,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/undertakerprog/speedtest/tree/master/Desktop"
    click Controller "https://github.com/undertakerprog/speedtest/tree/master/Web/Src/Сontroller"
    click Service "https://github.com/undertakerprog/speedtest/tree/master/Web/Src/Service"
    click Model "https://github.com/undertakerprog/speedtest/tree/master/Web/Src/Model"
    click InfraProj "https://github.com/undertakerprog/speedtest/tree/master/Infrastructure"
    click FileReader "https://github.com/undertakerprog/speedtest/blob/master/Infrastructure/FileReader.cs"
    click IFileReader "https://github.com/undertakerprog/speedtest/blob/master/Infrastructure/IFileReader.cs"
    click CacheInterface "https://github.com/undertakerprog/speedtest/blob/master/Web/Src/Cache/IRedisCacheService.cs"
    click CacheService "https://github.com/undertakerprog/speedtest/blob/master/Web/Src/Cache/RedisCacheService.cs"
    click AppSettings "https://github.com/undertakerprog/speedtest/blob/master/Web/appsettings.json"
    click RedisConfig "https://github.com/undertakerprog/speedtest/blob/master/Web/appsettings.json"
    click Tests "https://github.com/undertakerprog/speedtest/tree/master/WebTest"
    click Dockerfile "https://github.com/undertakerprog/speedtest/tree/master/Web/Dockerfile"
    click DockerCompose "https://github.com/undertakerprog/speedtest/blob/master/docker-compose.yml"
    click CICD "https://github.com/undertakerprog/speedtest/tree/master/.github/workflows"
```
