The Word Association Game is a multiplayer online game where players take turns submitting words that are logically associated with the previous word. The game uses OpenAI's GPT model to validate word associations and ensure fair gameplay.
- Players must enter a valid OpenAI API key to start.
- The game begins with an initial word generated by the AI.
- Each player submits a word that is logically associated with the previous word.
- The AI validates word associations before accepting the new word.
- Players earn 10 points for each valid word submission.
- The game continues indefinitely until players decide to stop.
The application is organized into a backend and frontend structure:
word_game_app/
│── backend/ # Server-side code
│ ├── server.js # Express.js and Socket.IO backend
│ ├── package.json # Backend dependencies
│── frontend/ # Client-side code
│ ├── index.html # Main game interface
│── README.md # Documentation
express- Web framework for handling API requests.socket.io- Enables real-time multiplayer communication.body-parser- Parses incoming API requests.node-fetch- Fetches data from OpenAI's API.
- TailwindCSS - For UI styling.
- Socket.IO Client - For real-time updates.
git clone https://github.com/your-username/word-game-app.git
cd word-game-appcd backend
npm installnpm startUse a static server like http-server:
cd ../frontend
npx http-serverVisit the provided URL from http-server in your browser.
This guide walks through deploying the backend of the Word Association Game on Google Cloud Run with Firebase Firestore for persistent game storage.
Before starting, make sure you have:
✅ A Google Cloud account (Sign up)
✅ Google Cloud SDK installed (Install Guide)
✅ A Firebase project set up (Firebase Console)
✅ The backend code with Firebase integration (from the previous step)
Run the following command in your terminal:
gcloud auth loginThis opens a browser window to authenticate your Google account.
gcloud config set project YOUR_PROJECT_IDReplace YOUR_PROJECT_ID with your Google Cloud project ID.
Run these commands to enable necessary services:
gcloud services enable run.googleapis.com firestore.googleapis.com- Cloud Run API → Allows deployment of containerized applications.
- Firestore API → Enables interaction with the Firebase Firestore database.
Ensure you're in the backend directory:
cd word_game_app/backendGoogle Cloud Run needs Firebase permissions to read and write data.
- Go to the Firebase Console → Project Settings → Service accounts
- Click Generate new private key (this downloads a
.jsonfile). - Move the file to your project directory:
mv ~/Downloads/YOUR-FIREBASE-ADMIN-KEY.json ./firebase-admin-sdk.json
Create an .env file in the backend directory:
touch .envEdit the .env file and add:
GOOGLE_APPLICATION_CREDENTIALS=firebase-admin-sdk.json
PORT=8080
Google Cloud Run runs containerized applications. Create a Dockerfile:
touch DockerfilePaste the following into the Dockerfile:
# Use official Node.js image
FROM node:18
# Set working directory
WORKDIR /usr/src/app
# Copy package files and install dependencies
COPY package.json package-lock.json ./
RUN npm install
# Copy all backend files
COPY . .
# Set environment variables
ENV PORT=8080
ENV GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/firebase-admin-sdk.json
# Expose port 8080 for Cloud Run
EXPOSE 8080
# Start the server
CMD ["node", "server.js"]gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/word-game-backendReplace YOUR_PROJECT_ID with your Google Cloud project ID.
gcloud run deploy word-game-backend \
--image gcr.io/YOUR_PROJECT_ID/word-game-backend \
--platform managed \
--region us-central1 \
--allow-unauthenticated--image→ Specifies the Docker image to deploy.--platform managed→ Deploys to fully managed Cloud Run.--region us-central1→ Choose the region closest to your users.--allow-unauthenticated→ Allows anyone to access the game (you can restrict this later).
After deployment, Google Cloud Run provides a URL (e.g., https://word-game-backend-xyz.a.run.app).
Copy this URL for use in the frontend.
Open frontend/index.html and replace:
const BACKEND_URL = "https://word-game-backend-xyz.a.run.app";Replace word-game-backend-xyz.a.run.app with your actual Cloud Run URL.
You can deploy the frontend using:
- Vercel (
vercel deploy) - Netlify (drag and drop
index.html) - Firebase Hosting (
firebase deploy)
- Open your backend URL (
https://word-game-backend-xyz.a.run.app) in the browser → Should return a 404 or JSON response. - Run the game from the frontend and check if:
- Players can join.
- The game state persists across refreshes.
- Word submissions are validated via OpenAI.
- Player scores are stored in Firebase Firestore.
For security:
- Restrict OpenAI API Key usage to your backend's IP.
- Restrict Cloud Run access:
gcloud run services update word-game-backend --no-allow-unauthenticated
- Use Firebase Authentication if you want login-based access. ======= update for Google Cloud services