Skip to content
kiprPublic

About

A scoring application for KIPR

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

346 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Colosseum - Tournament Scoring Platform

A web-based tournament management and scoring platform with event-centric workflows, supporting seeding rounds, double-elimination brackets, game queues, and customizable score sheet templates.

Features

  • Event Management - Create and manage tournament events with statuses (setup, active, complete, archived)
  • Team Management - Register teams, bulk import, check-in workflows, and status tracking
  • Seeding Rounds - Multi-round seeding with automatic ranking calculation (top 2 of 3 scores)
  • Double Elimination Brackets - Generate brackets (4-64 teams), automatic seeding from rankings, bye handling, and winner advancement
  • Game Queue - Ordered queue system for seeding rounds and bracket games with table assignments
  • Customizable Score Sheets - Template-driven scoring with text, number, dropdown, button, checkbox, and repeatable group field types
  • Score Review System - Admins can accept, reject, or edit submitted scores with full audit trail
  • Access Codes - Judges access scoresheets via secure access codes (no login required)
  • Google OAuth Authentication - Secure admin login with Google accounts
  • Modern UI - Responsive React interface with dark mode support
  • Public Views - Public event listings and bracket/seeding displays

Supported Field Types

Score sheet templates support the following field types:

  • Text - Free-form text input
  • Number - Numeric input with min/max/step validation
  • Dropdown - Select from predefined options
  • Buttons - Multiple choice with visual button selection
  • Checkbox - Boolean (true/false) values
  • Repeatable Group - Repeatable rows of sub-fields (for example, per-stack cube entry)

See Template Schema Guide for detailed schema documentation.

Note: Templates that include repeatableGroup fields are not portable yet. They cannot be exported with the portable scoresheet tool until portable exporter support for this field type is added.

Prerequisites

  • Node.js 24 LTS and npm 11
  • Google Cloud Platform account with OAuth 2.0 credentials (for admin authentication)
  • Docker Engine + Compose (required; local PostgreSQL 18)

Setup Instructions

1. Clone and Install

cd colosseum
npm install

2. Configure Google OAuth

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Create OAuth 2.0 credentials:
    • Go to "Credentials" -> "Create Credentials" -> "OAuth 2.0 Client ID"
    • Application type: Web application
    • Authorized redirect URIs: http://localhost:3000/auth/google/callback
  4. Copy the Client ID and Client Secret

OAuth scopes and domain restriction

Colosseum uses Google only to sign admins in. It requests the basic profile and email scopes and nothing else: no offline access (refresh tokens) and no Google API scopes such as Drive or Sheets. Google tokens are not stored after sign-in. The OAuth consent screen only needs those two scopes, so remove any others listed there. Scopes granted to earlier versions stay on each user's Google account until revoked, either by the user at https://myaccount.google.com/connections or by a Workspace admin under Security → API controls.

The production OAuth client is configured as an Internal app, so Google only lets kipr.org Workspace accounts sign in. The app also checks the signed-in email against ALLOWED_EMAIL_DOMAINS (default kipr.org), and every account that passes that check is created as an admin. If the OAuth client is ever switched to External:

  • ALLOWED_EMAIL_DOMAINS becomes the only gate on admin access, so it must stay set to the organization's domains in production. Setting it to an empty string would make any Google account an admin.
  • The domain check reads the account's email address. With an External client, consider also checking the verified Workspace domain (the hd claim) rather than the email domain alone.
  • Because only basic sign-in scopes are requested, an External client does not need Google's sensitive-scope verification.

3. Environment Configuration

cp .env.example .env

Edit .env and add your Google OAuth credentials:

GOOGLE_CLIENT_ID=your-client-id-here
GOOGLE_CLIENT_SECRET=your-client-secret-here
SESSION_SECRET=your-random-session-secret
DATABASE_URL=postgres://colosseum:colosseum@localhost:5432/colosseum
TEST_DATABASE_URL=postgres://colosseum:colosseum@localhost:5432/colosseum_test

.env.example already includes those database URLs. Inside a devcontainer the hostname is postgres rather than localhost.

4. Start PostgreSQL

Do not auto-start Compose from npm run dev. Start it first:

npm run db:up && npm run db:wait

Port 5432 already in use. Create docker-compose.override.yml (gitignored if you prefer; do not commit local port choices):

services:
  postgres:
    ports:
      - '5433:5432'

Point DATABASE_URL and TEST_DATABASE_URL at localhost:5433.

Wipe local Postgres data:

npm run db:reset

Helper scripts: db:up, db:wait, db:down, db:reset, db:psql.

