Skip to content

Muti stage Vite | React | Tailwind project with docker ๐Ÿณ and SSR -> server side rendering ๐ŸŒ intergrated with Gemini โœจ by Google

Notifications You must be signed in to change notification settings

kevinThulnith/multi-stage-react-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NodeJS Vite React TypeScript Tailwind Vercel Docker Nginx Google Gemini

Game Cave ๐ŸŽฎ

A collection of classic game projects developed with Vite | React | Tailwind CSS and TypeScript with Server-Side Rendering (SSR) and Google Gemini AI Integration. ๐Ÿš€ Live Demo on Vercel | ๐Ÿ“ฑ Mobile Friendly | โšก Lightning Fast | ๐Ÿณ Docker Ready | ๐Ÿ”„ SSR Enabled | ๐Ÿค– AI-Powered Features


๐ŸŽฏ Featured Games

๐Ÿงฑ Classic Arcade ๐Ÿงฉ Strategy & Logic ๐ŸŽฒ Casual Fun
๐Ÿงฑ Brick Breaker ๐Ÿ”ด Connect Four ๐ŸŽฏ Number Guesser
๐Ÿ Snake ๐ŸŽฏ Tic Tac Toe ๐Ÿชจ Rock Paper Scissors
๐Ÿ“ Pong ๐Ÿ’ฃ Minesweeper ๐Ÿ”ค Word Scramble
๐Ÿง  Memory Match โšก Typing Test
๐ŸŽช Hangman

๐ŸŒŸ Game Highlights

  • ๐Ÿงฑ Brick Breaker - Classic arcade action with paddle and ball physics
  • ๐Ÿ Snake - Navigate the snake to collect food and grow longer
  • ๐Ÿ”ด Connect Four - Strategic gameplay to connect four pieces in a row
  • ๐Ÿ’ฃ Minesweeper - Clear the minefield using logic and deduction
  • ๐Ÿง  Memory Match - Test your memory with card matching gameplay
  • ๐Ÿ“ Pong - The original tennis-style arcade game
  • ๐ŸŽฏ Tic Tac Toe - Classic 3x3 grid strategy game
  • ๐ŸŽช Hangman - Guess the word before the drawing is complete
  • ๐ŸŽฏ Number Guesser - Challenge your intuition with number guessing
  • ๐Ÿชจ Rock Paper Scissors - The timeless hand game
  • โšก Typing Test - Improve your typing speed and accuracy
  • ๐Ÿ”ค Word Scramble - Unscramble letters to form words

๐Ÿค– AI-Enhanced Features

Experience the power of Google Gemini AI integrated into select games:

  • ๐ŸŽช Hangman - AI generates dynamic word hints and contextual clues
  • ๐Ÿ”ค Word Scramble - Smart difficulty adjustment and AI-powered word generation
  • ๐ŸŽฏ Tic Tac Toe - AI opponent with adaptive difficulty levels
  • ๐Ÿง  Memory Match - Intelligent pattern analysis and performance insights
  • โšก Typing Test - AI-curated text content and personalized improvement suggestions

๐Ÿ’ก Pro Tip: Set up your Gemini API key to unlock these enhanced AI features! The games work perfectly without it, but AI features add an extra layer of intelligence and personalization.


โœจ Key Features

  • ๐ŸŽฎ 12 Classic Games - A diverse collection of timeless games
  • ๐Ÿค– AI-Powered Features - Enhanced gameplay with Google Gemini AI integration
  • ๐Ÿ“ฑ Responsive Design - Perfect on desktop, tablet, and mobile
  • โšก Lightning Fast - Built with Vite for optimal performance
  • ๐ŸŽจ Modern UI - Clean, intuitive interface with TailwindCSS
  • ๐Ÿ”ง Type Safe - Written in TypeScript for reliability
  • ๐Ÿ”„ Server-Side Rendering (SSR) - Faster initial page loads and better SEO
  • ๐Ÿณ Docker Ready - Containerized deployment for any environment
  • ๐ŸŒ Nginx-Optimized Builds - Production images served behind Nginx
  • ๐ŸŒ Multi-Platform Deploy - Vercel, Docker, or cloud platforms
  • ๐ŸŽฏ PWA Ready - Can be installed as a Progressive Web App
  • ๐Ÿ”„ State Management - Smooth game state handling
  • ๐ŸŽต Sound Effects - Immersive audio feedback (coming soon)
  • ๐Ÿ† Score Tracking - Keep track of your best performances

