# lemononmars/mathdle architecture

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

- Interactive diagram: https://gitdiagram.com/lemononmars/mathdle
- Repository: https://github.com/lemononmars/mathdle

## Overview

Mathdle is a browser-based daily equation-guessing game: a player submits a valid equation, the app compares it with a seeded solution, displays character feedback, and saves attempts for later. The graph also includes the documented adjustable difficulty and sharing flow, plus the help and presentation components. The sampled source shows the main calls and persistence behavior; unsampled UI details are not inferred beyond the README and source index.

Main entry points: [`src/App.svelte`](https://github.com/lemononmars/mathdle/blob/main/src/App.svelte) (Game UI and controller), [`src/lib/Mathdle.ts`](https://github.com/lemononmars/mathdle/blob/main/src/lib/Mathdle.ts) (Equation engine), [`src/main.ts`](https://github.com/lemononmars/mathdle/blob/main/src/main.ts) (Browser entry), [`src/lib/store.ts`](https://github.com/lemononmars/mathdle/blob/main/src/lib/store.ts) (Attempt persistence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gameplay["Game flow"]
  node_entry["Browser entry<br/>[main.ts]"]
  node_game["Game UI and controller<br/>[App.svelte]"]
end

subgraph group_logic["Equation logic"]
  node_mathdle["Equation engine<br/>[Mathdle.ts]"]
  node_random["Seeded randomizer<br/>[Random.ts]"]
  node_wordle["Feedback states<br/>[Wordle.ts]"]
end

subgraph group_state["Game state"]
  node_store["Attempt persistence<br/>[store.ts]"]
end

subgraph group_presentation["Presentation"]
  node_head["Page metadata<br/>[Head.svelte]"]
  node_menu["Link menu<br/>[Menu.svelte]"]
  node_social["Social sharing UI<br/>[Social.svelte]"]
  node_modal["Rules and examples<br/>[Modal.svelte]"]
  node_libloader["External script loader<br/>[LibLoader.svelte]"]
  node_kofi["Ko-fi integration<br/>[Kofi.svelte]"]
end

node_player(("Player"))
node_mathjs["mathjs evaluator"]
node_localstorage[("Browser local storage")]
node_clipboard["Clipboard"]

node_player -->|"opens game"| node_entry
node_entry -->|"mounts"| node_game
node_game -->|"gets solutions and feedback"| node_mathdle
node_mathdle -->|"uses seeded values"| node_random
node_mathdle -->|"evaluates expressions"| node_mathjs
node_game -->|"checks equation sides"| node_mathjs
node_game -->|"saves attempts"| node_store
node_store -->|"reads and writes"| node_localstorage
node_game -->|"copies results"| node_clipboard
node_game -->|"renders"| node_head
node_game -->|"renders"| node_menu
node_game -->|"renders"| node_social
node_game -->|"renders"| node_modal
node_modal -->|"uses feedback states"| node_wordle
node_kofi -->|"uses loader"| node_libloader

click node_entry "https://github.com/lemononmars/mathdle/blob/main/src/main.ts"
click node_game "https://github.com/lemononmars/mathdle/blob/main/src/App.svelte"
click node_mathdle "https://github.com/lemononmars/mathdle/blob/main/src/lib/Mathdle.ts"
click node_random "https://github.com/lemononmars/mathdle/blob/main/src/lib/Random.ts"
click node_wordle "https://github.com/lemononmars/mathdle/blob/main/src/lib/Wordle.ts"
click node_store "https://github.com/lemononmars/mathdle/blob/main/src/lib/store.ts"
click node_head "https://github.com/lemononmars/mathdle/blob/main/src/lib/Head.svelte"
click node_menu "https://github.com/lemononmars/mathdle/blob/main/src/lib/Menu.svelte"
click node_social "https://github.com/lemononmars/mathdle/blob/main/src/lib/Social.svelte"
click node_modal "https://github.com/lemononmars/mathdle/blob/main/src/lib/Modal.svelte"
click node_libloader "https://github.com/lemononmars/mathdle/blob/main/src/lib/LibLoader.svelte"
click node_kofi "https://github.com/lemononmars/mathdle/blob/main/src/lib/Kofi.svelte"

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_game toneBlue
class node_mathdle,node_random,node_wordle,node_localstorage toneAmber
class node_store toneMint
class node_head,node_menu,node_social,node_modal,node_libloader,node_kofi toneRose
class node_player,node_mathjs,node_clipboard toneIndigo
```

## Components

### Game flow

- [Browser entry](https://github.com/lemononmars/mathdle/blob/main/src/main.ts): `src/main.ts`
- [Game UI and controller](https://github.com/lemononmars/mathdle/blob/main/src/App.svelte): `src/App.svelte`

### Equation logic

- [Equation engine](https://github.com/lemononmars/mathdle/blob/main/src/lib/Mathdle.ts): `src/lib/Mathdle.ts`
- [Seeded randomizer](https://github.com/lemononmars/mathdle/blob/main/src/lib/Random.ts): `src/lib/Random.ts`
- [Feedback states](https://github.com/lemononmars/mathdle/blob/main/src/lib/Wordle.ts): `src/lib/Wordle.ts`

### Game state

- [Attempt persistence](https://github.com/lemononmars/mathdle/blob/main/src/lib/store.ts): `src/lib/store.ts`

### Presentation

- [Page metadata](https://github.com/lemononmars/mathdle/blob/main/src/lib/Head.svelte): `src/lib/Head.svelte`
- [Link menu](https://github.com/lemononmars/mathdle/blob/main/src/lib/Menu.svelte): `src/lib/Menu.svelte`
- [Social sharing UI](https://github.com/lemononmars/mathdle/blob/main/src/lib/Social.svelte): `src/lib/Social.svelte`
- [Rules and examples](https://github.com/lemononmars/mathdle/blob/main/src/lib/Modal.svelte): `src/lib/Modal.svelte`
- [External script loader](https://github.com/lemononmars/mathdle/blob/main/src/lib/LibLoader.svelte): `src/lib/LibLoader.svelte`
- [Ko-fi integration](https://github.com/lemononmars/mathdle/blob/main/src/lib/Kofi.svelte): `src/lib/Kofi.svelte`

### Other components

- **Player**
- **mathjs evaluator**
- **Browser local storage**
- **Clipboard**

## Connections

- Player → Browser entry: opens game (evidence: `src/main.ts`)
- Browser entry → Game UI and controller: mounts (evidence: `src/main.ts`)
- Game UI and controller → Equation engine: gets solutions and feedback (evidence: `src/App.svelte`)
- Equation engine → Seeded randomizer: uses seeded values (evidence: `src/lib/Mathdle.ts`)
- Equation engine → mathjs evaluator: evaluates expressions (evidence: `README.md`)
- Game UI and controller → mathjs evaluator: checks equation sides (evidence: `src/App.svelte`)
- Game UI and controller → Attempt persistence: saves attempts (evidence: `src/App.svelte`)
- Attempt persistence → Browser local storage: reads and writes (evidence: `src/lib/store.ts`)
- Game UI and controller → Clipboard: copies results (evidence: `src/App.svelte`)
- Game UI and controller → Page metadata: renders (evidence: `src/App.svelte`)
- Game UI and controller → Link menu: renders (evidence: `src/App.svelte`)
- Game UI and controller → Social sharing UI: renders (evidence: `src/App.svelte`)
- Game UI and controller → Rules and examples: renders (evidence: `src/App.svelte`)
- Rules and examples → Feedback states: uses feedback states (evidence: `src/lib/Modal.svelte`)
- Ko-fi integration → External script loader: uses loader (evidence: `src/lib/Kofi.svelte`)
