Files
spotlightcam/backend
Radosław Gierwiało 75cb4b16e7 feat: implement real-time chat with Socket.IO
Implemented WebSocket-based real-time messaging for both event rooms and private match chats using Socket.IO with comprehensive test coverage.

Backend changes:
- Installed socket.io@4.8.1 for WebSocket server
- Created Socket.IO server with JWT authentication middleware
- Implemented event room management (join/leave/messages)
- Added active users tracking with real-time updates
- Implemented private match room messaging
- Integrated Socket.IO with Express HTTP server
- Messages are persisted to PostgreSQL via Prisma
- Added 12 comprehensive unit tests (89.13% coverage)

Frontend changes:
- Installed socket.io-client for WebSocket connections
- Created socket service layer for connection management
- Updated EventChatPage with real-time messaging
- Updated MatchChatPage with real-time private chat
- Added connection status indicators (● Connected/Disconnected)
- Disabled message input when not connected

Infrastructure:
- Updated nginx config to proxy WebSocket connections at /socket.io
- Added Upgrade and Connection headers for WebSocket support
- Set long timeouts (7d) for persistent WebSocket connections

Key features:
- JWT-authenticated socket connections
- Room-based architecture for events and matches
- Real-time message broadcasting
- Active users list with automatic updates
- Automatic cleanup on disconnect
- Message persistence in database

Test coverage:
- 12 tests passing (authentication, event rooms, match rooms, disconnect, errors)
- Socket.IO module: 89.13% statements, 81.81% branches, 91.66% functions
- Overall coverage: 81.19%

Phase 1, Step 4 completed. Ready for Phase 2 (Core Features).
2025-11-12 22:42:15 +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