๐Ÿš€ Quick Start

Choose your preferred setup method:

๐Ÿƒโ€โ™‚๏ธ Local Development (Recommended for development)

  • Standard npm setup with hot reload
  • Perfect for development and customization

๐Ÿณ Docker Deployment (Recommended for consistency)

  • Containerized environment
  • Works identically across all platforms
  • Great for teams and production

๐ŸŒ Cloud Deployment (Recommended for production)

  • One-click deploy to Vercel
  • Instant global CDN distribution

๐Ÿ“ฆ Installation

  1. Clone the repository:

    git clone https://github.com/kevinThulnith/multi-stage-react-project.git
  2. Navigate to the project directory:

    cd multi-stage-react-project
  3. Install dependencies:

    npm i
  4. Set up environment variables (required for AI features):

    Create a .env file in the root directory:

    # In the root directory
    touch .env

    Add the following environment variables to your .env file:

    # Required: Gemini API Key for AI-powered game features
    VITE_GEMINI_API_KEY=your_gemini_api_key_here

    Note: The VITE_GEMINI_API_KEY is now actively used in some games for AI-powered features. You can obtain a free API key from Google AI Studio. While the games will still function without the API key, some AI-enhanced features will be disabled.


๐ŸŽฎ Running the Games

Development Mode

npm run dev

// On local Network
npx vite --host {Device Ip Address}
  • Starts the development server at http://localhost:5173/_

Production Build

npm run build
  • Creates an optimized production build with SSR support_

Server-Side Rendering (SSR) Mode

npm run serve
  • Runs the production build with SSR for better SEO and faster initial loads_

Preview Build

npm run preview
  • Preview the production build locally_

Network Access - Run on your local network for testing on multiple devices_

npm run host

๐ŸŒ Deployment

Deploy to Vercel

The easiest way to deploy your Game Cave is using Vercel:

  1. One-Click Deploy:

    Deploy with Vercel

  2. Manual Deployment:

    # Install Vercel CLI
    npm i -g vercel
    
    # Deploy from the root directory
    cd multi-stage-react-project
    vercel
  3. GitHub Integration:

    • Connect your repository to Vercel
    • Automatic deployments on every push to main branch
    • Preview deployments for pull requests

Build Configuration

For Vercel deployment, make sure your build settings are:

  • Build Command: npm run build
  • Output Directory: dist
  • Install Command: npm install
  • Root Directory: multi-stage-react-project

Environment Variables

For enhanced AI-powered gameplay features, you'll need to set up the Gemini API key. While basic gameplay works without it, some games include AI-enhanced features that require this configuration.

  1. Create a .env file in the root directory:

    touch .env  # On Windows: type nul > .env
  2. Add the following variables:

    # Required for AI-powered game features
    VITE_GEMINI_API_KEY=your_gemini_api_key_here
  3. Get your Gemini API Key:

    • Visit Google AI Studio
    • Create a new API key
    • Replace your_gemini_api_key_here with your actual key
  4. For Vercel deployment:

    • Go to your Vercel project dashboard
    • Navigate to Settings > Environment Variables
    • Add VITE_GEMINI_API_KEY with your API key value

Important: Never commit your .env file to version control. The .env file is already included in .gitignore for your security.


๐Ÿณ Docker Deployment

Containerize Game Cave with Docker for consistent deployment across any environment! Perfect for development, testing, and production deployments.

๐Ÿ“‹ Prerequisites

