TurfBD is Bangladesh's premier, full-stack sports arena and box cricket slot booking ecosystem. Built with a high-performance React 19 single-page application frontend, an Express + TypeScript API engine, and a PostgreSQL persistence layer backed by Drizzle ORM.
- Architectural Overview
- Project Directory Structure
- Environment Variables Reference
- Database Setup & Migrations
- Admin Credentials Setup Guide
- Local Development & Quick Start
- Production Deployment Instructions
- Automated Regression & Payment Test Suites
- Payment Gateway Integration Guide
- Exporting the Project
- Frontend: React 19 + TypeScript, Tailwind CSS v4, Lucide React icons, Motion animations.
- Backend: Node.js + Express 4, compiled via Vite & bundled with
esbuildfor zero-overhead CJS production execution (dist/server.cjs). - Database: PostgreSQL (Cloud SQL or self-hosted) with Drizzle ORM for type-safe schema definitions and relation mappings.
- Authentication: Dual-token JWT (Access Token + Refresh Token with rotation), bcrypt password hashing, phone OTP verification, plus Google and Facebook OAuth providers.
- Payment Gateways: Native integrations for bKash (Tokenized Checkout API), Nagad (PG API), and SSLCommerz (Session & IPN Webhook validation) with tamper-proofing and replay protection.
- File Storage: Dual-tier storage supporting local disk storage with Sharp image resizing/optimization or Google Cloud Storage (GCS) buckets.
turfbd/
├── .env.example # Production & development environment variable templates
├── .gitignore # Git exclusion rules
├── .dockerignore # Docker build context filters
├── Dockerfile # Multi-stage production container build manifest
├── README.md # Core project documentation & handover guide
├── HANDOVER.md # Comprehensive operational handover specification
├── package.json # Project dependencies, scripts, and runtime engines
├── server.ts # Main Express backend server & Vite middleware entry
├── vite.config.ts # Vite configuration with Tailwind CSS plugin
├── tsconfig.json # TypeScript compiler options
├── metadata.json # AI Studio application metadata & frame permissions
├── index.html # HTML entry point with TurfBD meta tags and favicons
│
├── public/ # Static assets served by Express and Vite
│ ├── favicon.svg # Official vector TurfBD brand icon
│ ├── favicon-32x32.png # Standard browser favicon
│ ├── apple-touch-icon.png # iOS home screen web-clip icon
│ ├── logo.svg # Full vector TurfBD brand mark & typography
│ ├── logo.png # High-resolution raster logo (transparent PNG)
│ ├── logo-dark.png # Dark-variant TurfBD logo
│ └── uploads/ # Local directory for venue photos and owner KYC documents
│
├── src/ # Application Source Code
│ ├── App.tsx # Root React application layout, modals & router logic
│ ├── main.tsx # React DOM client bootstrap
│ ├── index.css # Global stylesheet with Tailwind CSS rules
│ ├── types.ts # Central TypeScript interfaces, types & data models
│ │
│ ├── components/ # Modular UI components
│ │ ├── Navbar.tsx # Responsive navigation header with active role badges
│ │ ├── TurfBDLogo.tsx # Standardized brand logo component (variants & sizes)
│ │ ├── LoadingSplash.tsx # Branded pulse loading splash screen
│ │ ├── SearchBar.tsx # City, area, sport, and date filter controls
│ │ ├── TurfCard.tsx # Arena presentation card with rates and amenities
│ │ ├── TurfDetailModal.tsx # Detailed venue profile, image gallery & reviews
│ │ ├── BookingModal.tsx # Slot selection, advance/full payment selection
│ │ ├── PaymentGatewayModal.tsx # bKash, Nagad & SSLCommerz checkout modal
│ │ ├── PaymentReceiptModal.tsx # Printable verified voucher & QR match pass
│ │ ├── BookingDetailsModal.tsx # Full booking details & voucher presentation
│ │ ├── CancellationModal.tsx # Automated booking cancellation & refund request
│ │ ├── MyBookings.tsx # Player booking history & match status cards
│ │ ├── OwnerDashboard.tsx # Venue owner management portal & payout requests
│ │ ├── AdminPanel.tsx # Super Admin operations, venue verification & audits
│ │ └── ReviewSection.tsx # Customer rating submission & verified feedback
│ │
│ ├── context/
│ │ └── AppContext.tsx # Global React state management with PostgreSQL sync
│ │
│ ├── services/
│ │ └── api.ts # Client-side HTTP API client with auth token headers
│ │
│ ├── data/
│ │ └── mockData.ts # Offline fallback seed fixtures & demo records
│ │
│ ├── db/ # PostgreSQL Database & Drizzle ORM
│ │ ├── schema.ts # Drizzle relational table definitions & relations
│ │ ├── index.ts # Pooled PostgreSQL connection instance
│ │ └── drizzle.config.ts # Drizzle Kit CLI migration configuration
│ │
│ └── server/ # Backend Express Controllers & Services
│ ├── middleware/
│ │ └── auth.ts # JWT verification & role authorization (owner/admin)
│ ├── routes/
│ │ ├── auth.ts # Sign in, sign up, OTP, OAuth, refresh tokens
│ │ ├── turfs.ts # Turf listing, creation, updates & admin verification
│ │ ├── slots.ts # Real-time slot availability, locking & management
│ │ ├── bookings.ts # Slot booking, confirmation & conflict prevention
│ │ ├── payments.ts # Gateways, callbacks, IPN webhooks, refunds & audit
│ │ ├── reviews.ts # Player ratings & verified customer feedback
│ │ ├── reports.ts # Super admin business analytics & revenue reports
│ │ └── uploads.ts # Multipart file upload handler with Sharp compression
│ ├── services/gateways/
│ │ ├── bkash.ts # bKash Tokenized Checkout API integration
│ │ ├── nagad.ts # Nagad Merchant Payment integration
│ │ ├── sslcommerz.ts # SSLCommerz Hosted Session & IPN Validator
│ │ └── gatewayManager.ts# Unified payment gateway dispatch interface
│ └── utils/
│ ├── auth.ts # Token generators, cookie handlers, rate limiters
│ └── storage.ts # Cloud Storage and local disk file abstraction
│
├── scripts/ # Operational, Seeding & Testing Automation
│ ├── seed.ts # Idempotent PostgreSQL seeder (users, turfs, slots)
│ ├── create_admin.ts # CLI provisioning script for Super Admin accounts
│ └── regression_test.ts # End-to-end regression test suite (9 test suites)
│
└── test_payment_regression.ts # Comprehensive payment & security test suite (22 test suites)
Create a .env file in the root directory (or inject variables via your hosting provider's secrets manager):
| Variable | Required | Default / Example | Purpose |
|---|---|---|---|
NODE_ENV |
Yes | production |
Node execution environment |
PORT |
Yes | 3000 |
HTTP server port |
APP_URL |
Yes | https://turfbd.com |
Base public URL for redirects & webhooks |
SQL_HOST |
Yes | 127.0.0.1 |
PostgreSQL database host |
SQL_PORT |
No | 5432 |
PostgreSQL database port |
SQL_DB_NAME |
Yes | turfbd |
PostgreSQL database name |
SQL_USER |
Yes | turfbd_app |
PostgreSQL runtime database username |
SQL_PASSWORD |
Yes | [SECURE_DB_PASSWORD] |
PostgreSQL runtime database password |
SQL_ADMIN_USER |
For CLI | postgres |
Superuser for Drizzle migrations |
SQL_ADMIN_PASSWORD |
For CLI | [SECURE_ADMIN_PASSWORD] |
Superuser password for Drizzle migrations |
JWT_SECRET |
Yes | [RANDOM_64_CHAR_HEX] |
Secret key used to sign access tokens (15m) |
JWT_REFRESH_SECRET |
Yes | [RANDOM_64_CHAR_HEX] |
Secret key used to sign refresh tokens (7d) |
BKASH_APP_KEY |
Optional | sandbox_app_key |
bKash Merchant App Key |
BKASH_APP_SECRET |
Optional | sandbox_secret |
bKash Merchant App Secret |
BKASH_USERNAME |
Optional | sandbox_user |
bKash API Username |
BKASH_PASSWORD |
Optional | sandbox_pass |
bKash API Password |
BKASH_SANDBOX |
No | true |
Set false for live production gateway |
NAGAD_MERCHANT_ID |
Optional | 68000100 |
Nagad Merchant ID |
NAGAD_SANDBOX |
No | true |
Set false for live production gateway |
SSLCOMMERZ_STORE_ID |
Optional | turfbdlive001 |
SSLCommerz Store ID |
SSLCOMMERZ_STORE_PASS |
Optional | [STORE_PASSWORD] |
SSLCommerz Store Password |
SSLCOMMERZ_SANDBOX |
No | true |
Set false for live production gateway |
GCS_BUCKET_NAME |
Optional | turfbd-storage |
Google Cloud Storage bucket (local if unset) |
GOOGLE_CLIENT_ID |
Optional | [GOOGLE_OAUTH_ID] |
Google OAuth Client ID |
GOOGLE_CLIENT_SECRET |
Optional | [GOOGLE_SECRET] |
Google OAuth Client Secret |
FACEBOOK_APP_ID |
Optional | [FB_APP_ID] |
Facebook Login App ID |
FACEBOOK_APP_SECRET |
Optional | [FB_SECRET] |
Facebook Login App Secret |
TurfBD uses PostgreSQL with Drizzle ORM.
# Connect to PostgreSQL as admin
psql -U postgres -h localhost
# Create database and application user
CREATE DATABASE turfbd;
CREATE USER turfbd_app WITH ENCRYPTED PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE turfbd TO turfbd_app;
\qDrizzle Kit synchronizes src/db/schema.ts directly into PostgreSQL:
npm run db:pushSeed standard administrator, venue owners, player accounts, featured venues, and booking slots:
npm run db:seedTurfBD includes a dedicated command-line utility for provisioning or upgrading Super Administrator accounts with zero manual database editing.
Run the following command in your terminal:
npm run admin:create <email> <password> <name> <phone>Example:
npm run admin:create admin@turfbd.com "SuperSecret2026!" "Platform Administrator" "+8801912334455"The script:
- Validates input parameters and sanitizes the email.
- Hashes the password with bcrypt (salt rounds = 10).
- If the account does not exist, creates a new user with
role: 'admin', verified email, and verified phone. - If the account already exists, elevates the user's role to
'admin', resets lockouts, and updates credentials.
If you ran npm run db:seed, the following default administrator account is available:
- Email:
admin@turfbd.com - Password:
Password123! - Role:
admin - Access Level: Unrestricted access to Venue Verification, Global Booking Ledger, Financial Audits, Commission Settings, and User Management.
Security Note: Before going live, immediately change the default password by running:
npm run admin:create admin@turfbd.com "NewStrongPassword" "Super Admin" "+8801912334455"
git clone <repository-url>
cd turfbd
npm installcp .env.example .env
# Edit .env with your PostgreSQL credentialsnpm run db:push
npm run db:seednpm run devThe application will be accessible at: http://localhost:3000
- Build and push the container image:
gcloud builds submit --tag gcr.io/[PROJECT_ID]/turfbd:latest .- Deploy the container to Cloud Run:
gcloud run deploy turfbd \
--image gcr.io/[PROJECT_ID]/turfbd:latest \
--platform managed \
--region asia-southeast1 \
--allow-unauthenticated \
--port 3000 \
--set-env-vars NODE_ENV=production \
--add-cloudsql-instances [PROJECT_ID]:asia-southeast1:turfbd-dbBuild and run using the included production Dockerfile:
# Build the Docker image
docker build -t turfbd:production .
# Run container with environment file
docker run -d \
--name turfbd-app \
-p 3000:3000 \
--env-file .env \
-v turfbd_uploads:/app/public/uploads \
--restart unless-stopped \
turfbd:production- Build the production bundle:
npm run buildThis produces:
dist/: Optimized Vite client-side static bundle.dist/server.cjs: Self-contained, bundled CommonJS Express server.
- Start the application with PM2:
npm install -g pm2
pm2 start dist/server.cjs --name "turfbd" -i max
pm2 save
pm2 startup- Nginx Reverse Proxy Configuration (
/etc/nginx/sites-available/turfbd):
server {
listen 80;
server_name turfbd.com www.turfbd.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name turfbd.com www.turfbd.com;
ssl_certificate /etc/letsencrypt/live/turfbd.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/turfbd.com/privkey.pem;
client_max_body_size 20M;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}TurfBD comes pre-packaged with two end-to-end automated testing suites verifying all business-critical workflows:
Tests health check, registration, login, phone OTP flow, venue listings, slot locking, double-booking prevention, owner dashboard, admin audit, and upload handlers:
npm run test:regressionTests bKash tokenized flow, Nagad gateway, SSLCommerz hosted sessions, IPN webhooks, duplicate transaction replay prevention, amount tampering detection, expired session handling, owner revenue settlements, and 5% platform commission calculations:
npm run test:paymentsTurfBD features production-ready integrations for all three premier Bangladeshi payment methods:
-
bKash (Tokenized Checkout API):
- Implemented in
src/server/services/gateways/bkash.ts. - Sandbox testing credentials provided by bKash developer portal.
- Switch to live by setting
BKASH_SANDBOX=falseand inserting your live merchant keys in.env.
- Implemented in
-
Nagad (Online Payment Gateway):
- Implemented in
src/server/services/gateways/nagad.ts. - Generates merchant cryptographic transaction payloads.
- Switch to live by setting
NAGAD_SANDBOX=falseand adding your registeredNAGAD_MERCHANT_ID.
- Implemented in
-
SSLCommerz (Hosted Gateway & IPN Webhook):
- Implemented in
src/server/services/gateways/sslcommerz.ts. - Supports credit cards, debit cards, internet banking, and mobile banking.
- Switch to live by setting
SSLCOMMERZ_SANDBOX=falsewith your liveSSLCOMMERZ_STORE_IDandSSLCOMMERZ_STORE_PASS.
- Implemented in
To export this project for repository hosting (GitHub / GitLab / Bitbucket) or distribution:
- In Google AI Studio, open the Project Settings menu on the top right.
- Select Export to GitHub to link directly to your Git repository, or click Download ZIP to get a complete, self-contained project archive.
- The archive contains all source code, public assets, database definitions, scripts, and Docker configuration files ready for deployment.