Skip to content

Code-by-Muazam-Ali/JS-Snooker-Club-Management

Repository files navigation

JS Snooker Club Manager

A complete web application for managing snooker club operations including table management, player sessions, payments, canteen orders, loans, and comprehensive reporting.

Features

Core Features

  • 13 Table Management: Different types (standard, main, room) with real-time status tracking
  • Session Management: Timer-based sessions with automatic pricing calculation
  • Player Management: Add, track, and move players between tables
  • Payment Processing: Support for cash, online, and mixed payment methods
  • Canteen Integration: Add food/drink orders directly to table sessions
  • Loan Management: Track customer loans with partial repayment support
  • Real-time Dashboard: Live table status with elapsed timers
  • Comprehensive Reports: Daily, table-wise, and player-centric analytics

Admin Features

  • Manager Accounts: Create and manage staff accounts
  • Business Rules Configuration: Adjust pricing, discounts, and game rules
  • System Statistics: Performance metrics and revenue tracking
  • Google Sheets Integration: Automatic data backup and sync
  • CSV Export: Download reports for external analysis

Technical Features

  • Real-time Updates: Live timer updates and status changes
  • Mobile Responsive: Optimized for tablet and phone use by managers
  • Role-based Access: Different permissions for admin and managers
  • Data Security: Encrypted passwords and secure authentication
  • Audit Trail: Complete tracking of all transactions and changes

Setup Instructions

Prerequisites

  • Node.js 18+ installed
  • SQLite3 (included in dependencies)
  • Modern web browser

Development Setup

  1. Clone and Install Dependencies
git clone <repository-url>
cd js-snooker-club-manager
npm install
  1. Environment Configuration Create a .env file in the root directory:
PORT=3001
JWT_SECRET=your_jwt_secret_key_here
NODE_ENV=development
  1. Start Development Servers
npm run dev

This starts both the frontend (port 5173) and backend (port 3001) simultaneously.

  1. Access the Application

Production Deployment

  1. Build the Application
npm run build
  1. Production Environment Variables
PORT=3001
JWT_SECRET=your_strong_jwt_secret
NODE_ENV=production
DATABASE_URL=your_production_database_url (optional for PostgreSQL)
  1. Start Production Server
npm run server:start

Database Configuration

SQLite (Default)

  • Database file created automatically at server/database/snooker_club.db
  • Perfect for development and small deployments

PostgreSQL (Production)

  • Update connection settings in server/database/init.js
  • Provide DATABASE_URL environment variable
  • Run database migrations manually

Default Login Credentials

Admin Account:

Manager Account:

Important: Change these default passwords immediately after first login!

API Documentation

Authentication

POST /api/auth/login
GET  /api/auth/verify

Tables Management

GET    /api/tables                    # Get all tables
GET    /api/tables/:id                # Get table details
POST   /api/tables/:id/start-session  # Start new session

Session Management

POST   /api/sessions/:id/end          # End session with payment
POST   /api/sessions/:id/next-game    # Start next game
POST   /api/sessions/:id/add-player   # Add player to session
POST   /api/sessions/:id/move-players # Move players to another table

Canteen

POST   /api/canteen/session/:sessionId  # Add canteen item
GET    /api/canteen/session/:sessionId  # Get session items
DELETE /api/canteen/:id                 # Remove canteen item

Loans

GET    /api/loans                    # Get all loans
POST   /api/loans                    # Create new loan
POST   /api/loans/:id/payment        # Add loan payment
GET    /api/loans/:id/history        # Get loan payment history

Reports

GET    /api/reports/daily            # Daily report
GET    /api/reports/daily/export     # Export daily CSV
GET    /api/reports/manager/:id      # Manager performance
GET    /api/reports/player/:id       # Player activity
GET    /api/reports/trends           # Revenue trends

Admin (Admin only)