Ensure Docker is installed on your system:

# Check if Docker is installed
docker --version

# Check if Docker Compose is available
docker compose version

Need Docker? Download from docker.com - Available for Windows, macOS, and Linux

๐Ÿš€ Quick Start with Docker

Method 1: Direct Docker Build & Run

  1. Navigate to the project directory:

    cd multi-stage-react-project
  2. Build the Docker image:

    # Basic build (without AI features)
    docker build -t game-cave:dev .
    
    # Build with Gemini API key for AI-powered features
    docker build --build-arg VITE_GEMINI_API_KEY=your_gemini_api_key_here -t game-cave:dev .

    Note: Using --build-arg VITE_GEMINI_API_KEY passes the API key as a build argument to enable AI-powered features in games like Hangman, Word Scramble, and Tic Tac Toe. Replace your_gemini_api_key_here with your actual Gemini API key from Google AI Studio.

  3. Verify the image was created:

    docker images | grep game-cave
  4. Run the container:

    # Run created docker image
    docker run -p 5173:5173 game-cave:dev
    
    # Run created docker image as background process
    docker run -d -p 5173:5173 game-cave:dev
    
    # Run created docker image with custome container name
    docker run -p 5173:5173 --name game-cave-dev game-cave:dev
  5. Access your games:

Method 2: Docker Compose (Recommended)

# Navigate to project directory
cd multi-stage-react-project

# Start the application with Docker Compose
docker compose up -d

# View logs
docker compose logs -f

# Stop the application
docker compose down

On the `docker` branch, Compose exposes Nginx on port 5173 by default for a static SPA build. On the `docker+ssr` branch, Compose starts both the SSR Node app and Nginx, with Nginx reverseโ€‘proxying traffic to the app (typically on port 3000) and serving static assets directly for optimal performance.

๐Ÿ› ๏ธ Docker Commands Cheat Sheet

Command Description
docker build -t game-cave:dev . Build development image
docker build --build-arg VITE_GEMINI_API_KEY=your_key -t game-cave:dev . Build with AI features
docker run -p 5173:5173 game-cave:dev Run dev container
docker run -p 5173:5173 game-cave:prod Run prod (Nginx static)
docker run -p 5173:5173 game-cave:ssr Run prod (Nginx + SSR)
docker ps List running containers
docker stop game-cave-dev Stop container
docker rm game-cave-dev Remove container
docker rmi game-cave:dev Remove image
docker logs game-cave-dev View container logs

๐Ÿ”ง Advanced Configuration

Environment Variables

# Run with custom environment variables
docker run -p 5173:5173 \
  -e NODE_ENV=development \
  -e VITE_API_URL=http://localhost:3000 \
  --name game-cave-dev \
  game-cave:dev

Volume Mounting for Development

# Mount source code for hot reload during development
docker run -p 5173:5173 \
  -v "$(pwd):/app" \
  -v /app/node_modules \
  --name game-cave-dev \
  game-cave:dev

Multi-Stage Production Build

# Example production Dockerfile (Dockerfile.prod)
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

FROM nginx:alpine AS production
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

For SSR, Nginx acts as a reverse proxy to the Node server and may also serve static assets directly. Example (simplified):

# Example nginx.conf (docker+ssr branch)
worker_processes auto;
events { worker_connections 1024; }
http {
   include       /etc/nginx/mime.types;
   sendfile      on;
   gzip          on;
   gzip_types    text/plain application/javascript text/css application/json image/svg+xml;

   upstream app {
      server 127.0.0.1:3000; # Node SSR server
   }

   server {
      listen 80;
      server_name _;

      # Serve built assets directly if desired
      location /assets/ {
         root /usr/share/nginx/html;
         access_log off;
         expires 1y;
         add_header Cache-Control "public, max-age=31536000, immutable";
      }

      # Proxy everything else to SSR
      location / {
         proxy_pass         http://app;
         proxy_http_version 1.1;
         proxy_set_header   Upgrade $http_upgrade;
         proxy_set_header   Connection "upgrade";
         proxy_set_header   Host $host;
         proxy_set_header   X-Forwarded-Proto $scheme;
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      }
   }
}

