# lalopapa/mindmatch architecture

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

- Interactive diagram: https://gitdiagram.com/lalopapa/mindmatch
- Repository: https://github.com/lalopapa/mindmatch

## Overview

MindMatch is a word-pair memory game with local collections and a two-player online mode. The main workflow configures a game, applies shared game rules, and renders play; collections and preferences are stored locally, while online rooms are managed by a server and synchronized to clients over sockets. The README documents the product routes and local-first storage. Some server and UI relationships are based on the SOURCE INDEX rather than full excerpts; unverified client-to-server wiring is shown as optional.

Main entry points: [`server/core/app.ts`](https://github.com/lalopapa/mindmatch/blob/main/server/core/app.ts) (HTTP and socket app), [`server/core/rooms/RoomService.ts`](https://github.com/lalopapa/mindmatch/blob/main/server/core/rooms/RoomService.ts) (Room and game service), [`app/services/collectionService.ts`](https://github.com/lalopapa/mindmatch/blob/main/app/services/collectionService.ts) (Collection service), [`server/core/orchestrator/orchestrator.ts`](https://github.com/lalopapa/mindmatch/blob/main/server/core/orchestrator/orchestrator.ts) (Service orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Game experience"]
  node_setup["Game setup<br/>[page.tsx]"]
  node_play["Local game page<br/>[page.tsx]"]
  node_board["Board and status<br/>[Board.tsx]"]
  node_gamehook["Local game state<br/>[useGame.ts]"]
  node_collectionsui["Collections pages<br/>[page.tsx]"]
  node_collectionform["Collection form<br/>[CollectionForm.tsx]"]
end

subgraph group_local["Local data"]
  node_collectionservice["Collection service"]
  node_database[("IndexedDB<br/>[database.ts]")]
  node_settings["Settings service<br/>[settingsService.ts]"]
end

subgraph group_rules["Game rules"]
  node_engine["Game engine<br/>[engine.ts]"]
end

subgraph group_online["Online play"]
  node_join["Join room page<br/>[page.tsx]"]
  node_onlinepage["Online game page<br/>[page.tsx]"]
  node_onlinehook["Online game state<br/>[useOnlineGame.ts]"]
  node_socketclient["Socket client<br/>[socket.ts]"]
end

subgraph group_server["Room server"]
  node_serverapp["HTTP and socket app<br/>[app.ts]"]
  node_orchestrator["Service orchestrator<br/>[orchestrator.ts]"]
  node_roomservice["Room and game service<br/>[RoomService.ts]"]
  node_roomstore[("Room store<br/>[RoomStore.ts]")]
  node_broadcaster["Socket broadcaster<br/>[broadcaster.ts]"]
  node_sweeper["Room maintenance<br/>[roomSweepWorker.ts]"]
end

node_player(("Player"))

node_player -->|"configures"| node_setup
node_setup -->|"starts game"| node_play
node_play -->|"uses state"| node_gamehook
node_play -->|"renders"| node_board
node_gamehook -->|"applies rules"| node_engine
node_board -->|"uses game types"| node_engine
node_player -->|"manages words"| node_collectionsui
node_collectionsui -->|"reads collections"| node_collectionservice
node_collectionform -.->|"saves collection"| node_collectionservice
node_collectionservice -->|"reads and writes"| node_database
node_collectionservice -->|"parses words"| node_engine
node_settings -->|"reads and writes"| node_database
node_player -.->|"joins online"| node_join
node_join -.->|"opens room"| node_onlinepage
node_onlinepage -->|"uses online state"| node_onlinehook
node_onlinehook -->|"sends actions"| node_socketclient
node_socketclient -.->|"exchanges socket events"| node_serverapp
node_serverapp -->|"creates services"| node_orchestrator
node_serverapp -->|"creates broadcaster"| node_broadcaster
node_serverapp -->|"starts worker"| node_sweeper
node_orchestrator -->|"creates store"| node_roomstore
node_orchestrator -->|"creates service"| node_roomservice
node_roomservice -->|"manages rooms"| node_roomstore
node_roomservice -->|"broadcasts updates"| node_broadcaster
node_roomservice -->|"applies game rules"| node_engine
node_sweeper -->|"uses services"| node_orchestrator

click node_setup "https://github.com/lalopapa/mindmatch/blob/main/app/(main)/page.tsx"
click node_play "https://github.com/lalopapa/mindmatch/blob/main/app/(main)/play/page.tsx"
click node_board "https://github.com/lalopapa/mindmatch/blob/main/app/components/game/Board.tsx"
click node_gamehook "https://github.com/lalopapa/mindmatch/blob/main/app/game/useGame.ts"
click node_collectionsui "https://github.com/lalopapa/mindmatch/blob/main/app/(main)/collections/page.tsx"
click node_collectionform "https://github.com/lalopapa/mindmatch/blob/main/app/components/collection-form/CollectionForm.tsx"
click node_collectionservice "https://github.com/lalopapa/mindmatch/blob/main/app/services/collectionService.ts"
click node_database "https://github.com/lalopapa/mindmatch/blob/main/app/services/database.ts"
click node_settings "https://github.com/lalopapa/mindmatch/blob/main/app/services/settingsService.ts"
click node_engine "https://github.com/lalopapa/mindmatch/blob/main/packages/engine/src/engine.ts"
click node_join "https://github.com/lalopapa/mindmatch/blob/main/app/(main)/join/page.tsx"
click node_onlinepage "https://github.com/lalopapa/mindmatch/blob/main/app/(main)/online/%5Bcode%5D/page.tsx"
click node_onlinehook "https://github.com/lalopapa/mindmatch/blob/main/app/online/useOnlineGame.ts"
click node_socketclient "https://github.com/lalopapa/mindmatch/blob/main/app/online/socket.ts"
click node_serverapp "https://github.com/lalopapa/mindmatch/blob/main/server/core/app.ts"
click node_orchestrator "https://github.com/lalopapa/mindmatch/blob/main/server/core/orchestrator/orchestrator.ts"
click node_roomservice "https://github.com/lalopapa/mindmatch/blob/main/server/core/rooms/RoomService.ts"
click node_roomstore "https://github.com/lalopapa/mindmatch/blob/main/server/core/rooms/RoomStore.ts"
click node_broadcaster "https://github.com/lalopapa/mindmatch/blob/main/server/core/sockets/broadcaster.ts"
click node_sweeper "https://github.com/lalopapa/mindmatch/blob/main/server/core/workers/maintenance/roomSweepWorker.ts"

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_setup,node_play,node_board,node_gamehook,node_collectionsui,node_collectionform toneBlue
class node_collectionservice,node_database,node_settings toneAmber
class node_engine toneMint
class node_join,node_onlinepage,node_onlinehook,node_socketclient toneRose
class node_serverapp,node_orchestrator,node_roomservice,node_roomstore,node_broadcaster,node_sweeper,node_player toneIndigo
```

## Components

### Game experience

- [Game setup](https://github.com/lalopapa/mindmatch/blob/main/app/(main)/page.tsx): `app/(main)/page.tsx`
- [Local game page](https://github.com/lalopapa/mindmatch/blob/main/app/(main)/play/page.tsx): `app/(main)/play/page.tsx`
- [Board and status](https://github.com/lalopapa/mindmatch/blob/main/app/components/game/Board.tsx): `app/components/game/Board.tsx`
- [Local game state](https://github.com/lalopapa/mindmatch/blob/main/app/game/useGame.ts): `app/game/useGame.ts`
- [Collections pages](https://github.com/lalopapa/mindmatch/blob/main/app/(main)/collections/page.tsx): `app/(main)/collections/page.tsx`
- [Collection form](https://github.com/lalopapa/mindmatch/blob/main/app/components/collection-form/CollectionForm.tsx): `app/components/collection-form/CollectionForm.tsx`

### Local data

- [Collection service](https://github.com/lalopapa/mindmatch/blob/main/app/services/collectionService.ts): `app/services/collectionService.ts`
- [IndexedDB](https://github.com/lalopapa/mindmatch/blob/main/app/services/database.ts): `app/services/database.ts`
- [Settings service](https://github.com/lalopapa/mindmatch/blob/main/app/services/settingsService.ts): `app/services/settingsService.ts`

### Game rules

- [Game engine](https://github.com/lalopapa/mindmatch/blob/main/packages/engine/src/engine.ts): `packages/engine/src/engine.ts`

### Online play

- [Join room page](https://github.com/lalopapa/mindmatch/blob/main/app/(main)/join/page.tsx): `app/(main)/join/page.tsx`
- [Online game page](https://github.com/lalopapa/mindmatch/blob/main/app/(main)/online/%5Bcode%5D/page.tsx): `app/(main)/online/[code]/page.tsx`
- [Online game state](https://github.com/lalopapa/mindmatch/blob/main/app/online/useOnlineGame.ts): `app/online/useOnlineGame.ts`
- [Socket client](https://github.com/lalopapa/mindmatch/blob/main/app/online/socket.ts): `app/online/socket.ts`

### Room server

- [HTTP and socket app](https://github.com/lalopapa/mindmatch/blob/main/server/core/app.ts): `server/core/app.ts`
- [Service orchestrator](https://github.com/lalopapa/mindmatch/blob/main/server/core/orchestrator/orchestrator.ts): `server/core/orchestrator/orchestrator.ts`
- [Room and game service](https://github.com/lalopapa/mindmatch/blob/main/server/core/rooms/RoomService.ts): `server/core/rooms/RoomService.ts`
- [Room store](https://github.com/lalopapa/mindmatch/blob/main/server/core/rooms/RoomStore.ts): `server/core/rooms/RoomStore.ts`
- [Socket broadcaster](https://github.com/lalopapa/mindmatch/blob/main/server/core/sockets/broadcaster.ts): `server/core/sockets/broadcaster.ts`
- [Room maintenance](https://github.com/lalopapa/mindmatch/blob/main/server/core/workers/maintenance/roomSweepWorker.ts): `server/core/workers/maintenance/roomSweepWorker.ts`

### Other components

- **Player**

## Connections

- Player → Game setup: configures
- Game setup → Local game page: starts game
- Local game page → Local game state: uses state (evidence: `app/(main)/play/page.tsx`)
- Local game page → Board and status: renders (evidence: `app/(main)/play/page.tsx`)
- Local game state → Game engine: applies rules (evidence: `app/game/useGame.ts`)
- Board and status → Game engine: uses game types (evidence: `app/components/game/Board.tsx`)
- Player → Collections pages: manages words
- Collections pages → Collection service: reads collections (evidence: `app/(main)/collections/page.tsx`)
- Collection form → Collection service: saves collection
- Collection service → IndexedDB: reads and writes (evidence: `app/services/collectionService.ts`)
- Collection service → Game engine: parses words (evidence: `app/services/collectionService.ts`)
- Settings service → IndexedDB: reads and writes (evidence: `app/services/settingsService.ts`)
- Player → Join room page: joins online
- Join room page → Online game page: opens room
- Online game page → Online game state: uses online state (evidence: `app/(main)/online/[code]/page.tsx`)
- Online game state → Socket client: sends actions (evidence: `app/online/useOnlineGame.ts`)
- Socket client → HTTP and socket app: exchanges socket events
- HTTP and socket app → Service orchestrator: creates services (evidence: `server/core/app.ts`)
- HTTP and socket app → Socket broadcaster: creates broadcaster (evidence: `server/core/app.ts`)
- HTTP and socket app → Room maintenance: starts worker (evidence: `server/core/app.ts`)
- Service orchestrator → Room store: creates store (evidence: `server/core/orchestrator/orchestrator.ts`)
- Service orchestrator → Room and game service: creates service (evidence: `server/core/orchestrator/orchestrator.ts`)
- Room and game service → Room store: manages rooms (evidence: `server/core/rooms/RoomService.ts`)
- Room and game service → Socket broadcaster: broadcasts updates (evidence: `server/core/rooms/RoomService.ts`)
- Room and game service → Game engine: applies game rules (evidence: `server/core/rooms/RoomService.ts`)
- Room maintenance → Service orchestrator: uses services (evidence: `server/core/workers/maintenance/roomSweepWorker.ts`)
