# kena-at/fpl_lens architecture

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

- Interactive diagram: https://gitdiagram.com/kena-at/fpl_lens
- Repository: https://github.com/kena-at/fpl_lens

## Overview

FPL Lens is a Fantasy Premier League backend API. Its visible workflows include account registration and sign-in, authenticated access to FPL team data, and projection generation and publication; the repository also contains FPL data ingestion and squad optimization capabilities. The README provides no additional product detail, and several route and service implementations were not sampled, so links to those subsystems are limited to relationships visible in the application wiring or source index.

Main entry points: [`src/fpl_lens/api/app.py`](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/app.py) (API application), [`src/fpl_lens/db/models.py`](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/db/models.py) (Application database), [`src/fpl_lens/engine/service.py`](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/service.py) (Projection persistence), [`src/fpl_lens/api/routes/auth.py`](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/auth.py) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_entry["API application<br/>[app.py]"]
  node_auth["Authentication routes<br/>[auth.py]"]
  node_deps["Request dependencies<br/>[deps.py]"]
end

subgraph group_fpl["FPL data"]
  node_proxy["FPL proxy routes<br/>[fpl_proxy.py]"]
  node_jobs["Internal job routes<br/>[internal_jobs.py]"]
  node_ingestion["FPL ingestion<br/>[ingestion.py]"]
  node_fpl_client["FPL API client<br/>[fpl_client.py]"]
end

subgraph group_projections["Projection engine"]
  node_projection_routes["Projection routes<br/>[projections.py]"]
  node_squad_routes["Squad routes<br/>[squads.py]"]
  node_engine_service["Projection persistence<br/>[service.py]"]
  node_projection["Projection model<br/>[projection.py]"]
  node_playing_time["Playing-time model<br/>[playing_time.py]"]
  node_projection_v2["Layer 1 v2<br/>[projection_v2.py]"]
  node_v2_playing["V2 playing time<br/>[playing_time_v2.py]"]
  node_optimiser["Squad optimizer<br/>[optimiser.py]"]
end

subgraph group_platform["Persistence and services"]
  node_database[("Application database<br/>[models.py]")]
  node_session["Database session<br/>[session.py]"]
  node_cache["FPL response cache<br/>[cache.py]"]
  node_rate_limiter["Rate limiter<br/>[rate_limiter.py]"]
  node_token["Token service<br/>[token.py]"]
  node_backup["User backup<br/>[backup.py]"]
end

node_client(("API client"))
node_external_fpl(("FPL service"))

node_client -->|"sends requests"| node_entry
node_entry -->|"registers routes"| node_auth
node_entry -->|"registers routes"| node_proxy
node_entry -->|"registers routes"| node_projection_routes
node_entry -->|"registers routes"| node_squad_routes
node_entry -->|"registers routes"| node_jobs
node_auth -->|"uses dependencies"| node_deps
node_auth -->|"reads and writes"| node_database
node_auth -->|"uses tokens"| node_token
node_deps -->|"gets sessions"| node_session
node_deps -->|"loads users"| node_database
node_deps -->|"decodes tokens"| node_token
node_proxy -->|"fetches FPL data"| node_fpl_client
node_proxy -->|"reads and writes"| node_cache
node_proxy -->|"enriches picks"| node_database
node_fpl_client -->|"requests data"| node_external_fpl
node_fpl_client -->|"throttles requests"| node_rate_limiter
node_ingestion -->|"fetches source data"| node_fpl_client
node_ingestion -->|"writes FPL data"| node_database
node_ingestion -->|"invokes engine"| node_engine_service
node_jobs -.->|"triggers projection job"| node_engine_service
node_engine_service -->|"loads and publishes"| node_database
node_engine_service -->|"uses model"| node_projection
node_projection_v2 -->|"computes playing time"| node_v2_playing
node_projection_routes -.->|"requests projections"| node_engine_service
node_squad_routes -.->|"requests optimization"| node_optimiser
node_backup -.->|"backs up user data"| node_database

