# stefanosvasileiou/apiaggregator architecture

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

- Interactive diagram: https://gitdiagram.com/stefanosvasileiou/apiaggregator
- Repository: https://github.com/stefanosvasileiou/apiaggregator

## Overview

ApiAggregator is an ASP.NET Core service that exposes authenticated aggregation and statistics endpoints, plus anonymous token and health endpoints. Its main workflow validates an aggregation request, fans out to selected sources, uses fresh or stale cached results when appropriate, and returns normalized, filtered, sorted items with explicit source degradation. Separate runtime capabilities record outbound-request latency and monitor it for anomalies. The excerpts show orchestration and registration; the README documents resilience and API behavior, while some endpoint wiring and source details are only partially sampled.

Main entry points: [`src/ApiAggregator.Core/Aggregation/AggregationService.cs`](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Aggregation/AggregationService.cs) (Aggregation service), [`src/ApiAggregator.Api/Program.cs`](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs) (Aggregate endpoint), [`src/ApiAggregator.Core/Statistics/ApiStatsStore.cs`](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Statistics/ApiStatsStore.cs) (Stats store), [`src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs`](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs) (Anomaly monitor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and auth"]
  node_token_endpoint["Token endpoint<br/>[Program.cs]"]
  node_jwt_auth["JWT auth<br/>[Program.cs]"]
  node_aggregate_endpoint["Aggregate endpoint<br/>[Program.cs]"]
  node_stats_endpoint["Stats endpoint<br/>[Program.cs]"]
  node_health_endpoint["Health endpoint<br/>[Program.cs]"]
end

subgraph group_aggregation["Aggregation"]
  node_aggregation_service["Aggregation service"]
  node_source_cache[("Memory cache")]
end

subgraph group_sources["Data sources"]
  node_github_source["GitHub source<br/>[GitHubSource.cs]"]
  node_hackernews_source["Hacker News source"]
  node_newsapi_source["NewsAPI source<br/>[NewsApiSource.cs]"]
end

subgraph group_observability["Observability"]
  node_stats_handler["Stats handler"]
  node_stats_store[("Stats store<br/>[ApiStatsStore.cs]")]
  node_anomaly_monitor["Anomaly monitor"]
  node_anomaly_detector["Anomaly detector<br/>[AnomalyDetector.cs]"]
end

node_caller(("API caller"))
node_github_api["GitHub API"]
node_hackernews_api["Hacker News API"]
node_newsapi["NewsAPI"]

node_caller -->|"requests token"| node_token_endpoint
node_token_endpoint -->|"returns JWT"| node_caller
node_caller -->|"requests results"| node_aggregate_endpoint
node_caller -->|"requests stats"| node_stats_endpoint
node_caller -->|"checks health"| node_health_endpoint
node_aggregate_endpoint -->|"requires authorization"| node_jwt_auth
node_stats_endpoint -->|"requires authorization"| node_jwt_auth
node_aggregate_endpoint -->|"calls aggregate"| node_aggregation_service
node_aggregation_service -->|"reads and writes"| node_source_cache
node_aggregation_service -->|"fetches selected"| node_github_source
node_aggregation_service -->|"fetches selected"| node_hackernews_source
node_aggregation_service -->|"fetches selected"| node_newsapi_source
node_github_source -->|"fetches data"| node_github_api
node_hackernews_source -->|"fetches data"| node_hackernews_api
node_newsapi_source -.->|"fetches data"| node_newsapi
node_stats_endpoint -->|"reads snapshot"| node_stats_store
node_stats_handler -->|"records latency"| node_stats_store
node_anomaly_monitor -->|"reads windowed stats"| node_stats_store
node_anomaly_monitor -->|"checks anomalies"| node_anomaly_detector

click node_token_endpoint "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs"
click node_jwt_auth "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs"
click node_aggregate_endpoint "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs"
click node_stats_endpoint "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs"
click node_health_endpoint "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs"
click node_aggregation_service "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Aggregation/AggregationService.cs"
click node_source_cache "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Caching/MemoryCacheSourceCache.cs"
click node_github_source "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/GitHubSource.cs"
click node_hackernews_source "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/HackerNewsSource.cs"
click node_newsapi_source "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/NewsApiSource.cs"
click node_stats_handler "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Resilience/StatsRecordingHandler.cs"
click node_stats_store "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Statistics/ApiStatsStore.cs"
click node_anomaly_monitor "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs"
click node_anomaly_detector "https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Statistics/AnomalyDetector.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_token_endpoint,node_jwt_auth,node_aggregate_endpoint,node_stats_endpoint,node_health_endpoint toneBlue
class node_aggregation_service,node_source_cache toneAmber
class node_github_source,node_hackernews_source,node_newsapi_source,node_caller,node_github_api,node_hackernews_api,node_newsapi toneMint
class node_stats_handler,node_stats_store,node_anomaly_monitor,node_anomaly_detector toneRose
```

## Components

### API and auth

- [Token endpoint](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs): `src/ApiAggregator.Api/Program.cs`
- [JWT auth](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs): `src/ApiAggregator.Api/Program.cs`
- [Aggregate endpoint](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs): `src/ApiAggregator.Api/Program.cs`
- [Stats endpoint](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs): `src/ApiAggregator.Api/Program.cs`
- [Health endpoint](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Api/Program.cs): `src/ApiAggregator.Api/Program.cs`

### Aggregation

- [Aggregation service](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Aggregation/AggregationService.cs): `src/ApiAggregator.Core/Aggregation/AggregationService.cs`
- [Memory cache](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Caching/MemoryCacheSourceCache.cs): `src/ApiAggregator.Core/Caching/MemoryCacheSourceCache.cs`

### Data sources

- [GitHub source](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/GitHubSource.cs): `src/ApiAggregator.Core/Sources/GitHubSource.cs`
- [Hacker News source](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/HackerNewsSource.cs): `src/ApiAggregator.Core/Sources/HackerNewsSource.cs`
- [NewsAPI source](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Sources/NewsApiSource.cs): `src/ApiAggregator.Core/Sources/NewsApiSource.cs`

### Observability

- [Stats handler](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Resilience/StatsRecordingHandler.cs): `src/ApiAggregator.Core/Resilience/StatsRecordingHandler.cs`
- [Stats store](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Statistics/ApiStatsStore.cs): `src/ApiAggregator.Core/Statistics/ApiStatsStore.cs`
- [Anomaly monitor](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs): `src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs`
- [Anomaly detector](https://github.com/stefanosvasileiou/apiaggregator/blob/main/src/ApiAggregator.Core/Statistics/AnomalyDetector.cs): `src/ApiAggregator.Core/Statistics/AnomalyDetector.cs`

### Other components

- **API caller**
- **GitHub API**
- **Hacker News API**
- **NewsAPI**

## Connections

- API caller → Token endpoint: requests token (evidence: `README.md`)
- Token endpoint → API caller: returns JWT (evidence: `src/ApiAggregator.Api/Program.cs`)
- API caller → Aggregate endpoint: requests results (evidence: `README.md`)
- API caller → Stats endpoint: requests stats (evidence: `README.md`)
- API caller → Health endpoint: checks health (evidence: `README.md`)
- Aggregate endpoint → JWT auth: requires authorization (evidence: `src/ApiAggregator.Api/Program.cs`)
- Stats endpoint → JWT auth: requires authorization (evidence: `README.md`)
- Aggregate endpoint → Aggregation service: calls aggregate (evidence: `src/ApiAggregator.Api/Program.cs`)
- Aggregation service → Memory cache: reads and writes (evidence: `src/ApiAggregator.Core/Aggregation/AggregationService.cs`)
- Aggregation service → GitHub source: fetches selected (evidence: `src/ApiAggregator.Core/Aggregation/AggregationService.cs`)
- Aggregation service → Hacker News source: fetches selected (evidence: `src/ApiAggregator.Core/Aggregation/AggregationService.cs`)
- Aggregation service → NewsAPI source: fetches selected (evidence: `src/ApiAggregator.Core/Aggregation/AggregationService.cs`)
- GitHub source → GitHub API: fetches data (evidence: `README.md`)
- Hacker News source → Hacker News API: fetches data (evidence: `README.md`)
- NewsAPI source → NewsAPI: fetches data (evidence: `README.md`)
- Stats endpoint → Stats store: reads snapshot (evidence: `src/ApiAggregator.Api/Program.cs`)
- Stats handler → Stats store: records latency (evidence: `src/ApiAggregator.Core/Resilience/StatsRecordingHandler.cs`)
- Anomaly monitor → Stats store: reads windowed stats (evidence: `src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs`)
- Anomaly monitor → Anomaly detector: checks anomalies (evidence: `src/ApiAggregator.Core/BackgroundServices/PerformanceAnomalyMonitor.cs`)