๐ŸŒ Network Access & Mobile Testing

# Run on all interfaces for network access
docker run -p 0.0.0.0:5173:5173 --name game-cave-dev game-cave:dev

# Find your IP address

# Windows PowerShell:
ipconfig | findstr IPv4

# macOS/Linux:
ifconfig | grep inet

Now you can test on mobile devices using http://your-ip:5173

For Nginx-based production images (docker or docker+ssr branches), map port 5173 and test via http://your-ip/.

๐Ÿ› Troubleshooting

Common Issues & Solutions

Issue Solution
Port already in use Use different port: -p 3000:5173
Permission denied Run with sudo (Linux/macOS) or check Docker Desktop (Windows)
Image not found Rebuild image: docker build -t game-cave:dev .
Container won't start Check logs: docker logs game-cave-dev

Clean Slate Reset

# Stop and remove all Game Cave containers
docker stop $(docker ps -q --filter ancestor=game-cave:dev)
docker rm $(docker ps -aq --filter ancestor=game-cave:dev)

# Remove all Game Cave images
docker rmi $(docker images game-cave -q)

# Clean up unused Docker resources
docker system prune -af

๐Ÿšข Production Deployment

Docker Hub Deployment

# Tag your image
docker tag game-cave:dev yourusername/game-cave:latest

# Push to Docker Hub
docker push yourusername/game-cave:latest

# Deploy anywhere
docker run -p 80:80 yourusername/game-cave:latest

Cloud Deployment Options

  • ๐ŸŒŠ DigitalOcean App Platform - One-click Docker deployment
  • โ˜๏ธ AWS ECS/Fargate - Scalable container orchestration
  • ๐Ÿ”ต Azure Container Instances - Serverless containers
  • ๐ŸŒ Google Cloud Run - Pay-per-use container platform

๐Ÿ“Š Container Health & Monitoring

# Monitor container resources
docker stats game-cave-dev

# Health check
docker exec game-cave-dev curl -f http://localhost:5173 || exit 1

# Container shell access
docker exec -it game-cave-dev sh

๐ŸŽฏ Why Docker for Game Cave?

  • โœ… Consistent Environment - Same setup across all machines
  • โœ… Quick Setup - Get running in minutes, not hours
  • โœ… Isolated Dependencies - No conflicts with system packages
  • โœ… Easy Cleanup - Remove everything with one command
  • โœ… Production Ready - Scale from dev to production seamlessly
  • โœ… Team Collaboration - Everyone runs the same environment

๐Ÿ› ๏ธ Tech Stack

Frontend Technologies

  • โš›๏ธ React 19 - Modern UI library with hooks and functional components
  • ๐Ÿ“˜ TypeScript - Type-safe JavaScript for better development experience
  • โšก Vite - Lightning-fast build tool and development server with SSR support
  • ๐ŸŽจ TailwindCSS - Utility-first CSS framework for rapid UI development
  • ๐Ÿ”ง ESLint - Code linting for maintaining code quality
  • ๐Ÿ”„ Express.js - Server-side rendering and API handling

AI & Intelligence

  • ๐Ÿค– Google Gemini AI - Advanced AI integration for enhanced gameplay features
  • ๐Ÿง  Smart Game Logic - AI-powered hints, difficulty adjustment, and content generation
  • ๐Ÿ“Š Intelligent Analytics - AI-driven performance insights and personalized recommendations

Deployment & DevOps

  • ๐Ÿณ Docker - Containerization for consistent deployments
  • ๐ŸŒ Vercel - Serverless deployment platform
  • โ˜๏ธ Multi-Cloud Ready - AWS, Azure, Google Cloud, DigitalOcean

๐ŸŒณ Development Branches

This repository contains multiple branches representing different development stages and feature implementations:

