# anthueeccel/hackernews architecture

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

- Interactive diagram: https://gitdiagram.com/anthueeccel/hackernews
- Repository: https://github.com/anthueeccel/hackernews

## Overview

This is a small ASP.NET Core API that validates a requested story count, fetches and filters Hacker News stories, sorts them by score, and returns a public JSON response. Its internal service layer uses a bounded in-memory cache with single-flight coalescing and limited parallel fetches; the typed client calls Hacker News. README documents health and Development OpenAPI endpoints. Relationships shown come from excerpts or README; configuration wiring is visible in Program.cs, while health/OpenAPI routes are documented only.

Main entry points: [`src/HackerNews.BestStories.Api/Program.cs`](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs) (Application setup), [`src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Services/BestStoriesService.cs) (Best stories service), [`src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs`](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs) (Stories endpoint), [`src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs`](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs) (Hacker News client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_stories_route["Stories endpoint"]
  node_health["Health check<br/>[Program.cs]"]
  node_openapi["OpenAPI document<br/>[Program.cs]"]
end

subgraph group_stories["Story retrieval"]
  node_story_service["Best stories service"]
  node_cache["Single-flight cache"]
  node_memory_cache[("Bounded memory cache")]
  node_story_dto["Story response DTO<br/>[StoryResponse.cs]"]
end

subgraph group_upstream["Hacker News integration"]
  node_hn_client["Hacker News client"]
  node_hn_interface["Client contract"]
  node_hn_item["Upstream item model<br/>[HackerNewsItem.cs]"]
  node_hn_api["Hacker News API"]
end

subgraph group_runtime["Runtime configuration"]
  node_story_options["Story options<br/>[StoriesOptions.cs]"]
  node_hn_options["Upstream options"]
  node_composition["Application setup<br/>[Program.cs]"]
end

node_caller(("API caller"))

node_caller -->|"requests stories"| node_stories_route
node_stories_route -->|"calls service"| node_story_service
node_stories_route -->|"validates count"| node_story_options
node_story_service -->|"fetches IDs/items"| node_hn_interface
node_story_service -->|"gets cached values"| node_cache
node_story_service -->|"uses limits and TTLs"| node_story_options
node_story_service -->|"maps stories"| node_story_dto
node_cache -->|"reads and writes"| node_memory_cache
node_hn_client -->|"requests IDs/items"| node_hn_api
node_hn_client -->|"deserializes items"| node_hn_item
node_composition -->|"maps routes"| node_stories_route
node_composition -->|"maps health route"| node_health
node_composition -->|"enables in Development"| node_openapi
node_composition -->|"registers typed client"| node_hn_client
node_composition -->|"registers cache"| node_cache
node_composition -->|"registers service"| node_story_service
node_composition -->|"binds and validates"| node_story_options
node_composition -->|"binds and validates"| node_hn_options

click node_stories_route "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs"
click node_health "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs"
click node_openapi "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs"
click node_story_service "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Services/BestStoriesService.cs"
click node_cache "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs"
click node_memory_cache "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs"
click node_story_dto "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Models/StoryResponse.cs"
click node_hn_client "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs"
click node_hn_interface "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Clients/IHackerNewsClient.cs"
click node_hn_item "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Models/HackerNewsItem.cs"
click node_story_options "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Options/StoriesOptions.cs"
click node_hn_options "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Options/HackerNewsOptions.cs"
click node_composition "https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.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_stories_route,node_health,node_openapi toneBlue
class node_story_service,node_cache,node_memory_cache,node_story_dto toneAmber
class node_hn_client,node_hn_interface,node_hn_item,node_hn_api,node_caller toneMint
class node_story_options,node_hn_options,node_composition toneRose
```

## Components

### API surface

- [Stories endpoint](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs): `src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs`
- [Health check](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs): `src/HackerNews.BestStories.Api/Program.cs`
- [OpenAPI document](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs): `src/HackerNews.BestStories.Api/Program.cs`

### Story retrieval

- [Best stories service](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Services/BestStoriesService.cs): `src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`
- [Single-flight cache](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs): `src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs`
- [Bounded memory cache](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs): `src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs`
- [Story response DTO](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Models/StoryResponse.cs): `src/HackerNews.BestStories.Api/Models/StoryResponse.cs`

### Hacker News integration

- [Hacker News client](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs): `src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs`
- [Client contract](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Clients/IHackerNewsClient.cs): `src/HackerNews.BestStories.Api/Clients/IHackerNewsClient.cs`
- [Upstream item model](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Models/HackerNewsItem.cs): `src/HackerNews.BestStories.Api/Models/HackerNewsItem.cs`
- **Hacker News API**

### Runtime configuration

- [Story options](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Options/StoriesOptions.cs): `src/HackerNews.BestStories.Api/Options/StoriesOptions.cs`
- [Upstream options](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Options/HackerNewsOptions.cs): `src/HackerNews.BestStories.Api/Options/HackerNewsOptions.cs`
- [Application setup](https://github.com/anthueeccel/hackernews/blob/main/src/HackerNews.BestStories.Api/Program.cs): `src/HackerNews.BestStories.Api/Program.cs`

### Other components

- **API caller**

## Connections

- API caller → Stories endpoint: requests stories (evidence: `README.md`)
- Stories endpoint → Best stories service: calls service (evidence: `src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs`)
- Stories endpoint → Story options: validates count (evidence: `src/HackerNews.BestStories.Api/Endpoints/StoriesEndpoints.cs`)
- Best stories service → Client contract: fetches IDs/items (evidence: `src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`)
- Best stories service → Single-flight cache: gets cached values (evidence: `src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`)
- Best stories service → Story options: uses limits and TTLs (evidence: `src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`)
- Best stories service → Story response DTO: maps stories (evidence: `src/HackerNews.BestStories.Api/Services/BestStoriesService.cs`)
- Single-flight cache → Bounded memory cache: reads and writes (evidence: `src/HackerNews.BestStories.Api/Infrastructure/SingleFlightCache.cs`)
- Hacker News client → Hacker News API: requests IDs/items (evidence: `README.md`)
- Hacker News client → Upstream item model: deserializes items (evidence: `src/HackerNews.BestStories.Api/Clients/HackerNewsClient.cs`)
- Application setup → Stories endpoint: maps routes (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Health check: maps health route (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → OpenAPI document: enables in Development (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Hacker News client: registers typed client (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Single-flight cache: registers cache (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Best stories service: registers service (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Story options: binds and validates (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
- Application setup → Upstream options: binds and validates (evidence: `src/HackerNews.BestStories.Api/Program.cs`)
