# appsecco/dvcsharp-api architecture

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

- Interactive diagram: https://gitdiagram.com/appsecco/dvcsharp-api
- Repository: https://github.com/appsecco/dvcsharp-api

## Overview

##### Project type and purpose
- This is a .NET Core 2.x RESTful API (“Damn Vulnerable C# Application – API Only”) designed to demonstrate common web-app vulnerabilities.
- It provides user registration, authentication (tokens), password-resets, product CRUD, and import endpoints. It is explicitly meant for security testing (not production).

##### File structure
- Top-level:
- Controllers/ – ASP.NET Core MVC controllers (entry points for HTTP).
- Models/ – DTOs and EF Core entity classes (User, Product, AuthorizationRequest/Response, etc.).
- Data/ – GenericDataContext.cs (EF Core DbContext).
- Migrations/ – EF Core migration files for schema evolution.
- Startup.cs & Program.cs – host & middleware configuration.
- appsettings*.json – configuration for database, logging, etc.
- Dockerfile & docker-compose.yml – container definitions (API + backing database).
- documentation-dvcsharp-book/ – static documentation and attack guides (external to core runtime).
- test/ & Postman collections – integration/testing assets.

##### README for additional insights
- The API runs on Kestrel (dotnet run or in Docker).
- Database migrations via `dotnet ef database update`.
- Docker Compose brings up the API and likely a SQL database.
- There are explicit Postman collections and sample data under documentation.

##### Main components & interactions
a. Components
1. Client(s)
– REST clients (Postman, browser-based API client, automated tests).
2. API Layer (ASP.NET Core)
– Kestrel web server hosting
– Startup & Middleware (Routing, Authentication, CORS, Logging)
– Controllers (Authorization, Registrations, Tokens, PasswordResets, Users, Products, Imports)
3. Business/Data Layer
– Models (Entity definitions)
– GenericDataContext (DbContext)
– EF Core Migrations
4. Database
– SQL Server/MySQL/PostgreSQL (configured via appsettings.json)
5. External/Infrastructure
– Docker Engine & Docker Compose
– Volume mounts for data persistence
– CI/CD or local tooling (dotnet watch, Postman collection for tests)

b. Relationships & Interactions
- Clients → HTTP(S) → Kestrel/API Layer
- Controllers use Dependency-Injected DbContext → SQL Database
- Startup configures middlewares (JWT bearer auth, error handling)
- Docker Compose networks “api” and “db” containers
- EF Core Migrations manage schema in the Database

c. Architectural patterns & principles
- Layered architecture: Presentation (Controllers) → Business/Data (Services can be added) → Data Access (DbContext) → Persistence (Database)
- Dependency Injection for DbContext and configuration
- RESTful resource design
- Immutable configuration via appsettings.json & environment overrides
- Containerization for environment parity

d. Key technologies
- ASP.NET Core 2.x (Kestrel)
- Entity Framework Core (Code-First Migrations)
- Docker & Docker Compose
- SQL Database of choice (through EF Core provider)
- Postman for API testing

##### Detailed step-by-step for the principal software engineer
- Middleware (JWT auth, error handling)
- Controllers (list key controllers)
- Data Access (GenericDataContext + Migrations)
5. Configuration files (appsettings.json) feeding into Startup.
6. Optionally, off to the side, show “documentation-dvcsharp-book” as a static GitBook/Markdown site consumed by security testers.
- Client hits /registrations → RegistrationController → DbContext.Add(User) → SQL INSERT.
- Client logs in → TokensController → returns JWT → Client uses JWT in Authorization header on protected endpoints.

## Diagram (Mermaid)

```mermaid
graph TB
    classDef client fill:#add8e6,stroke:#333,stroke-width:1px
    classDef api fill:#90ee90,stroke:#333,stroke-width:1px
    classDef data fill:#ffa500,stroke:#333,stroke-width:1px
    classDef infra fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef docs fill:#e6e6fa,stroke:#333,stroke-width:1px

    subgraph Clients
        Clients["REST Clients\n(Postman, Browser, Tests)"]:::client
    end

    subgraph "Docker Container\n(appsecco/dvcsharp)" 
        StartupCs["Startup.cs"]:::api
        ProgramCs["Program.cs"]:::api
        Config1["appsettings.json"]:::infra
        Config2["appsettings.Development.json"]:::infra

        subgraph "Controllers Directory"
            ControllersDir["Controllers/"]:::api
            subgraph "Controllers"
                AuthzCtrl["AuthorizationsController"]:::api
                RegistrationsCtrl["RegistrationsController"]:::api
                TokensCtrl["TokensController"]:::api
                PwdResetsCtrl["PasswordResetsController"]:::api
                UsersCtrl["UsersController"]:::api
                ProductsCtrl["ProductsController"]:::api
                ImportsCtrl["ImportsController"]:::api
            end
        end

        subgraph "Data Layer"
            DbContext["GenericDataContext.cs"]:::data
            subgraph "Migrations"
                MigDir["Migrations/"]:::data
                Mig1["20180427052355_InitialCreate.cs"]:::data
                Mig2["20180514042927_AddPasswordRestRequest.cs"]:::data
                Mig3["20180515161327_AddProduct.cs"]:::data
                Mig4["GenericDataContextModelSnapshot.cs"]:::data
            end
        end

        ModelsDir["Models/"]:::data
    end

    subgraph "Docker Container\n(SQL Database)"
        DB["SQL Database"]:::data
    end

    DockerCompose["docker-compose.yml"]:::infra

    subgraph Documentation
        Docs["documentation-dvcsharp-book/"]:::docs
        Postman1["DVCSharp-API.postman_collection.json"]:::docs
        Postman2["test/DVCSharp-Core-API.postman_collection.json"]:::docs
    end

    %% Connections
    Clients -->|"HTTP/HTTPS"| ControllersDir
    StartupCs -->|"configures"| ControllersDir
    StartupCs -->|"runs migrations"| MigDir
    Config1 -->|"configuration"| StartupCs
    Config2 -->|"configuration"| StartupCs
    ControllersDir -->|uses| DbContext
    DbContext -->|"SQL/TCP"| DB
    DockerCompose --> APIContainer
    DockerCompose -->|"networks"| DB

    Docs --> Clients
    Postman1 --> Clients
    Postman2 --> Clients

    %% Click Events
    click ControllersDir "https://github.com/appsecco/dvcsharp-api/tree/master/Controllers/"
    click AuthzCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/AuthorizationsController.cs"
    click RegistrationsCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/RegistrationsController.cs"
    click TokensCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/TokensController.cs"
    click PwdResetsCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/PasswordResetsController.cs"
    click UsersCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/UsersController.cs"
    click ProductsCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/ProductsController.cs"
    click ImportsCtrl "https://github.com/appsecco/dvcsharp-api/blob/master/Controllers/ImportsController.cs"
    click DbContext "https://github.com/appsecco/dvcsharp-api/blob/master/Data/GenericDataContext.cs"
    click MigDir "https://github.com/appsecco/dvcsharp-api/tree/master/Migrations/"
    click Mig1 "https://github.com/appsecco/dvcsharp-api/blob/master/Migrations/20180427052355_InitialCreate.cs"
    click Mig2 "https://github.com/appsecco/dvcsharp-api/blob/master/Migrations/20180514042927_AddPasswordRestRequest.cs"
    click Mig3 "https://github.com/appsecco/dvcsharp-api/blob/master/Migrations/20180515161327_AddProduct.cs"
    click Mig4 "https://github.com/appsecco/dvcsharp-api/blob/master/Migrations/GenericDataContextModelSnapshot.cs"
    click ModelsDir "https://github.com/appsecco/dvcsharp-api/tree/master/Models/"
    click StartupCs "https://github.com/appsecco/dvcsharp-api/blob/master/Startup.cs"
    click ProgramCs "https://github.com/appsecco/dvcsharp-api/blob/master/Program.cs"
    click Config1 "https://github.com/appsecco/dvcsharp-api/blob/master/appsettings.json"
    click Config2 "https://github.com/appsecco/dvcsharp-api/blob/master/appsettings.Development.json"
    click DockerCompose "https://github.com/appsecco/dvcsharp-api/blob/master/docker-compose.yml"
    click Docs "https://github.com/appsecco/dvcsharp-api/tree/master/documentation-dvcsharp-book/"
    click Postman1 "https://github.com/appsecco/dvcsharp-api/blob/master/DVCSharp-API.postman_collection.json"
    click Postman2 "https://github.com/appsecco/dvcsharp-api/blob/master/test/DVCSharp-Core-API.postman_collection.json"
```
