Overview
Discover what makes Lichess powerful
Lila is the core engine behind the open‑source chess platform lichess.org. Written in **Scala 3** and built atop the **Play 2.8** web framework, it delivers a fully asynchronous server that can handle millions of concurrent users while keeping latency low for real‑time gameplay. The architecture splits responsibilities across several micro‑services: the main HTTP server, a dedicated WebSocket gateway (`lila-ws`), and an AI cluster that runs Stockfish instances via the `fishnet` distributed engine. Communication between services is largely event‑driven and leverages **Akka Streams** for back‑pressure control, while transient state is stored in a Redis cluster to enable fast pub/sub and session persistence.
Language & Framework
Concurrency
Data Stores
AI Integration
Overview
Lila is the core engine behind the open‑source chess platform lichess.org. Written in Scala 3 and built atop the Play 2.8 web framework, it delivers a fully asynchronous server that can handle millions of concurrent users while keeping latency low for real‑time gameplay. The architecture splits responsibilities across several micro‑services: the main HTTP server, a dedicated WebSocket gateway (lila-ws), and an AI cluster that runs Stockfish instances via the fishnet distributed engine. Communication between services is largely event‑driven and leverages Akka Streams for back‑pressure control, while transient state is stored in a Redis cluster to enable fast pub/sub and session persistence.
Technical Stack
- Language & Framework: Scala 3, Play 2.8 (MVC + JSON API), Scalatags for server‑side templating.
- Concurrency: Scala
Futures, Akka Streams, and Play’s async HTTP pipeline. - Data Stores: MongoDB (raw game records), Elasticsearch (full‑text search over millions of games), Redis (pub/sub, WebSocket session state).
- AI Integration: Stockfish binaries orchestrated by the
fishnetcluster; communication via gRPC‑style sockets. - Client Side: TypeScript + Snabbdom for virtual DOM diffing, Sass for CSS preprocessing.
- Testing & CI: BrowserStack for cross‑browser testing, IP2Proxy database for proxy detection.
Core Capabilities
- REST & WebSocket APIs: Expose game creation, move streams, tournament standings, and user data. Endpoints are versioned (
/api/v3/...) and support JSON‑only payloads, making them ideal for mobile or third‑party clients. - Event Bus: Internal
lila-eventbus publishes domain events (e.g.,GameFinished,UserRated) that can be subscribed to by plugins or external services via Redis streams. - Plugin System: Lila exposes a lightweight plugin API; developers can register custom handlers for game events, add new REST endpoints, or hook into the search index. The plugin repository is documented in
docs/plugins.md. - Webhooks: External services can subscribe to user or game events via configurable webhooks, enabling real‑time integrations (e.g., Discord bots, analytics dashboards).
Deployment & Infrastructure
Lila is container‑friendly: the source repository includes Dockerfiles for both the HTTP server and WebSocket gateway. A typical production stack uses:
- Docker Compose or Kubernetes manifests (see
deploy/k8s/). - Nginx as a reverse proxy for HTTPS termination and HTTP caching.
- Redis Cluster (≥ 3 nodes) for session storage and pub/sub.
- MongoDB Replica Set (≥ 3 nodes) for durability of game records.
- Elasticsearch Cluster for search indexing, optionally sharded by user or game type.
Horizontal scaling is straightforward: new HTTP workers can be spun up behind the load balancer, while WebSocket nodes handle real‑time traffic via Redis pub/sub. The AI cluster is entirely decoupled; any machine with a CPU can join fishnet, allowing community‑driven scaling.
Integration & Extensibility
- SDKs: A minimal Scala client library (
lila-client) is available for building custom bots or analytics tools. - GraphQL Support: While not yet fully featured, the platform is gradually adopting GraphQL for flexible data retrieval.
- Custom Themes & UI: The TypeScript front‑end is modular; developers can fork the
uirepo, replace components, or add new widgets that communicate via the existing WebSocket protocol. - Community Plugins: The ecosystem includes a handful of community plugins (e.g.,
lichess-puzzle‑generator,lichess-bot‑framework) that demonstrate the extensibility model.
Developer Experience
- Documentation: Comprehensive API docs (
docs/api.md), architecture guide (docs/architecture.md), and a dev‑setup tutorial in the README. - Community: Active Discord channel, GitHub discussions, and a dedicated issue tracker for plugin development.
- Licensing: MIT license for the core server, allowing commercial use without copyleft obligations.
- Testing: Unit tests written in ScalaTest and integration tests orchestrated via Docker Compose; continuous integration runs on GitHub Actions.
Use Cases
- Self‑hosted Chess Server: Small clubs or schools can deploy Lila to provide a private, ad‑free chess environment.
- Custom Bot Development: Using the WebSocket API and
fishnet, developers can build sophisticated chess engines or training bots. - Analytics Platform: Pull game data via the REST API, index it in Elasticsearch, and build dashboards for player performance or tournament statistics.
- Educational Tools: Integrate Lila’s tactical trainer into e‑learning platforms, exposing the training API to students.
Advantages
- Performance: Scala’s type safety combined with Play’s async I/O yields low‑latency, high‑throughput handling of game streams.
- Flexibility: The plugin architecture and event bus allow developers to inject custom logic without touching the core codebase.
- Scalability: Decoupled services (HTTP, WS, AI) and use of Redis/MongoDB/Elasticsearch
Open SourceReady to get started?
Join the community and start self-hosting Lichess today
Related Apps in other
Immich
Self‑hosted photo and video manager
Syncthing
Peer‑to‑peer file sync, no central server
Strapi
Open-source headless CMS for modern developers
reveal.js
Create stunning web‑based presentations with HTML, CSS and JavaScript
Stirling-PDF
Local web PDF editor with split, merge, convert and more
MinIO
Fast, S3-compatible object storage for AI and analytics
Weekly Views
Repository Health
Information
Explore More Apps
FOSSBilling
Open‑source billing and client management for hosting businesses
iSponsorBlockTV
Auto‑skip YouTube TV ads and sponsors on any smart TV
Mailu
Docker‑based, feature‑rich mail server for self‑hosters
QuickShare
Fast, secure file sharing across devices
Maza Ad Blocking
Local ad blocker, no extensions needed
linkding
Self‑hosted bookmark manager for minimal, fast organization
