A real-time queue management system for stations, built with modern web technologies. Perfect for managing customer queues at service stations, government offices, banks, or any location requiring organized queue management.
- No Login Required: Users join queues instantly without registration (tracked by browser storage)
- Multiple Queues: Join multiple station queues simultaneously
- Real-time Updates: See your queue position update instantly via WebSocket connections
- Notifications: Get notified when your turn approaches
- Mobile Responsive: Works seamlessly on all devices
- Station Dashboard: View and manage your station's queue in real-time
- Queue Control: Pop customers from the queue when served
- Station-specific Access: Secure access via unique station manager ID
- Station Management: Create and delete stations
- System Overview: Monitor all stations in the system
- Secure Access: Protected by admin secret key
- Real-time Communication: Powered by Ably for instant updates
- Fallback Polling: Automatic fallback when WebSocket connection fails
- Smart Queue Numbering: Positions start from 100 for better UX
- Data Integrity: Cascading deletes ensure clean data management
- Type Safety: Full TypeScript implementation
- Comprehensive Testing: Unit tests for all components
- Frontend: React 18, TypeScript, Vite
- Backend: Node.js, Express 5, Netlify Functions
- Database: PostgreSQL/SQLite with Prisma ORM
- Real-time: Ably WebSocket connections
- Styling: Bootstrap 5
- Testing: Vitest, React Testing Library
- Deployment: Netlify
- Node.js 18+ and npm
- PostgreSQL database (or SQLite for local development)
- Ably account for real-time features
- Netlify CLI (for local development with functions)
git clone https://github.com/your-username/station-queue.git
cd station-queue
npm installCreate a .env file in the root directory:
# Database Configuration
DATABASE_URL="postgresql://user:password@localhost:5432/station_queue"
# For SQLite: DATABASE_URL="file:./dev.db"
# Admin Secret (for admin panel access)
ADMIN_SECRET="your-admin-secret-key"
# API Configuration (optional)
VITE_API_URL=http://localhost:5000
VITE_API_TIMEOUT=30000
VITE_API_RETRY_ATTEMPTS=3
VITE_API_RETRY_DELAY=1000# Generate Prisma client
npx prisma generate --no-engine
# Run migrations
npx prisma migrate dev
# (Optional) Seed with sample data
npx prisma db seedThis application uses two separate Ably API keys for security:
npm run set-backend-ably-key YOUR_BACKEND_ABLY_API_KEYnpm run set-frontend-ably-key YOUR_FRONTEND_ABLY_API_KEYSecurity Notes:
- Backend key should have publish and subscribe capabilities
- Frontend key should be limited to subscribe-only permissions
- Keys are stored securely in the database
npm run netlify:devThe app will be available at:
If you are on Windows or where the Netlify CLI does not work, you may need to run the following command to start the server:
# Terminal 1: Start the development server
node dev-server.js# Terminal 2: Start the frontend
npm run devThe app will be available at:
- Frontend: http://localhost:5173
- API: http://localhost:5000 (or as defined in your
.envfile)
# Run all tests
npm test
# Run tests in watch mode
npm test -- --watch
# Run tests with coverage
npm test -- --coverage# Build the application
npm run build
# Preview production build locally
npm run preview-
Connect Repository: Link your GitHub repository to Netlify
-
Configure Build Settings:
- Build command:
npm run build - Publish directory:
dist - Functions directory:
netlify/functions
- Build command:
-
Set Environment Variables in Netlify:
DATABASE_URL: Your production database connection stringADMIN_SECRET: Your admin panel secretNODE_VERSION: 18 (or higher)
-
Configure Ably Keys: After deployment, SSH into your production database and run:
INSERT INTO "Config" (key, value) VALUES ('ABLY_API_KEY', 'your-backend-key'), ('VITE_ABLY_API_KEY', 'your-frontend-key');
-
Build the project:
npm run build
-
Deploy the
distfolder to your static hosting service -
Deploy the
netlify/functionsto your serverless platform
- Visit the application URL
- Select a station from the dropdown
- Click "Join Queue"
- Your queue number will be displayed
- Wait for notifications when your turn approaches
- Navigate to
/personor click "Manage Station" - Enter your Station ID and Manager ID
- View real-time queue updates
- Click "Next Customer" to serve the next person
- Navigate to
/adminor click "Admin Panel" - Enter the admin secret
- Create new stations with unique names
- Delete stations (automatically removes all queue data)
# Reset all queue positions (useful for testing)
npm run reset-queue-positions
# Initialize last position counters
npm run init-last-positions
# Clean up orphaned position keys
npm run cleanup-orphaned-keysstation-queue/
├── src/
│ ├── components/ # Reusable UI components
│ ├── hooks/ # Custom React hooks
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ ├── config/ # Configuration modules
│ ├── constants/ # Application constants
│ ├── __tests__/ # Test files
│ ├── App.tsx # Main application component
│ ├── UserQueue.tsx # User queue interface
│ ├── PersonQueue.tsx # Station manager interface
│ └── AdminPanel.tsx # Admin interface
├── netlify/
│ └── functions/ # Serverless API functions
├── prisma/
│ ├── schema.prisma # Database schema
│ └── migrations/ # Database migrations
├── public/ # Static assets
└── dist/ # Production build output
The application automatically detects the environment and configures the API URL:
- Development:
http://localhost:5000 - Production:
/.netlify/functions/api
Override with VITE_API_URL environment variable if needed.
- PostgreSQL (recommended for production)
- SQLite (for local development)
Update the provider in prisma/schema.prisma to match your database.
-
Real-time updates not working
- Verify Ably keys are correctly set
- Check browser console for WebSocket errors
- Ensure frontend key has subscribe permissions
-
Database connection errors
- Verify DATABASE_URL is correct
- Run
npx prisma generateafter schema changes - Check database server is running
-
Build failures
- Clear node_modules and package-lock.json
- Run
npm installagain - Ensure Node.js version is 18+
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.