Devcontainer / Codespaces. Reopening the folder in a container starts Compose siblings (app + postgres) with DATABASE_URL already pointing at hostname postgres. Wait for postStartCommand (pg_isready) before npm run dev.

5. Run the Application

Dev servers (React + Express):

npm run dev

This starts two servers:

  • Vite dev server (React frontend): http://localhost:5173 - Open this URL in your browser
  • Express API server (Backend): http://localhost:3000

The Vite server proxies API calls to Express automatically.

Expect these logs:

Using PostgreSQL session store
Using PostgreSQL database
Database initialized successfully

Confirm the API is up:

curl http://localhost:3000/health

Should return { "status": "ok", ... }.

Inspect databases and schema:

npm run db:psql

Then in psql:

\l
\c colosseum
\dt

\l should list both colosseum and colosseum_test. \dt should show application tables plus "session" after the first server start (the session table is created by connect-pg-simple).

Production mode:

npm run build
npm start

In production, Express serves the built React app at http://localhost:3000.

Important: When running the Vite + Express pair, always use http://localhost:5173 (Vite) for the frontend, NOT port 3000.

Usage Guide

Tournament Workflow

A typical tournament follows this workflow:

  1. Create Event - Admin creates a new event with name, date, location, and number of seeding rounds
  2. Register Teams - Add teams individually or via bulk import
  3. Check In Teams - Mark teams as checked in on competition day
  4. Run Seeding Rounds - Queue seeding rounds, judges score via access codes, admin reviews scores
  5. Calculate Rankings - System computes rankings from top 2 of 3 seeding scores
  6. Generate Brackets - Create double-elimination brackets seeded from rankings
  7. Run Bracket Games - Queue bracket games, judges score, admin reviews, winners advance automatically
  8. Complete Event - Archive the event when the tournament concludes

For Judges

  1. Navigate to the home page
  2. Click "Enter as Judge"
  3. Select a score sheet template
  4. Enter the access code provided by the admin
  5. Fill out the scoresheet and submit

For Administrators

  1. Login with Google OAuth
  2. Create an Event in the Events tab
  3. Add Teams in the Teams tab (single or bulk import)
  4. Configure Score Sheets in the Score Sheets tab
  5. Manage Seeding - View scores, calculate rankings in the Seeding tab
  6. Create Brackets - Generate brackets from seeding in the Brackets tab
  7. Manage Queue - Populate and order the game queue in the Queue tab
  8. Review Scores - Accept, reject, or edit scores in the Scoring tab

Project Structure

colosseum/
├── src/
│   ├── client/                    # React frontend
│   │   ├── components/            # Reusable React components
│   │   │   ├── admin/             # Admin panel tabs and modals
│   │   │   ├── bracket/           # Bracket visualization components
│   │   │   └── seeding/           # Seeding table components
│   │   ├── contexts/              # React contexts (Auth, Theme, Event, Chat)
│   │   ├── pages/                 # Page components (Home, Judge, Admin, etc.)
│   │   ├── styles/                # Global styles
│   │   ├── types/                 # TypeScript type definitions
│   │   ├── utils/                 # Utility functions
│   │   ├── App.tsx                # Main React app with routing
│   │   └── main.tsx               # React entry point
│   └── server/                    # Express backend
│       ├── config/                # OAuth and API configuration
│       ├── database/              # Database connection and schema initialization
│       ├── middleware/            # Authentication middleware
│       ├── routes/                # API route handlers
│       │   ├── auth.ts            # Authentication routes
│       │   ├── events.ts          # Event CRUD
│       │   ├── teams.ts           # Team management
│       │   ├── seeding.ts         # Seeding scores and rankings
│       │   ├── brackets.ts        # Bracket management
│       │   ├── queue.ts           # Game queue
│       │   ├── scores.ts          # Score review/approval
│       │   ├── scoresheet.ts      # Template management
│       │   ├── audit.ts           # Audit log
│       │   └── api.ts             # Score submission (judge-facing)
│       ├── services/              # Business logic
│       │   ├── seedingRankings.ts  # Seeding calculation
│       │   ├── bracketTemplates.ts # Bracket structure generation
│       │   ├── bracketByeResolver.ts # Bye handling
│       │   └── scoreAccept.ts      # Score acceptance logic
│       ├── session/               # Session store
│       └── server.ts              # Express server setup
├── docs/                          # Documentation
│   ├── TEMPLATE_SCHEMA_GUIDE.md   # Score sheet template schema reference
│   └── API_TESTING.md             # API testing guide with curl examples
├── templates/                     # Example score sheet templates
├── tests/                         # Unit & integration tests (Vitest)
├── e2e/                           # End-to-end tests (Playwright)
├── config/                        # Shared test-runner configuration
├── docker/                        # Local Postgres init scripts
├── docker-compose.yml             # Local PostgreSQL 18 (required for app and tests)
├── dist/                          # Build output
├── playwright.config.ts           # Playwright E2E config
├── vite.config.ts                 # Vite configuration
├── tsconfig.json                  # TypeScript config
├── package.json
├── Dockerfile                     # Production Docker image
└── .env                           # Environment variables (not committed)