GET    /api/admin/managers           # Get all managers
POST   /api/admin/managers           # Create manager
PUT    /api/admin/managers/:id       # Update manager
DELETE /api/admin/managers/:id       # Delete manager
GET    /api/admin/settings           # Get system settings
POST   /api/admin/settings           # Update settings
GET    /api/admin/stats              # System statistics

Business Rules

Pricing Structure

  • Standard Tables (1-10): Rs 150 per game
  • Main Tables (11-12): Rs 250 per game
  • Room Table (13): Rs 500 per hour
  • Century Games: 2x multiplier on base price

Game Types

  • Single: Regular snooker game
  • Double: Two-player team format
  • Century: Premium game type with multiplier
  • Hourly: Time-based billing for room bookings

Payment Methods

  • Cash: Traditional cash payment
  • Online: Bank transfer with account and transaction tracking
  • Mixed: Combination of cash and online payment

Loan System

  • Automatic loan creation for underpayments
  • Partial repayment tracking
  • Interest-free (configurable)
  • Customer-wise loan summaries

Google Sheets Integration

Enable automatic data backup to Google Sheets:

  1. Create Google Service Account

    • Go to Google Cloud Console
    • Create new project or use existing
    • Enable Google Sheets API
    • Create service account and download JSON key
  2. Configure in Admin Panel

    • Navigate to Admin > Settings
    • Enable Google Sheets Sync
    • Enter your Google Sheets ID
    • Paste the service account JSON
  3. Sheet Structure

    • Sessions tab: All game sessions
    • Canteen tab: Food/drink orders
    • Loans tab: Loan records and payments
    • Managers tab: Staff performance data

Testing

Run the test suite:

npm test

Tests cover:

  • API endpoint functionality
  • Authentication and authorization
  • Business logic validation
  • Database operations
  • Error handling

File Structure

├── server/
│   ├── database/
│   │   ├── init.js              # Database setup and seeding
│   │   └── snooker_club.db      # SQLite database file
│   ├── middleware/
│   │   └── auth.js              # Authentication middleware
│   ├── routes/                  # API route handlers
│   │   ├── auth.js              # Authentication routes
│   │   ├── tables.js            # Table management
│   │   ├── sessions.js          # Session operations
│   │   ├── players.js           # Player management
│   │   ├── canteen.js           # Canteen orders
│   │   ├── loans.js             # Loan system
│   │   ├── reports.js           # Analytics and reports
│   │   └── admin.js             # Admin panel functionality
│   └── index.js                 # Express server setup
├── src/
│   ├── components/              # React components
│   │   ├── Auth/                # Login components
│   │   ├── Dashboard/           # Main dashboard and table cards
│   │   ├── Reports/             # Analytics and reporting
│   │   ├── Loans/               # Loan management interface
│   │   ├── Admin/               # Admin panel components
│   │   └── Layout/              # Header and navigation
│   ├── contexts/
│   │   └── AuthContext.tsx      # Authentication context
│   └── App.tsx                  # Main application component
└── package.json                 # Dependencies and scripts

Troubleshooting

Common Issues

Database Connection Errors

  • Ensure SQLite file has write permissions
  • Check database file location and path
  • Verify database initialization completed

Authentication Failures

  • Verify JWT secret is set in environment
  • Check token expiration (24 hours default)
  • Clear browser localStorage if needed

Port Conflicts

  • Frontend default: 5173
  • Backend default: 3001
  • Change ports in vite.config.ts and server/index.js

Google Sheets Sync Issues

  • Verify service account has sheet access
  • Check JSON format in settings
  • Ensure Google Sheets API is enabled

Performance Tips

  • Restart server after database schema changes
  • Clear browser cache for frontend updates
  • Monitor database size and optimize queries
  • Use appropriate table indexes for large datasets

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support and questions:

  • Create GitHub issues for bugs
  • Check documentation for common solutions
  • Review API endpoints for integration help

Built with ❤️ for snooker club management

About

Created with StackBlitz ⚡️

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors