Files
spotlightcam/backend
Radosław Gierwiało a110ddb6a6 feat: implement incremental matching to preserve accepted suggestions
Phase 1 implementation of intelligent rebalancing that preserves
accepted/completed suggestions when rerunning matching algorithm.

**saveMatchingResults changes:**
- Delete only non-committed suggestions (status notIn ['accepted', 'completed'])
- Future-proof: any new statuses (expired, cancelled) auto-cleaned
- Filter out heats that already have accepted/completed suggestions
- Only create new suggestions for unmatched heats

**runMatching changes:**
- Build heatById map for efficient lookup
- Fetch existing accepted/completed suggestions before matching
- Initialize recorderAssignmentCount with accepted assignments
  * Prevents exceeding MAX_RECORDINGS_PER_PERSON
  * Treats accepted suggestions as if created in current run
- Initialize recorderBusySlots with accepted heat slots
  * Prevents slot collisions (two dancers in same time slot)
  * Respects existing recorder commitments
- Skip heats that already have accepted recorders
  * Avoids duplicate suggestions for matched heats

**Integration tests:**
- Phase 1: Preserve accepted suggestions on rerun (3 tests)
  * Verify initial suggestions created
  * Accept suggestion and verify match created
  * Rerun matching and verify accepted preserved, others regenerated
- Phase 2 & 3: Skipped (TODO for future)

**Results:**
- 307/308 tests passing (up from 304)
- No regressions
- Fixes critical bugs:
  * Orphaned matches when rerunning
  * Exceeding recorder limits
  * Slot double-booking
2025-11-30 11:26:43 +01:00
..

spotlight.cam Backend

Node.js + Express backend for spotlight.cam - P2P video exchange app for dance events.

Features

  • Express REST API
  • CORS enabled
  • Health check endpoint
  • Error handling
  • Unit tests (Jest + Supertest)
  • PostgreSQL integration (planned)
  • JWT authentication (planned)
  • Socket.IO for real-time chat (planned)
  • WebRTC signaling (planned)

API Endpoints

Health Check

  • GET /api/health - Backend health status

Future Endpoints

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • GET /api/users/me - Get current user
  • GET /api/events - List events
  • POST /api/matches - Create match
  • POST /api/ratings - Rate partner

Development

Install dependencies

npm install

Run in development mode

npm run dev

Run tests

npm test

Run tests in watch mode

npm run test:watch

Run in production mode

npm start

Environment Variables

Create a .env file (see .env.example):

NODE_ENV=development
PORT=3000
CORS_ORIGIN=http://localhost:8080

Project Structure

backend/
├── src/
│   ├── __tests__/          # Unit tests
│   │   └── app.test.js
│   ├── routes/             # API routes (future)
│   ├── controllers/        # Business logic (future)
│   ├── middleware/         # Custom middleware (future)
│   ├── utils/              # Helper functions (future)
│   ├── app.js              # Express app setup
│   └── server.js           # Server entry point
├── .env                    # Environment variables (gitignored)
├── .env.example            # Environment variables template
├── package.json
└── Dockerfile

Testing

Tests are written using:

  • Jest - Test framework
  • Supertest - HTTP assertions

Run tests:

npm test

Current test coverage:

  • Health check endpoint
  • 404 error handling
  • CORS configuration
  • JSON body parsing

Docker

Build and run with Docker Compose (from project root):

docker compose up --build

Backend will be available at:

Next Steps

  1. Basic Express setup
  2. Health check endpoint
  3. Unit tests
  4. PostgreSQL connection
  5. Database schema and migrations
  6. Authentication (JWT + bcrypt)
  7. Socket.IO for real-time chat
  8. WebRTC signaling

License

TBD