click node_entry "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/app.py"
click node_auth "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/auth.py"
click node_deps "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/deps.py"
click node_proxy "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/fpl_proxy.py"
click node_projection_routes "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/projections.py"
click node_squad_routes "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/squads.py"
click node_jobs "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/internal_jobs.py"
click node_ingestion "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/ingestion.py"
click node_fpl_client "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/fpl_client.py"
click node_engine_service "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/service.py"
click node_projection "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/projection.py"
click node_playing_time "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/playing_time.py"
click node_projection_v2 "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/layer1_v2/projection_v2.py"
click node_v2_playing "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/layer1_v2/playing_time_v2.py"
click node_optimiser "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/optimiser.py"
click node_database "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/db/models.py"
click node_session "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/db/session.py"
click node_cache "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/cache.py"
click node_rate_limiter "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/rate_limiter.py"
click node_token "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/token.py"
click node_backup "https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/backup.py"

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_entry,node_auth,node_deps,node_client toneBlue
class node_proxy,node_jobs,node_ingestion,node_fpl_client toneAmber
class node_projection_routes,node_squad_routes,node_engine_service,node_projection,node_playing_time,node_projection_v2,node_v2_playing,node_optimiser toneMint
class node_database,node_session,node_cache,node_rate_limiter,node_token,node_backup toneRose
class node_external_fpl toneIndigo
```

## Components

### API and identity

- [API application](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/app.py): `src/fpl_lens/api/app.py`
- [Authentication routes](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/auth.py): `src/fpl_lens/api/routes/auth.py`
- [Request dependencies](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/deps.py): `src/fpl_lens/api/deps.py`

### FPL data

- [FPL proxy routes](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/fpl_proxy.py): `src/fpl_lens/api/routes/fpl_proxy.py`
- [Internal job routes](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/internal_jobs.py): `src/fpl_lens/api/routes/internal_jobs.py`
- [FPL ingestion](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/ingestion.py): `src/fpl_lens/services/ingestion.py`
- [FPL API client](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/fpl_client.py): `src/fpl_lens/services/fpl_client.py`

### Projection engine

- [Projection routes](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/projections.py): `src/fpl_lens/api/routes/projections.py`
- [Squad routes](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/api/routes/squads.py): `src/fpl_lens/api/routes/squads.py`
- [Projection persistence](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/service.py): `src/fpl_lens/engine/service.py`
- [Projection model](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/projection.py): `src/fpl_lens/engine/projection.py`
- [Playing-time model](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/playing_time.py): `src/fpl_lens/engine/playing_time.py`
- [Layer 1 v2](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/layer1_v2/projection_v2.py): `src/fpl_lens/engine/layer1_v2/projection_v2.py`
- [V2 playing time](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/layer1_v2/playing_time_v2.py): `src/fpl_lens/engine/layer1_v2/playing_time_v2.py`
- [Squad optimizer](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/engine/optimiser.py): `src/fpl_lens/engine/optimiser.py`

### Persistence and services

- [Application database](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/db/models.py): `src/fpl_lens/db/models.py`
- [Database session](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/db/session.py): `src/fpl_lens/db/session.py`
- [FPL response cache](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/cache.py): `src/fpl_lens/services/cache.py`
- [Rate limiter](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/rate_limiter.py): `src/fpl_lens/services/rate_limiter.py`
- [Token service](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/token.py): `src/fpl_lens/services/token.py`
- [User backup](https://github.com/kena-at/fpl_lens/blob/main/src/fpl_lens/services/backup.py): `src/fpl_lens/services/backup.py`

### Other components

- **API client**
- **FPL service**

## Connections

- API client → API application: sends requests
- API application → Authentication routes: registers routes (evidence: `src/fpl_lens/api/app.py`)
- API application → FPL proxy routes: registers routes (evidence: `src/fpl_lens/api/app.py`)
- API application → Projection routes: registers routes (evidence: `src/fpl_lens/api/app.py`)
- API application → Squad routes: registers routes (evidence: `src/fpl_lens/api/app.py`)
- API application → Internal job routes: registers routes (evidence: `src/fpl_lens/api/app.py`)
- Authentication routes → Request dependencies: uses dependencies (evidence: `src/fpl_lens/api/routes/auth.py`)
- Authentication routes → Application database: reads and writes (evidence: `src/fpl_lens/api/routes/auth.py`)
- Authentication routes → Token service: uses tokens (evidence: `src/fpl_lens/api/routes/auth.py`)
- Request dependencies → Database session: gets sessions (evidence: `src/fpl_lens/api/deps.py`)
- Request dependencies → Application database: loads users (evidence: `src/fpl_lens/api/deps.py`)
- Request dependencies → Token service: decodes tokens (evidence: `src/fpl_lens/api/deps.py`)
- FPL proxy routes → FPL API client: fetches FPL data (evidence: `src/fpl_lens/api/routes/fpl_proxy.py`)
- FPL proxy routes → FPL response cache: reads and writes (evidence: `src/fpl_lens/api/routes/fpl_proxy.py`)
- FPL proxy routes → Application database: enriches picks (evidence: `src/fpl_lens/api/routes/fpl_proxy.py`)
- FPL API client → FPL service: requests data (evidence: `src/fpl_lens/services/fpl_client.py`)
- FPL API client → Rate limiter: throttles requests (evidence: `src/fpl_lens/services/fpl_client.py`)
- FPL ingestion → FPL API client: fetches source data (evidence: `src/fpl_lens/services/ingestion.py`)
- FPL ingestion → Application database: writes FPL data (evidence: `src/fpl_lens/services/ingestion.py`)
- FPL ingestion → Projection persistence: invokes engine (evidence: `src/fpl_lens/services/ingestion.py`)
- Internal job routes → Projection persistence: triggers projection job
- Projection persistence → Application database: loads and publishes (evidence: `src/fpl_lens/engine/service.py`)
- Projection persistence → Projection model: uses model (evidence: `src/fpl_lens/engine/service.py`)
- Layer 1 v2 → V2 playing time: computes playing time (evidence: `src/fpl_lens/engine/layer1_v2/projection_v2.py`)
- Projection routes → Projection persistence: requests projections
- Squad routes → Squad optimizer: requests optimization
- User backup → Application database: backs up user data