Database Schema

The application uses PostgreSQL with the following tables:

Core Tables

  • users - Admin accounts (Google account id, email, name)
  • events - Tournament events with status tracking
  • teams - Participating teams per event with check-in status
  • scoresheet_templates - Score sheet template definitions

Seeding

  • seeding_scores - Individual round scores per team
  • seeding_rankings - Computed rankings (seed average, rank, normalized score)

Brackets

  • brackets - Double-elimination bracket containers
  • bracket_entries - Teams assigned to brackets with seed positions
  • bracket_games - Individual games with advancement routing
  • bracket_templates - Pre-defined bracket structures for standard sizes

Scoring

  • score_submissions - Submitted scores with review status
  • score_details - Field-by-field score breakdown
  • event_scoresheet_templates - Links templates to events for seeding/bracket scoring

Operations

  • game_queue - Ordered queue of games ready for judging
  • audit_log - Change tracking for accountability

API Endpoints

Authentication

  • GET /auth/google - Initiate Google OAuth
  • GET /auth/google/callback - OAuth callback
  • GET /auth/user - Get current user
  • GET /auth/logout - Logout

Events

  • GET /events - List all events
  • GET /events/:id - Get event details
  • POST /events - Create event
  • PATCH /events/:id - Update event
  • DELETE /events/:id - Delete event

Teams

  • GET /teams/event/:eventId - List teams for event
  • GET /teams/:id - Get team details
  • POST /teams - Create team
  • POST /teams/bulk - Bulk create teams
  • PATCH /teams/:id - Update team
  • PATCH /teams/:id/check-in - Check in team
  • DELETE /teams/:id - Delete team

Seeding

  • GET /seeding/scores/event/:eventId - Get all scores for event
  • GET /seeding/scores/team/:teamId - Get scores for team
  • POST /seeding/scores - Submit seeding score
  • PATCH /seeding/scores/:id - Update score
  • DELETE /seeding/scores/:id - Delete score
  • GET /seeding/rankings/event/:eventId - Get rankings
  • POST /seeding/rankings/recalculate/:eventId - Recalculate rankings

Brackets

  • GET /brackets/event/:eventId - List brackets for event
  • GET /brackets/:id - Get bracket with entries and games
  • POST /brackets - Create bracket
  • PATCH /brackets/:id - Update bracket
  • DELETE /brackets/:id - Delete bracket
  • POST /brackets/:id/entries - Add entry
  • POST /brackets/:id/entries/generate - Generate entries from seeding
  • GET /brackets/:id/games - Get games
  • POST /brackets/:id/games - Create game
  • PATCH /brackets/games/:id - Update game
  • POST /brackets/games/:id/advance - Advance winner

Queue

  • GET /queue/event/:eventId - Get queue for event
  • POST /queue - Add item to queue
  • PATCH /queue/:id - Update queue item
  • PATCH /queue/:id/call - Call team/game
  • DELETE /queue/:id - Remove from queue

Scoring

  • POST /api/scores/submit - Submit a score (judge-facing)
  • GET /scores/by-event/:eventId - Get scores for event (admin)
  • POST /scores/:id/accept-event - Accept score (event-scoped)
  • POST /scores/:id/revert-event - Revert acceptance

Templates

  • GET /scoresheet/templates - List all templates
  • GET /scoresheet/templates/:id - Get template details
  • POST /scoresheet/templates - Create template
  • PUT /scoresheet/templates/:id - Update template

Audit

  • GET /audit/event/:eventId - Get audit log for event
  • GET /audit/entity/:type/:id - Get audit log for entity

Working on the app

Tech Stack

  • Frontend: React 19, TypeScript, React Router, Vite
  • Backend: Node.js, Express 5, TypeScript
  • Database: PostgreSQL 18 (Docker Compose locally; Cloud SQL in production)
  • Authentication: Passport.js with Google OAuth 2.0
  • Testing: Vitest (unit/integration), Playwright (E2E)
  • Build Tools: Vite (frontend), TypeScript Compiler (backend)

