# lichess-org/lila architecture

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

- Interactive diagram: https://gitdiagram.com/lichess-org/lila
- Repository: https://github.com/lichess-org/lila

## Overview

Lila is the Scala server behind Lichess, a realtime online chess service. A player enters through HTTP routes to create or join a game; game state and records are handled by the game domain, while live connections use the separately hosted WebSocket service. Analysis is a distinct follow-on capability, with distributed engine work supplied by fishnet. The map also retains the README’s major community, learning, competition, and API capabilities. README documents the external architecture; source excerpts sampled here are limited, so uncertain module-to-module wiring is omitted.

Main entry points: [`app/controllers/LilaController.scala`](https://github.com/lichess-org/lila/blob/master/app/controllers/LilaController.scala) (HTTP routes), [`app/controllers/Game.scala`](https://github.com/lichess-org/lila/blob/master/app/controllers/Game.scala) (Game routes), [`modules/game/src/main/Game.scala`](https://github.com/lichess-org/lila/blob/master/modules/game/src/main/Game.scala) (Game domain), [`modules/game/src/main/GameRepo.scala`](https://github.com/lichess-org/lila/blob/master/modules/game/src/main/GameRepo.scala) (Game records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Web entry"]
  node_lila["Lila server<br/>[Lila.scala]"]
  node_http["HTTP routes"]
  node_views["Server views<br/>[player.scala]"]
end

subgraph group_play["Chess play"]
  node_game_ctrl["Game routes<br/>[Game.scala]"]
  node_game["Game domain<br/>[Game.scala]"]
  node_game_repo["Game records<br/>[GameRepo.scala]"]
  node_pgn["PGN encoding<br/>[PgnStorage.scala]"]
  node_round["Live rounds<br/>[Round.scala]"]
  node_ws["WebSocket service"]
  node_challenge["Challenges<br/>[ChallengeApi.scala]"]
  node_lobby["Lobby<br/>[LobbyApi.scala]"]
end

subgraph group_analysis["Analysis"]
  node_analysis_ctrl["Analysis routes<br/>[Analyse.scala]"]
  node_analysis["Computer analysis<br/>[Analyser.scala]"]
  node_fishnet["Fishnet workers<br/>[FishnetApi.scala]"]
  node_fishnet_service["Fishnet cluster"]
end

subgraph group_community["Community and learning"]
  node_study["Shared studies<br/>[Study.scala]"]
  node_tournament["Tournaments<br/>[Tournament.scala]"]
  node_simul["Simultaneous games<br/>[Simul.scala]"]
  node_forum["Forums"]
  node_team["Teams<br/>[Team.scala]"]
  node_puzzle["Tactic trainer<br/>[Puzzle.scala]"]
  node_learn["Learning<br/>[Learn.scala]"]
end

subgraph group_platform["Data and APIs"]
  node_redis[("Redis")]
  node_api["Public API<br/>[GameApi.scala]"]
  node_mongo[("MongoDB")]
  node_search["Game search<br/>[AnySearch.scala]"]
  node_elasticsearch[("Elasticsearch")]
end

node_player(("Player"))

node_player -->|"sends requests"| node_http
node_lila -->|"serves routes"| node_http
node_http -->|"dispatches"| node_game_ctrl
node_game_ctrl -->|"handles games"| node_game
node_game -->|"reads and writes"| node_game_repo
node_game_repo -->|"stores records"| node_mongo
node_game -->|"encodes moves"| node_pgn
node_player -->|"plays live"| node_round
node_round -->|"uses live sockets"| node_ws
node_ws -->|"communicates through"| node_redis
node_game_ctrl -->|"manages challenges"| node_challenge
node_player -->|"browses games"| node_lobby
node_player -->|"requests analysis"| node_analysis_ctrl
node_analysis_ctrl -->|"serves analysis"| node_analysis
node_analysis -->|"dispatches engine work"| node_fishnet
node_fishnet -->|"requests computation"| node_fishnet_service
node_player -->|"shares analysis"| node_study
node_player -->|"enters competition"| node_tournament
node_player -->|"joins simul"| node_simul
node_player -->|"posts discussions"| node_forum
node_player -->|"uses teams"| node_team
node_player -->|"trains tactics"| node_puzzle
node_player -->|"learns chess"| node_learn
node_player -->|"accesses API"| node_api
node_api -->|"reads game data"| node_mongo
node_player -->|"searches games"| node_search
node_search -->|"queries index"| node_elasticsearch
node_http -->|"renders pages"| node_views

click node_lila "https://github.com/lichess-org/lila/blob/master/app/Lila.scala"
click node_http "https://github.com/lichess-org/lila/blob/master/app/controllers/LilaController.scala"
click node_game_ctrl "https://github.com/lichess-org/lila/blob/master/app/controllers/Game.scala"
click node_game "https://github.com/lichess-org/lila/blob/master/modules/game/src/main/Game.scala"
click node_game_repo "https://github.com/lichess-org/lila/blob/master/modules/game/src/main/GameRepo.scala"
click node_pgn "https://github.com/lichess-org/lila/blob/master/modules/game/src/main/PgnStorage.scala"
click node_round "https://github.com/lichess-org/lila/blob/master/app/controllers/Round.scala"
click node_challenge "https://github.com/lichess-org/lila/blob/master/modules/challenge/src/main/ChallengeApi.scala"
click node_lobby "https://github.com/lichess-org/lila/blob/master/modules/api/src/main/LobbyApi.scala"
click node_analysis_ctrl "https://github.com/lichess-org/lila/blob/master/app/controllers/Analyse.scala"
click node_analysis "https://github.com/lichess-org/lila/blob/master/modules/analyse/src/main/Analyser.scala"
click node_fishnet "https://github.com/lichess-org/lila/blob/master/modules/fishnet/src/main/FishnetApi.scala"
click node_study "https://github.com/lichess-org/lila/blob/master/app/controllers/Study.scala"
click node_tournament "https://github.com/lichess-org/lila/blob/master/app/controllers/Tournament.scala"
click node_simul "https://github.com/lichess-org/lila/blob/master/app/controllers/Simul.scala"
click node_forum "https://github.com/lichess-org/lila/blob/master/modules/forum/src/main/ForumTopicApi.scala"
click node_team "https://github.com/lichess-org/lila/blob/master/app/controllers/Team.scala"
click node_puzzle "https://github.com/lichess-org/lila/blob/master/app/controllers/Puzzle.scala"
click node_learn "https://github.com/lichess-org/lila/blob/master/app/controllers/Learn.scala"
click node_api "https://github.com/lichess-org/lila/blob/master/modules/api/src/main/GameApi.scala"
click node_search "https://github.com/lichess-org/lila/blob/master/modules/api/src/main/AnySearch.scala"
click node_views "https://github.com/lichess-org/lila/blob/master/app/views/round/player.scala"

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_lila,node_http,node_views toneBlue
class node_game_ctrl,node_game,node_game_repo,node_pgn,node_round,node_ws,node_challenge,node_lobby toneAmber
class node_analysis_ctrl,node_analysis,node_fishnet,node_fishnet_service toneMint
class node_study,node_tournament,node_simul,node_forum,node_team,node_puzzle,node_learn toneRose
class node_redis,node_api,node_mongo,node_search,node_elasticsearch,node_player toneIndigo
```

## Components

### Web entry

- [Lila server](https://github.com/lichess-org/lila/blob/master/app/Lila.scala): `app/Lila.scala`
- [HTTP routes](https://github.com/lichess-org/lila/blob/master/app/controllers/LilaController.scala): `app/controllers/LilaController.scala`
- [Server views](https://github.com/lichess-org/lila/blob/master/app/views/round/player.scala): `app/views/round/player.scala`

### Chess play

- [Game routes](https://github.com/lichess-org/lila/blob/master/app/controllers/Game.scala): `app/controllers/Game.scala`
- [Game domain](https://github.com/lichess-org/lila/blob/master/modules/game/src/main/Game.scala): `modules/game/src/main/Game.scala`
- [Game records](https://github.com/lichess-org/lila/blob/master/modules/game/src/main/GameRepo.scala): `modules/game/src/main/GameRepo.scala`
- [PGN encoding](https://github.com/lichess-org/lila/blob/master/modules/game/src/main/PgnStorage.scala): `modules/game/src/main/PgnStorage.scala`
- [Live rounds](https://github.com/lichess-org/lila/blob/master/app/controllers/Round.scala): `app/controllers/Round.scala`
- **WebSocket service**
- [Challenges](https://github.com/lichess-org/lila/blob/master/modules/challenge/src/main/ChallengeApi.scala): `modules/challenge/src/main/ChallengeApi.scala`
- [Lobby](https://github.com/lichess-org/lila/blob/master/modules/api/src/main/LobbyApi.scala): `modules/api/src/main/LobbyApi.scala`

### Analysis

- [Analysis routes](https://github.com/lichess-org/lila/blob/master/app/controllers/Analyse.scala): `app/controllers/Analyse.scala`
- [Computer analysis](https://github.com/lichess-org/lila/blob/master/modules/analyse/src/main/Analyser.scala): `modules/analyse/src/main/Analyser.scala`
- [Fishnet workers](https://github.com/lichess-org/lila/blob/master/modules/fishnet/src/main/FishnetApi.scala): `modules/fishnet/src/main/FishnetApi.scala`
- **Fishnet cluster**

### Community and learning

- [Shared studies](https://github.com/lichess-org/lila/blob/master/app/controllers/Study.scala): `app/controllers/Study.scala`
- [Tournaments](https://github.com/lichess-org/lila/blob/master/app/controllers/Tournament.scala): `app/controllers/Tournament.scala`
- [Simultaneous games](https://github.com/lichess-org/lila/blob/master/app/controllers/Simul.scala): `app/controllers/Simul.scala`
- [Forums](https://github.com/lichess-org/lila/blob/master/modules/forum/src/main/ForumTopicApi.scala): `modules/forum/src/main/ForumTopicApi.scala`
- [Teams](https://github.com/lichess-org/lila/blob/master/app/controllers/Team.scala): `app/controllers/Team.scala`
- [Tactic trainer](https://github.com/lichess-org/lila/blob/master/app/controllers/Puzzle.scala): `app/controllers/Puzzle.scala`
- [Learning](https://github.com/lichess-org/lila/blob/master/app/controllers/Learn.scala): `app/controllers/Learn.scala`

### Data and APIs

- **Redis**
- [Public API](https://github.com/lichess-org/lila/blob/master/modules/api/src/main/GameApi.scala): `modules/api/src/main/GameApi.scala`
- **MongoDB**
- [Game search](https://github.com/lichess-org/lila/blob/master/modules/api/src/main/AnySearch.scala): `modules/api/src/main/AnySearch.scala`
- **Elasticsearch**

### Other components

- **Player**

## Connections

- Player → HTTP routes: sends requests
- Lila server → HTTP routes: serves routes
- HTTP routes → Game routes: dispatches
- Game routes → Game domain: handles games
- Game domain → Game records: reads and writes
- Game records → MongoDB: stores records
- Game domain → PGN encoding: encodes moves
- Player → Live rounds: plays live
- Live rounds → WebSocket service: uses live sockets
- WebSocket service → Redis: communicates through
- Game routes → Challenges: manages challenges
- Player → Lobby: browses games
- Player → Analysis routes: requests analysis
- Analysis routes → Computer analysis: serves analysis
- Computer analysis → Fishnet workers: dispatches engine work
- Fishnet workers → Fishnet cluster: requests computation
- Player → Shared studies: shares analysis
- Player → Tournaments: enters competition
- Player → Simultaneous games: joins simul
- Player → Forums: posts discussions
- Player → Teams: uses teams
- Player → Tactic trainer: trains tactics
- Player → Learning: learns chess
- Player → Public API: accesses API
- Public API → MongoDB: reads game data
- Player → Game search: searches games
- Game search → Elasticsearch: queries index
- HTTP routes → Server views: renders pages