๐Ÿ“‹ Branch Overview

Branch Description Status Features
๐ŸŒŸ main Production-ready version โœ… Active Full game collection with modern React setup
๐Ÿณ docker Docker containerization โœ… Active Docker + Nginx static serving for production
๐Ÿ”„ SSR-Server-Side-Rendering Server-side rendering implementation โœ… Active Enhanced SEO and faster initial loads
๐Ÿš€ docker+ssr Combined SSR and Docker โœ… Active Nginx reverse proxy + Node SSR, optimized static asset handling

๐Ÿ”„ Branch Development Flow

graph LR
   A[main] --> B[docker]
   A --> C[SSR-Server-Side-Rendering]
   B --> D[docker+ssr]
   C --> D
Loading

๐ŸŽฏ Choosing the Right Branch

  • For basic development: Use main branch
  • For containerized deployment: Check out docker branch
  • For SEO optimization: Use SSR-Server-Side-Rendering branch
  • For production deployment: Use docker+ssr branch (recommended)

๐Ÿ”€ Switching Branches

# View all branches
git branch -a

# Switch to a specific branch
git checkout docker
git checkout SSR-Server-Side-Rendering
git checkout docker+ssr

# Return to main branch
git checkout main

๐Ÿš€ Branch-Specific Features

๐Ÿณ Docker Branch (with Nginx)

  • Complete Docker containerization
  • Multi-stage build process
  • Development and production Dockerfiles
  • Docker Compose configuration
  • Nginx serves optimized static build on port 80 with sensible cache headers

๐Ÿ”„ SSR Branch

  • Server-side rendering with Express.js
  • Enhanced SEO capabilities
  • Faster initial page loads
  • Better Core Web Vitals scores

๐Ÿš€ docker+ssr Branch (Nginx + SSR)

  • Combined benefits of SSR and Docker
  • Production-ready deployment
  • Scalable architecture
  • Cloud deployment optimized
  • Nginx reverse proxies to Node SSR and serves static assets directly when possible

Note: The Nginx configuration and Dockerfiles referenced above live in the respective branches (docker and docker+ssr). This main branch README documents how to use them.


๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch (git checkout -b feature/amazing-game)
  3. ๐Ÿ’ Commit your changes (git commit -m 'Add some amazing game')
  4. ๐Ÿ“ค Push to the branch (git push origin feature/amazing-game)
  5. ๐ŸŽ‰ Open a Pull Request

๐Ÿ“„ License

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


๐Ÿ™ Acknowledgments

  • ๐ŸŽฎ Inspired by classic arcade and casual games
  • โšก Built with modern web technologies for the best user experience
  • ๐Ÿค– Enhanced with Google Gemini AI for intelligent gameplay features
  • ๐ŸŒ Deployed on Vercel for blazing-fast global delivery
  • ๐Ÿ™ Thanks to all contributors who help make this project better!
  • ๐Ÿ’ก Special thanks to the React, TypeScript, Vite, and Google AI communities

๐Ÿ“Š Project Stats

  • ๐ŸŽฏ 12 Games implemented and ready to play
  • ๐Ÿค– AI-Enhanced - 5 games feature Google Gemini AI integration
  • ๐Ÿ“ฆ Lightweight Bundle - Optimized for fast loading
  • ๐ŸŒ Global CDN - Fast delivery worldwide via Vercel
  • ๐Ÿ“ฑ Mobile Optimized - Works perfectly on all devices
  • โšก < 3s Load Time - Lightning-fast performance
  • ๐Ÿณ Docker Ready - Container support for all environments
  • โ˜๏ธ Multi-Cloud - Deploy anywhere with Docker containers

โญ Don't forget to star this repository if you enjoyed the games! โญ

Made with โค๏ธ by Kevin Thulnith

About

Muti stage Vite | React | Tailwind project with docker ๐Ÿณ and SSR -> server side rendering ๐ŸŒ intergrated with Gemini โœจ by Google

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages