# firstisrael/lems architecture

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

- Interactive diagram: https://gitdiagram.com/firstisrael/lems
- Repository: https://github.com/firstisrael/lems

## Overview

#### 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: [`apps/backend/src/main.ts`](https://github.com/firstisrael/lems/blob/main/apps/backend/src/main.ts) (Express backend), [`apps/backend/src/lib/graphql/apollo-server.ts`](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/apollo-server.ts) (Live GraphQL API), [`apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts`](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts) (Match state mutations), [`apps/backend/src/routers/scheduler/divisions/index.ts`](https://github.com/firstisrael/lems/blob/main/apps/backend/src/routers/scheduler/divisions/index.ts) (Scheduler REST router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Web clients"]
  node_admin["Admin app<br/>Next.js<br/>[page.tsx]"]
  node_admin_event_context["Event-scoped admin<br/>route layout<br/>[layout.tsx]"]
  node_schedule_editor["Schedule editor<br/>admin feature"]
  node_volunteer["Volunteer live app<br/>Next.js<br/>[page.tsx]"]
  node_live_workflows["Match and judging workflows<br/>volunteer screens<br/>[page.tsx]"]
  node_audience_display["Audience display<br/>live display<br/>[page.tsx]"]
  node_portal["Public portal<br/>Next.js<br/>[page.tsx]"]
  node_public_event["Public event pages<br/>portal route<br/>[page.tsx]"]
end

subgraph group_backend["Backend platform"]
  node_backend_api{{"Express backend<br/>Node API<br/>[main.ts]"}}
  node_authorization["Authorization boundary<br/>middleware"]
  node_graphql{{"Live GraphQL API<br/>Apollo GraphQL<br/>[apollo-server.ts]"}}
  node_match_mutations["Match state mutations<br/>GraphQL resolver<br/>[index.ts]"]
  node_subscriptions["Live subscriptions<br/>GraphQL resolver<br/>[index.ts]"]
  node_event_workers["Scheduled-event workers<br/>worker manager<br/>[worker-manager.ts]"]
  node_scheduler_api["Scheduler REST router<br/>backend router<br/>[index.ts]"]
end

subgraph group_scheduling["Scheduling"]
  node_scheduler{{"Python scheduler<br/>Python service<br/>[main.py]"}}
  node_scheduler_service["Schedule generation<br/>service layer"]
end

subgraph group_data["Data services"]
  node_postgres[("PostgreSQL event model<br/>relational database<br/>[kysely.ts]")]
  node_mongodb[("MongoDB operations state<br/>document database")]
  node_redis["Redis pub/sub<br/>real-time bus<br/>[redis-pubsub.ts]"]
end

subgraph group_external["External services"]
  node_object_storage[("Object storage<br/>S3 client<br/>[s3-client.ts]")]
end

node_admin -->|"scopes work"| node_admin_event_context
node_admin_event_context -->|"hosts"| node_schedule_editor
node_admin -->|"admin REST"| node_backend_api
node_schedule_editor -->|"requests schedules"| node_scheduler_api
node_volunteer -->|"hosts"| node_live_workflows
node_live_workflows -->|"mutations and live state"| node_graphql
node_audience_display -->|"subscribes"| node_graphql
node_portal -->|"hosts"| node_public_event
node_public_event -->|"public REST"| node_backend_api
node_backend_api -->|"enforces"| node_authorization
node_authorization -->|"event-scoped data"| node_postgres
node_backend_api -->|"routes requests"| node_scheduler_api
node_scheduler_api -->|"invokes"| node_scheduler
node_scheduler -->|"uses"| node_scheduler_service
node_scheduler_service -->|"reads and writes schedules"| node_postgres
node_graphql -->|"executes"| node_match_mutations
node_match_mutations -->|"updates live state"| node_mongodb
node_match_mutations -->|"publishes changes"| node_redis
node_graphql -->|"serves"| node_subscriptions
node_subscriptions -->|"consumes updates"| node_redis
node_event_workers -->|"processes timed state"| node_mongodb
node_event_workers -->|"broadcasts transitions"| node_redis
node_backend_api -->|"stores documents"| node_object_storage