Building

npm run build

Builds both React frontend and Express backend:

  • React app -> dist/client/
  • Express server -> dist/server/

Dev Servers

npm run dev

Runs both servers concurrently:

Changes to React components update instantly (Hot Module Replacement). Changes to Express server restart automatically (nodemon).

Individual servers:

npm run dev:client  # Vite only
npm run dev:server  # Express only

Testing

Unit & integration tests (Vitest):

These run against PostgreSQL 18, the same major version as production, so the tests exercise the dialect the application actually ships on. Start the server first — npm run db:up also creates the colosseum_test database:

npm run db:up && npm run db:wait
npm test           # Run tests in watch mode
npm run test:run   # Run tests once
npm run coverage   # Run with coverage report

The connection string comes from TEST_DATABASE_URL (in your environment or .env), and defaults to postgres://colosseum:colosseum@localhost:5432/colosseum_test. Inside a devcontainer the host is postgres rather than localhost.

Each Vitest worker process creates its own schema in that database and truncates it between tests, so runs never touch your colosseum dev data.

End-to-end tests (Playwright):

Playwright tests live in the e2e/ directory and run against the full application. npm run db:up must have been run first.

The Playwright config (playwright.config.ts) starts its own Express on port 3001 and Vite on port 5174, with DATABASE_URL set to TEST_DATABASE_URL. It never reuses a server already listening on 3000/5173, so you can leave npm run dev running while the suite executes and it will not touch your dev data. The suite uses the public schema of colosseum_test and truncates it once at the start of each run, which does not disturb the Vitest suite's per-worker schemas on the same database.

Before your first run, you will need to download Playwright's headless browser builds and their required OS libraries. This is not handled by npm install.

Note

If you are using the Devcontainer setup, you do not need to run these commands manually. Simply go straight to npm run test:e2e below.

# First-time setup — download Chromium and install required OS libraries.
# If in an environment without sudo (e.g. container), install in two steps.
# First, run as root to install OS-level libraries and dependencies:
npx playwright install-deps

# Then, as your user, run:
npx playwright install

# If in an environment with sudo access, you can do this in one step with:
npx playwright install --with-deps

Once the dependencies are installed, run Playwright tests with:

# Run E2E tests
npm run test:e2e

Linting and Formatting

npm run lint       # ESLint
npm run pretty     # Prettier check

Rate Limiting

Public and abuse-prone API endpoints are protected by express-rate-limit with per-route policies defined in src/server/middleware/rateLimit.ts.

Current Limits

Limiter Endpoints Window Limit Key
oauthLimiter GET /auth/google 15 min 20 IP
scoreSubmitLimiter POST /api/scores/submit 1 min 30 IP
accessCodeLimiter POST /scoresheet/templates/:id/verify 15 min 10 IP + template id
chatWriteLimiter POST /chat/events/:eventId/messages 1 min 15 IP
chatReadLimiter GET /chat/events/:eventId/messages 1 min 120 IP
queueSyncLimiter GET /queue/event/:eventId (sync=1 only) 1 min 60 IP
publicExpensiveReadLimiter GET /events/:id/overall/public, GET /documentation-scores/event/:eventId/public 1 min 30 IP

Storage Constraints

  • Rate-limit counters use the built-in in-process memory store. This is a deliberate first-pass choice.
  • Counters reset on process restart and are not shared across workers or instances.
  • This is acceptable for a single-instance deployment or an initial rollout.

When to Upgrade the Store

Move to a shared store (e.g. Redis via rate-limit-redis) when any of the following apply:

  • The app runs on more than one instance (clustering, PM2 workers, Kubernetes replicas)
  • Consistent global rate limits are required across restarts
  • Stricter abuse controls are needed that survive deploys

Troubleshooting

"Authentication required" errors

  • Ensure you're logged in with Google
  • Check that OAuth credentials are correctly configured
  • Verify redirect URI matches in Google Cloud Console

Teams not appearing

  • Verify the event is selected in the admin panel
  • Check that teams have been added to the correct event
  • Ensure team status is not "withdrawn" or "no_show"

Bracket generation issues

  • Ensure seeding rankings have been calculated first
  • Verify the bracket size accommodates the number of teams
  • Check that teams are checked in before generating entries

Scores not updating rankings

  • Rankings must be recalculated manually after score changes
  • Use the "Recalculate Rankings" button in the Seeding tab

License

GNU AGPL v3

About

A scoring application for KIPR

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages