Backend API for BePARTy - A platform for nightclubs and DJs where users earn digital tokens and spend them to vote for songs, creating an interactive nightlife experience.
BePARTy is a SaaS platform that transforms nightclub experiences by:
- Token Economy: Users earn digital tokens by buying tickets, drinks, or directly in-app
- Song Voting: Spend tokens to vote for songs and influence DJ playlists
- Real-time Dashboard: DJs get live audience preference data
- Enhanced Engagement: Features like song auctions, golden hours, and raffles
- Business Model: SaaS for clubs and DJs
- Runtime: Node.js 20 LTS
- Framework: Express 5 with TypeScript
- Database: PostgreSQL 16 with Prisma ORM
- Real-time: Socket.IO
- Security: Helmet, CORS, Rate Limiting
- Validation: Zod
- Documentation: OpenAPI/Swagger
- Logging: Pino
- Testing: Jest + Supertest
- Containerization: Docker & Docker Compose
- Node.js 20 LTS
- Docker & Docker Compose
- npm (comes with Node.js)
-
Clone and install dependencies:
git clone <repository-url> cd beparty-server npm install
-
Environment setup:
cp .env.example .env.development
-
Start the infrastructure:
npm run docker:up
-
Database setup:
npx prisma generate npx prisma migrate dev --name init_mvp npm run prisma:seed
-
Start development server:
npm run dev
- API Health: http://localhost:3000/api/health
- API Documentation: http://localhost:3000/api/docs
- Socket.IO: http://localhost:3000/realtime
The MVP includes a minimal but complete token-based voting system:
- Users: DJ and USER roles with token balances
- Sessions: DJ-created rooms for voting
- SessionSongs: Song aggregates with Spotify integration
- Votes: Individual token spending records
- TokenTransactions: Complete token ledger for audit
# Generate Prisma client
npx prisma generate
# Run migrations
npx prisma migrate dev --name init_mvp
# Seed with sample data
npm run prisma:seed
# Reset database (development only)
npx prisma migrate reset --forceCheck the session scoreboard with:
SELECT ss.spotify_track_id, ss.track_name, ss.artist_name, ss.total_tokens
FROM "session_songs" ss
WHERE ss.session_id = '<SESSION_ID>'
ORDER BY ss.total_tokens DESC;Example with seeded data:
SELECT ss.spotify_track_id, ss.track_name, ss.artist_name, ss.total_tokens
FROM "session_songs" ss
WHERE ss.session_id = 'cmfx4ei2h000acz48kgfhrw5x'
ORDER BY ss.total_tokens DESC;The system maintains token balance integrity:
-- Verify user token balance matches transaction ledger
SELECT
u.display_name,
u.tokens_balance as current_balance,
COALESCE(SUM(CASE WHEN tt.direction = 'EARN' THEN tt.amount ELSE 0 END), 0) -
COALESCE(SUM(CASE WHEN tt.direction = 'SPEND' THEN tt.amount ELSE 0 END), 0) as ledger_balance
FROM "users" u
LEFT JOIN "token_transactions" tt ON u.id = tt.user_id
WHERE u.deleted_at IS NULL
GROUP BY u.id, u.display_name, u.tokens_balance;npm run docker:up-
Run database migrations and seed:
npm run prisma:migrate npm run prisma:seed
-
Start the development server:
npm run dev
The API will be available at:
- API: http://localhost:3000/api
- Health Check: http://localhost:3000/api/health
- API Documentation: http://localhost:3000/api/docs
- Socket.IO: http://localhost:3000/realtime
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production server
npm run lint- Run ESLintnpm run lint:fix- Fix ESLint issuesnpm test- Run testsnpm run test:watch- Run tests in watch mode
npm run prisma:generate- Generate Prisma clientnpm run prisma:migrate- Run database migrationsnpm run prisma:seed- Seed database with test data
npm run docker:up- Start all servicesnpm run docker:down- Stop all servicesnpm run docker:logs- View logs
The docker-compose.yml includes:
- api: BePARTy server (port 3000)
- db: PostgreSQL 16 (port 5432)
- pgadmin: Database management UI (port 8080) - optional
# Start all services
docker compose up -d
# Start with PgAdmin
docker compose --profile tools up -d
# View logs
docker compose logs -f api
# Stop services
docker compose downsrc/
โโโ config/ # Configuration (env, logger)
โโโ loaders/ # App initialization (express, prisma, socket)
โโโ api/
โ โโโ routes/ # Route definitions
โ โโโ controllers/ # Request handlers
โ โโโ middlewares/ # Custom middleware
โ โโโ schemas/ # Validation schemas
โ โโโ docs/ # OpenAPI documentation
โโโ modules/ # Future feature modules
โโโ app.ts # App setup and configuration
โโโ server.ts # Server entry point
prisma/
โโโ schema.prisma # Database schema
โโโ seed.ts # Database seeding
tests/
โโโ setup.ts # Test configuration
โโโ *.test.ts # Test files
Run the test suite:
npm testTest the API endpoints:
# Health check
curl http://localhost:3000/api/health
# Socket.IO (using wscat or similar)
wscat -c "http://localhost:3000/realtime"Interactive API documentation is available at /api/docs when the server is running.
Key endpoints:
GET /api/health- Health check with server status
- Linting: ESLint with TypeScript rules
- Formatting: Prettier integration
- Imports: Organized with import/order plugin
Use Conventional Commits format:
feat/: New featuresfix/: Bug fixeschore/: Maintenance tasksdocs/: Documentation updates
feat/feature-namefix/bug-descriptionchore/task-description
- Authentication: JWT + OAuth integration
- Token Economy: Internal token management
- Voting System: Song voting mechanics
- Auctions: Bidding system for songs
- Draws/Raffles: Prize distribution system
- Real-time: Advanced room management
- Billing: Stripe integration
- Multi-tenancy: Support for multiple venues
- Multi-tenancy:
tenant_idin relevant tables - RBAC: Role-based access (owner, dj, staff, user)
- Observability: Enhanced logging and monitoring
- CI/CD: Automated testing and deployment
Port conflicts:
# Check what's using port 3000
netstat -tulpn | grep 3000
# Kill the process or change PORT in .envDatabase connection:
# Check if PostgreSQL is running
docker compose ps
# View database logs
docker compose logs dbPermission issues (Linux/Mac):
# Fix Docker permissions
sudo chown -R $USER:$USER .Prisma issues:
# Reset database
npm run prisma:migrate -- --name reset
npm run prisma:seedMIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Ensure all tests pass
- Submit a pull request
Built with โค๏ธ for the nightlife community