click node_admin "https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/page.tsx"
click node_admin_event_context "https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/events/%5Bslug%5D/layout.tsx"
click node_schedule_editor "https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/events/%5Bslug%5D/schedule/components/schedule-manager.tsx"
click node_volunteer "https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/page.tsx"
click node_live_workflows "https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/(volunteer)/(dashboard)/scorekeeper/page.tsx"
click node_audience_display "https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/(volunteer)/audience-display/page.tsx"
click node_portal "https://github.com/firstisrael/lems/blob/main/apps/portal/src/app/%5Blocale%5D/page.tsx"
click node_public_event "https://github.com/firstisrael/lems/blob/main/apps/portal/src/app/%5Blocale%5D/event/%5Bslug%5D/page.tsx"
click node_backend_api "https://github.com/firstisrael/lems/blob/main/apps/backend/src/main.ts"
click node_authorization "https://github.com/firstisrael/lems/blob/main/apps/backend/src/routers/admin/middleware/require-permission.ts"
click node_graphql "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/apollo-server.ts"
click node_match_mutations "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts"
click node_subscriptions "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/resolvers/subscriptions/matches/index.ts"
click node_event_workers "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/queues/worker-manager.ts"
click node_scheduler_api "https://github.com/firstisrael/lems/blob/main/apps/backend/src/routers/scheduler/divisions/index.ts"
click node_scheduler "https://github.com/firstisrael/lems/blob/main/apps/scheduler/src/main.py"
click node_scheduler_service "https://github.com/firstisrael/lems/blob/main/apps/scheduler/src/services/scheduler_service.py"
click node_postgres "https://github.com/firstisrael/lems/blob/main/libs/database/src/schema/kysely.ts"
click node_mongodb "https://github.com/firstisrael/lems/blob/main/libs/database/src/schema/documents/robot-game-match-state.ts"
click node_redis "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/redis/redis-pubsub.ts"
click node_object_storage "https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/blob-storage/s3-client.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_admin,node_admin_event_context,node_schedule_editor,node_volunteer,node_live_workflows,node_audience_display,node_portal,node_public_event toneBlue
class node_backend_api,node_authorization,node_graphql,node_match_mutations,node_subscriptions,node_event_workers,node_scheduler_api toneAmber
class node_scheduler,node_scheduler_service toneMint
class node_postgres,node_mongodb,node_redis toneRose
class node_object_storage toneIndigo
```

## Components

### Web clients

Role-specific Next.js applications.

- [Admin app](https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/page.tsx): Next.js · Configures events, resources, awards, and schedules. · `apps/admin/src/app/[locale]/(dashboard)/page.tsx`
- [Event-scoped admin](https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/events/%5Bslug%5D/layout.tsx): route layout · Scopes administration by event slug and division. · `apps/admin/src/app/[locale]/(dashboard)/events/[slug]/layout.tsx`
- [Schedule editor](https://github.com/firstisrael/lems/blob/main/apps/admin/src/app/%5Blocale%5D/(dashboard)/events/%5Bslug%5D/schedule/components/schedule-manager.tsx): admin feature · Interactive schedule editing workflow. · `apps/admin/src/app/[locale]/(dashboard)/events/[slug]/schedule/components/schedule-manager.tsx`
- [Volunteer live app](https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/page.tsx): Next.js · Role-oriented field, judging, queueing, and lead workflows. · `apps/frontend/src/app/[locale]/lems/page.tsx`
- [Match and judging workflows](https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/(volunteer)/(dashboard)/scorekeeper/page.tsx): volunteer screens · Scorekeepers and judges operate matches, sessions, and rubrics. · `apps/frontend/src/app/[locale]/lems/(volunteer)/(dashboard)/scorekeeper/page.tsx`
- [Audience display](https://github.com/firstisrael/lems/blob/main/apps/frontend/src/app/%5Blocale%5D/lems/(volunteer)/audience-display/page.tsx): live display · Public-facing live display driven by real-time APIs. · `apps/frontend/src/app/[locale]/lems/(volunteer)/audience-display/page.tsx`
- [Public portal](https://github.com/firstisrael/lems/blob/main/apps/portal/src/app/%5Blocale%5D/page.tsx): Next.js · Publishes schedules, teams, scoreboard, awards, and results. · `apps/portal/src/app/[locale]/page.tsx`
- [Public event pages](https://github.com/firstisrael/lems/blob/main/apps/portal/src/app/%5Blocale%5D/event/%5Bslug%5D/page.tsx): portal route · 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](https://github.com/firstisrael/lems/blob/main/apps/backend/src/main.ts): Node API · Consumer-segregated REST integration boundary. · `apps/backend/src/main.ts`
- [Authorization boundary](https://github.com/firstisrael/lems/blob/main/apps/backend/src/routers/admin/middleware/require-permission.ts): middleware · Applies auth, CSRF, CAPTCHA, permissions, and event/division context. · `apps/backend/src/routers/admin/middleware/require-permission.ts`
- [Live GraphQL API](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/apollo-server.ts): Apollo GraphQL · Mutations and subscriptions for volunteer workflows. · `apps/backend/src/lib/graphql/apollo-server.ts`
- [Match state mutations](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts): GraphQL resolver · Transitions live match state from volunteer actions. · `apps/backend/src/lib/graphql/resolvers/mutations/matches/index.ts`
- [Live subscriptions](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/graphql/resolvers/subscriptions/matches/index.ts): GraphQL resolver · Streams match and related operational updates. · `apps/backend/src/lib/graphql/resolvers/subscriptions/matches/index.ts`
- [Scheduled-event workers](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/queues/worker-manager.ts): worker manager · Runs timing-driven completion and endgame handlers. · `apps/backend/src/lib/queues/worker-manager.ts`
- [Scheduler REST router](https://github.com/firstisrael/lems/blob/main/apps/backend/src/routers/scheduler/divisions/index.ts): backend router · Authenticated division-scoped scheduling interface. · `apps/backend/src/routers/scheduler/divisions/index.ts`

### Scheduling

Schedule generation service and integration.

- [Python scheduler](https://github.com/firstisrael/lems/blob/main/apps/scheduler/src/main.py): Python service · Generates and adjusts event schedules. · `apps/scheduler/src/main.py`
- [Schedule generation](https://github.com/firstisrael/lems/blob/main/apps/scheduler/src/services/scheduler_service.py): service layer · Scheduler request handling and generation logic. · `apps/scheduler/src/services/scheduler_service.py`

### Data services

Persistent and real-time infrastructure.

- [PostgreSQL event model](https://github.com/firstisrael/lems/blob/main/libs/database/src/schema/kysely.ts): relational database · Stores seasons, events, divisions, teams, schedules, awards, and resources. · `libs/database/src/schema/kysely.ts`
- [MongoDB operations state](https://github.com/firstisrael/lems/blob/main/libs/database/src/schema/documents/robot-game-match-state.ts): document database · Stores mutable matches, rubrics, scoresheets, and deliberations. · `libs/database/src/schema/documents/robot-game-match-state.ts`
- [Redis pub/sub](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/redis/redis-pubsub.ts): real-time bus · Distributes operational state updates to subscriptions. · `apps/backend/src/lib/redis/redis-pubsub.ts`

### External services

Document storage and outbound integrations.

- [Object storage](https://github.com/firstisrael/lems/blob/main/apps/backend/src/lib/blob-storage/s3-client.ts): S3 client · Stores documents and pit maps in DigitalOcean object storage. · `apps/backend/src/lib/blob-storage/s3-client.ts`

## Connections

- 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
