# LiChess

Summarizing my attempts to understand LiChess.

### Arch

<https://pbs.twimg.com/media/CYGyi12UwAArCU9?format=png&name=medium>

* The main diagram is not very clear, or helpful.
* Where's Redis? Or does the diagram predate it?

### API

<https://lichess.org/api>

* They stream board events with ndjson <https://lichess.org/api#operation/apiStreamEvent>. It's long polling I suppose?
* Can't find API to actually make moves. I suppose it's done via websockets?
* Can't find API to actually do puzzles. Only see API to get daily puzzle. Perhaps it's also done with web sockets.
* There's an API to send a message, but I see no API to view messages.

### Code

{% embed url="<https://lichess.org/source>" %}

### Lila

<https://github.com/ornicar/lila>

* Doesn't seem to have many tests.
* Board literals in tests whoa <https://github.com/ornicar/scalachess/blob/master/src/test/scala/BishopTest.scala#L32-L40>

### WS

* WS deploy command whoa <https://github.com/ornicar/lila-ws/blob/master/deploy.sh> Just like that.
* **Very** magic numbers are all over the place <https://github.com/ornicar/lila-ws/blob/3bf35711609034235dcf77e2fccfc5b1c4a53a5b/src/main/scala/LilaWsServer.scala#L65-L74>
* Few comments, very hard to follow which class is doing what.
* No tests apparently.
* WFH is anaMove?
* Actually receive move from Lila <https://github.com/ornicar/lila-ws/blob/c18ac9df67893e22c2196f5745c53eae83b8251b/src/main/scala/LilaHandler.scala#L128-L132>
* Send the move to watching clients <https://github.com/ornicar/lila-ws/blob/c18ac9df67893e22c2196f5745c53eae83b8251b/src/main/scala/Fens.scala#L56-L77>

## UI

* Arguments: t, d, o. <https://github.com/ornicar/lila/blob/6bdf93d27ac08cb9321e439fcf3b10f235c373ac/ui/site/src/component/socket.ts#L147> How is anyone supposed to understand what it means?

Tracking how a move is sent to the server:

* <https://github.com/ornicar/lila/blob/97a46cfa5d7334904d0ee0698e7822ee9314d052/ui/round/src/ctrl.ts#L303>
* <https://github.com/ornicar/lila/blob/97a46cfa5d7334904d0ee0698e7822ee9314d052/ui/round/src/ctrl.ts#L277>

### Puzzler

{% embed url="<https://github.com/ornicar/lichess-puzzler>" %}

Overall, seems very basic stuff. It feels like it's possible to do a lot better.

* Main script (?) <https://github.com/ornicar/lichess-puzzler/blob/master/bin/import-more.sh>
* Generator <https://github.com/ornicar/lichess-puzzler/tree/master/generator>
* Extracting puzzle from a game <https://github.com/ornicar/lichess-puzzler/blob/master/generator/generator.py>

### Cheat detection

<https://github.com/clarkerubber/irwin>

<https://github.com/ornicar/lila/tree/master/modules/irwin/src/main>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.ainzzorl.lol/tech/open-source/lichess.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
