# joaovictortb/espn-tennis-api architecture

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

- Interactive diagram: https://gitdiagram.com/joaovictortb/espn-tennis-api
- Repository: https://github.com/joaovictortb/espn-tennis-api

## Overview

ESPN Tennis API is a Fastify service that exposes a stable, normalized and cached API over undocumented ESPN tennis feeds. The main workflow is client request → `/v1` validation and dispatch → tennis service orchestration → ESPN fetch → normalization → enveloped response; player, tournament, news and rankings capabilities share this flow. App setup also enriches responses with resolved player photos. The excerpts establish the central calls and module dependencies; links for unsampled route branches rely on README documentation, and photo-provider details are not shown.

Main entry points: [`src/services/tennis.ts`](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/services/tennis.ts) (Tennis Services), [`src/app.ts`](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/app.ts) (Fastify App), [`src/routes/v1.ts`](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/routes/v1.ts) (V1 Routes), [`src/normalize/matches.ts`](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/matches.ts) (Match Normalizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_fastify["Fastify App<br/>[app.ts]"]
  node_v1routes["V1 Routes<br/>[v1.ts]"]
  node_contract["Response Contract<br/>[types.ts]"]
end

subgraph group_services["Domain Services"]
  node_tennis["Tennis Services<br/>[tennis.ts]"]
  node_photos["Photo Resolver<br/>[photos.ts]"]
end

subgraph group_normalization["Normalization"]
  node_matches["Match Normalizer<br/>[matches.ts]"]
  node_players["Player Normalizer<br/>[players.ts]"]
  node_news["News Normalizer<br/>[news.ts]"]
  node_rankings["Rankings Normalizer<br/>[rankings.ts]"]
  node_common["Normalize Helpers<br/>[common.ts]"]
end

subgraph group_upstream["ESPN Access"]
  node_espn["ESPN Feeds<br/>[client.ts]"]
end

subgraph group_foundation["Shared Runtime"]
  node_http["HTTP Transport<br/>[http.ts]"]
  node_cache[("TTL Cache<br/>[cache.ts]")]
  node_dates["Date Utilities<br/>[dates.ts]"]
  node_errors["Error Mapping<br/>[errors.ts]"]
  node_config["Runtime Config<br/>[config.ts]"]
end

node_client(("API Client"))
node_espnservice(("ESPN"))
node_photoapis(("Photo Providers"))

node_client -->|"requests"| node_fastify
node_fastify -->|"registers"| node_v1routes
node_v1routes -->|"dispatches"| node_tennis
node_v1routes -->|"normalizes summaries"| node_matches
node_tennis -->|"fetches data"| node_espn
node_tennis -->|"caches results"| node_cache
node_tennis -->|"normalizes scores"| node_matches
node_tennis -->|"normalizes profiles"| node_players
node_tennis -->|"normalizes articles"| node_news
node_tennis -->|"normalizes rankings"| node_rankings
node_espn -->|"fetches JSON"| node_http
node_espn -->|"requests feeds"| node_espnservice
node_matches -->|"uses helpers"| node_common
node_players -->|"uses helpers"| node_common
node_news -->|"uses helpers"| node_common
node_rankings -->|"uses helpers"| node_common
node_matches -->|"converts dates"| node_dates
node_players -->|"converts dates"| node_dates
node_news -->|"converts dates"| node_dates
node_fastify -->|"enriches responses"| node_photos
node_photos -.->|"resolves photos"| node_photoapis
node_fastify -->|"configures server"| node_config
node_fastify -->|"formats errors"| node_errors
node_tennis -->|"uses settings"| node_config
node_v1routes -->|"serves typed data"| node_contract
node_tennis -->|"returns domain data"| node_contract

click node_fastify "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/app.ts"
click node_v1routes "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/routes/v1.ts"
click node_contract "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/domain/types.ts"
click node_tennis "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/services/tennis.ts"
click node_photos "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/services/photos.ts"
click node_matches "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/matches.ts"
click node_players "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/players.ts"
click node_news "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/news.ts"
click node_rankings "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/rankings.ts"
click node_common "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/common.ts"
click node_espn "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/espn/client.ts"
click node_http "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/http.ts"
click node_cache "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/cache.ts"
click node_dates "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/dates.ts"
click node_errors "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/errors.ts"
click node_config "https://github.com/joaovictortb/espn-tennis-api/blob/main/src/config.ts"

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_fastify,node_v1routes,node_contract,node_client toneBlue
class node_tennis,node_photos toneAmber
class node_matches,node_players,node_news,node_rankings,node_common toneMint
class node_espn toneRose
class node_http,node_cache,node_dates,node_errors,node_config,node_espnservice,node_photoapis toneIndigo
```

## Components

### HTTP API

- [Fastify App](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/app.ts): `src/app.ts`
- [V1 Routes](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/routes/v1.ts): `src/routes/v1.ts`
- [Response Contract](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/domain/types.ts): `src/domain/types.ts`

### Domain Services

- [Tennis Services](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/services/tennis.ts): `src/services/tennis.ts`
- [Photo Resolver](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/services/photos.ts): `src/services/photos.ts`

### Normalization

- [Match Normalizer](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/matches.ts): `src/normalize/matches.ts`
- [Player Normalizer](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/players.ts): `src/normalize/players.ts`
- [News Normalizer](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/news.ts): `src/normalize/news.ts`
- [Rankings Normalizer](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/rankings.ts): `src/normalize/rankings.ts`
- [Normalize Helpers](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/normalize/common.ts): `src/normalize/common.ts`

### ESPN Access

- [ESPN Feeds](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/espn/client.ts): `src/espn/client.ts`

### Shared Runtime

- [HTTP Transport](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/http.ts): `src/lib/http.ts`
- [TTL Cache](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/cache.ts): `src/lib/cache.ts`
- [Date Utilities](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/dates.ts): `src/lib/dates.ts`
- [Error Mapping](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/lib/errors.ts): `src/lib/errors.ts`
- [Runtime Config](https://github.com/joaovictortb/espn-tennis-api/blob/main/src/config.ts): `src/config.ts`

### Other components

- **API Client**
- **ESPN**
- **Photo Providers**

## Connections

- API Client → Fastify App: requests (evidence: `README.md`)
- Fastify App → V1 Routes: registers (evidence: `src/app.ts`)
- V1 Routes → Tennis Services: dispatches (evidence: `src/routes/v1.ts`)
- V1 Routes → Match Normalizer: normalizes summaries (evidence: `src/routes/v1.ts`)
- Tennis Services → ESPN Feeds: fetches data (evidence: `src/services/tennis.ts`)
- Tennis Services → TTL Cache: caches results (evidence: `README.md`)
- Tennis Services → Match Normalizer: normalizes scores (evidence: `src/services/tennis.ts`)
- Tennis Services → Player Normalizer: normalizes profiles (evidence: `src/services/tennis.ts`)
- Tennis Services → News Normalizer: normalizes articles (evidence: `src/services/tennis.ts`)
- Tennis Services → Rankings Normalizer: normalizes rankings (evidence: `src/services/tennis.ts`)
- ESPN Feeds → HTTP Transport: fetches JSON (evidence: `src/espn/client.ts`)
- ESPN Feeds → ESPN: requests feeds (evidence: `src/espn/client.ts`)
- Match Normalizer → Normalize Helpers: uses helpers (evidence: `src/normalize/matches.ts`)
- Player Normalizer → Normalize Helpers: uses helpers (evidence: `src/normalize/players.ts`)
- News Normalizer → Normalize Helpers: uses helpers (evidence: `src/normalize/news.ts`)
- Rankings Normalizer → Normalize Helpers: uses helpers (evidence: `src/normalize/rankings.ts`)
- Match Normalizer → Date Utilities: converts dates (evidence: `src/normalize/matches.ts`)
- Player Normalizer → Date Utilities: converts dates (evidence: `src/normalize/players.ts`)
- News Normalizer → Date Utilities: converts dates (evidence: `src/normalize/news.ts`)
- Fastify App → Photo Resolver: enriches responses (evidence: `src/app.ts`)
- Photo Resolver → Photo Providers: resolves photos
- Fastify App → Runtime Config: configures server (evidence: `src/app.ts`)
- Fastify App → Error Mapping: formats errors (evidence: `src/app.ts`)
- Tennis Services → Runtime Config: uses settings (evidence: `src/services/tennis.ts`)
- V1 Routes → Response Contract: serves typed data (evidence: `src/routes/v1.ts`)
- Tennis Services → Response Contract: returns domain data (evidence: `src/services/tennis.ts`)
