-
Notifications
You must be signed in to change notification settings - Fork 1
feat: new algorithms + organisation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamEvanYT
wants to merge
4
commits into
main
Choose a base branch
from
evan/new-algorithms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "printWidth": 120, | ||
| "singleQuote": false, | ||
| "trailingComma": "none" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,46 @@ | ||
| # Repository Guidelines | ||
|
|
||
| ## Project Structure & Module Organization | ||
|
|
||
| - `src/`: TypeScript source. Key areas: `routes/` (HTTP endpoints; auto-mounted), `modules/` (config, DB, matchmaking), `middlewares/` (logging, parsing, errors), `schemas/` (zod), `types/` (shared types). Entry: `src/index.ts`. | ||
| - `tests/`: Manual scripts for local testing (`tests/manual/*.ts`). | ||
| - `Dockerfile`: Container entrypoint using Bun. | ||
|
|
||
| ## Build, Test, and Development Commands | ||
|
|
||
| - `bun run dev`: Start in watch mode (`bun --watch src/index.ts`). | ||
| - `bun run start`: Run the server once (uses Bun). | ||
| - `bun run build`: Type-check via `tsc` (no emit). | ||
| - Example health check: `curl http://localhost:3000/v1/healthcheck`. | ||
| - Manual test scripts: `bun tests/manual/join-queue.ts`, `bun tests/manual/leave-queue.ts`. | ||
|
|
||
| ## Coding Style & Naming Conventions | ||
|
|
||
| - Language: TypeScript (ES modules, target `es2020`). | ||
| - Indentation: 2 spaces; keep formatting consistent with existing files. | ||
| - Filenames: routes and middlewares use kebab-case (e.g., `join-queue.ts`); types/interfaces PascalCase within code; variables camelCase. | ||
| - Validation: zod schemas in `src/schemas`; reuse shared types from `src/types`. | ||
|
|
||
| ## Testing Guidelines | ||
|
|
||
| - Framework: none configured; use manual scripts under `tests/manual/` to exercise endpoints. | ||
| - Add new manual tests near related features, named after the route (e.g., `tests/manual/<route>.ts`). | ||
| - Targeted checks: verify `/v1/healthcheck`, queue join/leave flows, and expected JSON shapes. | ||
|
|
||
| ## Commit & Pull Request Guidelines | ||
|
|
||
| - Commit style: prefer Conventional Commits (`feat:`, `fix:`, `chore:`) as used in history. | ||
| - PRs: include clear description, linked issues, and sample requests/responses (curl or script output). Note any config or migration steps. | ||
| - Keep changes small and focused; update README/this guide when structure or commands change. | ||
|
|
||
| ## Security & Configuration Tips | ||
|
|
||
| - Copy `.env.example` to `.env`. Key vars: `AuthKey` (API auth), `MongoUrl` (default `mongodb://localhost:27017`), `Port` (default `3000`), `Environment`, `Instances`, `MATCHMAKING_ENABLED`. | ||
| - Start MongoDB locally and ensure indexes are created at startup. | ||
| - Use the `AuthKey` in requests where required. | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| - Server: Hono app with route auto-loading from `src/routes/**`. | ||
| - Data: MongoDB; collections configured in `modules/config.ts`. | ||
| - Matchmaking: logic under `modules/matchmaking/**`; enable via `MATCHMAKING_ENABLED=true`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Matchmaking Architecture | ||
|
|
||
| This project uses a modular architecture to organize matchmaking logic and make it easy to extend, test, and maintain. | ||
|
|
||
| ## Algorithms | ||
|
|
||
| Supported queue algorithms: | ||
|
|
||
| - normal: Fixed team size, no ranking. Packs parties greedily to fill teams. | ||
| - dynamic: Team size adapts between min/max based on oldest party wait time. | ||
| - ranked: Uses party `rankedValue` with a search range that expands over time. | ||
|
|
||
| Algorithms live in `src/modules/matchmaking/algorithms/*` and implement a common interface. | ||
|
|
||
| ## Interface and Registry | ||
|
|
||
| - Algorithm interface: `Algorithm<T extends QueueConfig> = (cfg: T, services: Services) => Promise<void>` | ||
| - Services provide DB access and utilities, keeping algorithm code pure and testable: | ||
| - `getOldestParties(queueId, limit)` | ||
| - `updatePartyRange(partyId, rankedMin, rankedMax)` | ||
| - `createMatch(queueConfig, teams, partiesUsed)` | ||
| - `now()` and `log()` | ||
| - A registry maps `queueType` to the corresponding algorithm. | ||
|
|
||
| ## Sharding (Regions) | ||
|
|
||
| Requests can include `shardId` to restrict matching to a region. The server processes queues per-shard. Each queue has `shardTimeoutSeconds` to control expansion: | ||
|
|
||
| - `-1`: disables sharding (global matching only) | ||
| - `>= 0`: match within shard until the oldest party waits this many seconds; then an expanded global pass can combine parties from all shards | ||
|
|
||
| Indexes support both per-shard and global scans for efficient matching. | ||
|
|
||
| ## Configuration Summary | ||
|
|
||
| See docs/configuration.md for complete details. Key fields: | ||
|
|
||
| - All queues: `queueId`, `queueType`, `usersPerTeam`, `teamsPerMatch`, `discoverMatchesInterval`, `shardTimeoutSeconds` | ||
| - Ranked: `searchRange`, `incrementRange`, `incrementRangeMax?` | ||
| - Dynamic: `minUsersPerTeam`, `maxUsersPerTeam`, `timeElaspedToUseMinimumUsers` | ||
|
|
||
| ## API Summary | ||
|
|
||
| See docs/api.md for request/response formats. To target a region, set `shardId` in `POST /v1/join-queue`. | ||
|
iamEvanYT marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { Context } from "hono"; | ||
|
|
||
| export const errorHandler = (err: Error, c: Context) => { | ||
| console.error(err) | ||
| return c.json({ error: 'Internal Server Error' }, 500) | ||
| } | ||
| console.error(err); | ||
| return c.json({ error: "Internal Server Error" }, 500); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.