How firstisrael/lems works
Purpose and Deployable Entry Points
LEMS manages local FIRST LEGO League Challenge events: setup, scheduling, volunteer operations, live field/judging execution, awards, public results, and exports. It is an Nx monorepo with four web/service deployables:
• Node backend: apps/backend/src/main.ts
• Admin Next.js app: apps/admin/src/app/[locale]/page.tsx
• Volunteer/live-operations Next.js app: apps/frontend/src/app/[locale]/lems/page.tsx
• Public portal Next.js app: apps/portal/src/app/[locale]/page.tsx
• Python scheduling service: apps/scheduler/src/main.py
Persistent Domain Model
PostgreSQL holds the relational event model—seasons, events, divisions, teams, schedules, awards, users, rooms, and tables—through the shared database library and migrations. MongoDB holds mutable operational documents such as match/session state, rubrics, scoresheets, and deliberations.
• libs/database/src/schema/kysely.ts
• libs/database/src/schema/documents/robot-game-match-state.ts
• libs/database/src/migrations/010_create_robot_game_tables_matches_and_participants.ts
Backend API and Authorization Boundary
The Express backend is the integration boundary for all clients. It exposes REST routers segregated by consumer (admin, portal, lems, scheduler) and a GraphQL API for live volunteer workflows. Auth, CSRF, CAPTCHA, authorization context, and per-event/division attachment middleware enforce access at the server boundary.
• apps/backend/src/main.ts
• apps/backend/src/lib/graphql/apollo-server.ts
• apps/backend/src/routers/admin/middleware/require-permission.ts
Event Configuration and Administration
The admin application configures event lifecycle and resources: seasons/events/divisions, team registration and import, volunteer assignment, venue assets, integrations, awards, and interactive schedule editing. Event-scoped route layouts and contexts organize work around an event slug and division.
• apps/admin/src/app/[locale]/(dashboard)/events/[slug]/layout.tsx
• apps/admin/src/app/[locale]/(dashboard)/events/[slug]/schedule/components/schedule-manager.tsx
• apps/backend/src/routers/admin/events/divisions/schedule/index.ts
Scheduling Pipeline
The Python scheduler accepts schedule-oriented requests via its own router/service layer; the backend presents a scheduler-facing API with division attachment/authentication. Generated or adjusted schedules are then consumed by admin editing and live field/judging views.
• apps/scheduler/src/routers/scheduler.py
• apps/scheduler/src/services/scheduler_service.py
• apps/backend/src/routers/scheduler/divisions/index.ts
Live Tournament Operations
The volunteer app is role-oriented: scorekeeper/referee operate matches and scoresheets; judges run sessions and rubrics; queuers track team movement; leads and advisors manage status and deliberation. Match/session state transitions invoke GraphQL mutations, then drive workflow-specific screens.
• apps/frontend/src/app/[locale]/lems/(volunteer)/(dashboard)/scorekeeper/page.tsx
• apps/frontend/src/app/[locale]/lems/(volunteer)/(dashboard)/judge/page.tsx
• apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts
Real-Time State Propagation
GraphQL subscriptions deliver match, judging, rubric, scoresheet, team-arrival, deliberation, and audience-display updates. Backend Redis pub/sub, subscription management, and scheduled-event workers distribute state changes and execute timing-driven completion/endgame handlers.
• apps/backend/src/lib/redis/redis-pubsub.ts
• apps/backend/src/lib/queues/worker-manager.ts
• apps/backend/src/lib/graphql/resolvers/subscriptions/matches/index.ts
Public Results, Displays, and External Services
The portal provides event schedules, teams, scoreboard, awards, and results; the live app also has audience-display and report routes driven by the same real-time APIs. Infrastructure includes PostgreSQL, MongoDB, Redis, Nginx, Docker, DigitalOcean object storage for documents/pit maps, and integrations for SendGrid and FIRST Israel dashboard exports.
• apps/portal/src/app/[locale]/event/[slug]/page.tsx
• apps/frontend/src/app/[locale]/lems/(volunteer)/audience-display/page.tsx
• apps/backend/src/lib/blob-storage/s3-client.ts
Main entry points: main.ts Express backend · apollo-server.ts Live GraphQL API · matches/index.ts Match state mutations · divisions/index.ts Scheduler REST router
Components 21
Web clients
Role-specific Next.js applications.
- Admin app · Configures events, resources, awards, and schedules.
apps/admin/src/app/[locale]/(dashboard)/page.tsx - Event-scoped admin · Scopes administration by event slug and division.
apps/admin/src/app/[locale]/(dashboard)/events/[slug]/layout.tsx - Schedule editor · Interactive schedule editing workflow.
apps/admin/src/app/[locale]/(dashboard)/events/[slug]/schedule/components/schedule-manager.tsx - Volunteer live app · Role-oriented field, judging, queueing, and lead workflows.
apps/frontend/src/app/[locale]/lems/page.tsx - Match and judging workflows · Scorekeepers and judges operate matches, sessions, and rubrics.
apps/frontend/src/app/[locale]/lems/(volunteer)/(dashboard)/scorekeeper/page.tsx - Audience display · Public-facing live display driven by real-time APIs.
apps/frontend/src/app/[locale]/lems/(volunteer)/audience-display/page.tsx - Public portal · Publishes schedules, teams, scoreboard, awards, and results.
apps/portal/src/app/[locale]/page.tsx - Public event pages · Event-specific public results and schedule pages.
apps/portal/src/app/[locale]/event/[slug]/page.tsx
Backend platform
Express API, live GraphQL, and event processing.
- Express backend · Consumer-segregated REST integration boundary.
apps/backend/src/main.ts - Authorization boundary · Applies auth, CSRF, CAPTCHA, permissions, and event/division context.
apps/backend/src/routers/admin/middleware/require-permission.ts - Live GraphQL API · Mutations and subscriptions for volunteer workflows.
apps/backend/src/lib/graphql/apollo-server.ts - Match state mutations · Transitions live match state from volunteer actions.
apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts - Live subscriptions · Streams match and related operational updates.
apps/backend/src/lib/graphql/resolvers/subscriptions/matches/index.ts - Scheduled-event workers · Runs timing-driven completion and endgame handlers.
apps/backend/src/lib/queues/worker-manager.ts - Scheduler REST router · Authenticated division-scoped scheduling interface.
apps/backend/src/routers/scheduler/divisions/index.ts
Scheduling
Schedule generation service and integration.
- Python scheduler · Generates and adjusts event schedules.
apps/scheduler/src/main.py - Schedule generation · Scheduler request handling and generation logic.
apps/scheduler/src/services/scheduler_service.py
Data services
Persistent and real-time infrastructure.
- PostgreSQL event model · Stores seasons, events, divisions, teams, schedules, awards, and resources.
libs/database/src/schema/kysely.ts - MongoDB operations state · Stores mutable matches, rubrics, scoresheets, and deliberations.
libs/database/src/schema/documents/robot-game-match-state.ts - Redis pub/sub · Distributes operational state updates to subscriptions.
apps/backend/src/lib/redis/redis-pubsub.ts
External services
Document storage and outbound integrations.
- Object storage · Stores documents and pit maps in DigitalOcean object storage.
apps/backend/src/lib/blob-storage/s3-client.ts
Connections 23
- Admin app → Event-scoped admin: scopes work
- Event-scoped admin → Schedule editor: hosts
- Admin app → Express backend: admin REST
- Schedule editor → Scheduler REST router: requests schedules
- Volunteer live app → Match and judging workflows: hosts
- Match and judging workflows → Live GraphQL API: mutations and live state
- Audience display → Live GraphQL API: subscribes
- Public portal → Public event pages: hosts
- Public event pages → Express backend: public REST
- Express backend → Authorization boundary: enforces
- Authorization boundary → PostgreSQL event model: event-scoped data
- Express backend → Scheduler REST router: routes requests
- Scheduler REST router → Python scheduler: invokes
- Python scheduler → Schedule generation: uses
- Schedule generation → PostgreSQL event model: reads and writes schedules
- Live GraphQL API → Match state mutations: executes
- Match state mutations → MongoDB operations state: updates live state
- Match state mutations → Redis pub/sub: publishes changes
- Live GraphQL API → Live subscriptions: serves
- Live subscriptions → Redis pub/sub: consumes updates
- Scheduled-event workers → MongoDB operations state: processes timed state
- Scheduled-event workers → Redis pub/sub: broadcasts transitions
- Express backend → Object storage: stores documents