# avansbitbybit/api architecture

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

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

## Overview

##### Project type and purpose
- BitByBitTrashAPI is a .NET 8 (ASP.NET Core) Web API that exposes endpoints for managing trash pickups, handling user roles/authentication, and providing weather data for pickup locations.
- It uses Entity Framework Core for persistence (with migrations under Migrations/), ASP Net Identity for authentication, calls out to external geocoding & weather APIs, is containerized via Docker, and has CI/CD workflows in GitHub Actions.

##### File structure
- Top‐level folders:
- BitByBitTrashAPI/ – the main Web API project
– Controllers/ (AdminController.cs, LitterController.cs, DummyTrashController.cs, WeatherController.cs)
– DBContext/ (ApplicationDbContext.cs for Identity, LitterDbContext.cs for trash/weather data)
– Migrations/ (EF Core schema migrations)
– Models/ (DTOs and entity definitions: TrashPickup.cs, WeatherModel.cs, AddRoleRequest.cs)
– Service/ (service abstractions & implementations: IAuthenticationService, AspNetIdentityAuthenticationService, IGeocodingService, GeocodingService, IWeatherApiService, WeatherApiService, etc.)
– Program.cs (host setup, DI registration, seeding)
– appsettings.json & appsettings.Development.json
– Dockerfile
– BitByBitTrashAPI.http (sample API calls)
- BitByBitTrashAPI.Tests/ – unit tests for controllers, services, and DbContext
- .github/workflows/ – CI/CD pipelines for auto‐deploy

##### README
- Minimal content (“# BitByBitTrashAPI”), so we rely on file/folder names to infer architecture: layered Web API, EF Core, external HTTP services, Docker, GitHub Actions.

a. Main components:
1. Clients (Web UI, Mobile App, Postman/CLI)
2. BitByBitTrashAPI (runs in Docker)
– Controllers layer
– Services layer (authentication, geocoding, weather, seeding)
– Data layer (EF Core DbContexts)
3. Database (SQL Server / Azure SQL)
4. External HTTP services (Geocoding API, Weather API)
5. CI/CD Pipeline (GitHub Actions → Docker registry → Hosting platform)

b. Relationships & interactions:
– Client → HTTP → Controllers
– Controllers → Services (via injected interfaces)
– Services → DbContext → Database
– Services → External APIs (geocoding, historical and forecast weather)
– Program.cs at startup runs migrations & SeedRoles to initialize Identity roles
– GitHub Actions watches master, builds Docker image, pushes to registry, and deploys container to hosting

c. Architectural patterns & principles:
– Layered architecture: Presentation (Controllers), Business (Services), Data (DbContexts).
– Dependency Injection (IAuthenticationService, IGeocodingService, etc.).
– Code-first migrations with EF Core.
– Single‐responsibility controllers and services.
– Containerization for environment consistency.
– Automated CI/CD.

d. Key technologies/frameworks:
– ASP .NET Core Web API
– Entity Framework Core (+ Migrations)
– ASP NET Identity
– Docker
– GitHub Actions
– External REST services (e.g., OpenWeatherMap, Google Geocoding)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients" 
        direction TB
        UI["Web UI / Mobile App"]:::client
        CLI["Postman/CLI"]:::client
    end

    %% Docker Container for API
    subgraph "BitByBitTrashAPI (Docker Container)" 
        direction TB
        Program["Program.cs"]:::internal
        subgraph "Configuration"
            ConfigProd["appsettings.json"]:::internal
            ConfigDev["appsettings.Development.json"]:::internal
        end
        subgraph "Controllers Layer"
            direction TB
            AC["AdminController"]:::internal
            LC["LitterController"]:::internal
            DC["DummyTrashController"]:::internal
            WC["WeatherController"]:::internal
        end
        subgraph "Services Layer"
            direction TB
            IAuthS["IAuthenticationService"]:::internal
            AuthImpl["AspNetIdentityAuthenticationService"]:::internal
            IGeo["IGeocodingService"]:::internal
            GeoImpl["GeocodingService"]:::internal
            IWeatherASP["IWeatherApiService"]:::internal
            WeatherASPImpl["WeatherApiService"]:::internal
            IHistW["IHistoricalWeatherService"]:::internal
            HistWImpl["HistoricalWeatherService"]:::internal
            Seed["SeedRoles"]:::internal
        end
        subgraph "Data Layer"
            direction TB
            Migrations["Migrations"]:::internal
            subgraph "DbContexts"
                direction TB
                AppDb["ApplicationDbContext"]:::internal
                LitterDb["LitterDbContext"]:::internal
            end
        end
        subgraph "Models"
            direction TB
            AddRole["AddRoleRequest"]:::internal
            TrashPickup["TrashPickup"]:::internal
            WeatherModel["WeatherModel"]:::internal
        end
        Dockerfile["Dockerfile"]:::infra
        HTTPCalls["Sample API Calls"]:::internal
    end

    %% External APIs
    subgraph "External APIs"
        direction TB
        GeocodingAPI["Geocoding API"]:::external
        WeatherAPI["Weather API"]:::external
    end

    %% Database
    Database["SQL Server / Azure SQL"]:::infra

    %% CI/CD Pipeline
    subgraph "CI/CD (GitHub Actions)" 
        direction TB
        Workflow["GitHub Actions"]:::infra
        DockerReg["Docker Registry"]:::infra
        Hosting["Hosting Platform"]:::infra
    end

    %% Unit Tests
    Tests["Unit Tests (BitByBitTrashAPI.Tests)"]:::internal

    %% Connections
    UI -->|HTTP| AC
    UI -->|HTTP| LC
    UI -->|HTTP| DC
    UI -->|HTTP| WC
    CLI -->|HTTP| AC
    CLI -->|HTTP| LC
    CLI -->|HTTP| DC
    CLI -->|HTTP| WC

    AC -->|uses| IAuthS
    LC -->|uses| IGeo
    DC -->|uses| IWeatherASP
    WC -->|uses| IWeatherASP

    IAuthS -->|impl| AuthImpl
    IGeo -->|impl| GeoImpl
    IWeatherASP -->|impl| WeatherASPImpl
    IHistW -->|impl| HistWImpl

    AuthImpl -->|uses Db| AppDb
    GeoImpl -->|uses Db| LitterDb
    WeatherASPImpl -->|uses Db| LitterDb
    HistWImpl -->|uses Db| LitterDb
    Seed -->|runs at startup| AppDb

    Program -->|Run Migrations| Migrations
    Program -->|Invoke Seeding| Seed
    Program -->|Load Config| ConfigProd
    Program -->|Load Config| ConfigDev

    ADbContext -->|EF Core| Migrations
    AppDb -->|SQL| Database
    LitterDb -->|SQL| Database

    IGeo -->|HTTP call| GeocodingAPI
    WeatherASPImpl -->|HTTP call| WeatherAPI
    HistWImpl -->|HTTP call| WeatherAPI

    Workflow -->|on push| Dockerfile
    Workflow -->|runs| Tests
    Workflow -->|build image| DockerReg
    DockerReg -->|deploy| Hosting
    Hosting -->|runs container| Dockerfile

    %% Click Events
    click AC "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Controllers/AdminController.cs"
    click LC "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Controllers/LitterController.cs"
    click DC "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Controllers/DummyTrashController.cs"
    click WC "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Controllers/WeatherController.cs"
    click AppDb "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/DBContext/ApplicationDbContext.cs"
    click LitterDb "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/DBContext/LitterDbContext.cs"
    click Migrations "https://github.com/avansbitbybit/api/tree/master/BitByBitTrashAPI/Migrations/"
    click AddRole "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Models/AddRoleRequest.cs"
    click TrashPickup "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Models/TrashPickup.cs"
    click WeatherModel "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Models/WeatherModel.cs"
    click IAuthS "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/IAuthenticationService.cs"
    click AuthImpl "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/AspNetIdentityAuthenticationService.cs"
    click IGeo "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/IGeocodingService.cs"
    click GeoImpl "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/GeocodingService.cs"
    click IWeatherASP "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/IWeatherApiService.cs"
    click WeatherASPImpl "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/WeatherApiService.cs"
    click IHistW "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/IHistoricalWeatherService.cs"
    click HistWImpl "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/HistoricalWeatherService.cs"
    click Seed "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Service/SeedRoles.cs"
    click Program "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/Program.cs"
    click ConfigProd "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/appsettings.json"
    click ConfigDev "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/appsettings.Development.json"
    click Dockerfile "https://github.com/avansbitbybit/api/tree/master/Dockerfile"
    click HTTPCalls "https://github.com/avansbitbybit/api/blob/master/BitByBitTrashAPI/BitByBitTrashAPI.http"
    click Workflow "https://github.com/avansbitbybit/api/blob/master/.github/workflows/bitbybit-api-AutoDeployTrigger-0ca60599-bdf6-4c04-be67-ff0934df60ef.yml"
    click Tests "https://github.com/avansbitbybit/api/tree/master/BitByBitTrashAPI.Tests/"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:1px
    classDef internal fill:#bbdefb,stroke:#0d47a1,stroke-width:1px
    classDef external fill:#c8e6c9,stroke:#1b5e20,stroke-width:1px,stroke-dasharray: 5 5
    classDef infra fill:#ffe0b2,stroke:#e65100,stroke-width:1px
```
