A modern web-based civilization game built with TypeScript, React, and Node.js. This project ports the freeciv-web 2D client with a modern React architecture while maintaining compatibility with civilization game mechanics.
This is a monorepo containing:
apps/client
- React/TypeScript frontend with Canvas 2D renderingapps/server
- Node.js/Socket.IO backend with PostgreSQL and Redis
- Node.js 20+
- Docker & Docker Compose
- Git
-
Clone the repository
git clone git@github.com:michaelchu/civjs.git cd civjs
-
Install dependencies
npm install
-
Start with Docker (recommended)
npm run docker:build
-
Or start locally
# Start both client and server npm run dev # Or start individually npm run dev:client # http://localhost:3000 npm run dev:server # http://localhost:3001
The project includes a complete Docker setup with:
- Frontend: React app on port 3000
- Backend: Node.js server on port 3001
- Database: PostgreSQL on port 5432
- Cache: Redis on port 6379
# Start all services
docker-compose up --build
# Stop all services
docker-compose down
civjs/
โโโ apps/
โ โโโ client/ # React frontend
โ โ โโโ src/
โ โ โ โโโ components/ # React components
โ โ โ โโโ services/ # API clients
โ โ โ โโโ store/ # State management (Zustand)
โ โ โ โโโ types/ # Local type definitions
โ โ โโโ Dockerfile.dev
โ โ โโโ package.json
โ โโโ server/ # Node.js backend
โ โโโ src/
โ โ โโโ game/ # Game logic managers
โ โ โโโ network/ # Socket.IO handlers
โ โ โโโ database/ # PostgreSQL & Redis
โ โ โโโ types/ # Server type definitions
โ โโโ Dockerfile
โ โโโ package.json
โโโ docker-compose.yml # Multi-container setup
โโโ package.json # Root scripts and dev dependencies
- Modern React Architecture - React 19 with TypeScript
- Canvas 2D Rendering - Ported from freeciv-web with HTML5 Canvas
- Real-time Communication - Socket.IO for live multiplayer
- State Management - Zustand for client-side game state
- Modern UI - Tailwind CSS with responsive design
- Hot Reload - Vite development server
- Socket.IO Server - Real-time multiplayer communication
- PostgreSQL Database - Game state persistence with Drizzle ORM
- Redis Cache - Session management and caching
- Game Managers - Modular game logic (Cities, Units, Turn, etc.)
- TypeScript - Fully typed server implementation
- Code Quality - ESLint, Prettier, and comprehensive testing setup
- Type Safety - Full TypeScript coverage across client and server
- Hot Reload - Fast development with Vite and nodemon
# Development
npm run dev # Start both client and server
npm run dev:client # Start only frontend
npm run dev:server # Start only backend
# Building
npm run build # Build all packages
npm run build:client # Build frontend only
npm run build:server # Build backend only
# Testing
npm run test # Run all tests
npm run test:client # Test frontend only
npm run test:server # Test backend only
# Code Quality
npm run lint # Lint all packages
npm run lint:fix # Fix linting issues
npm run typecheck # Type checking
# Docker
npm run docker:build # Build and start containers
npm run docker:up # Start existing containers
npm run docker:down # Stop all containers
# Utilities
npm run clean # Clean all build artifacts
# Add to client
cd apps/client && npm install <package>
# Add to server
cd apps/server && npm install <package>
# Add to both client and server
cd apps/client && npm install <package> && cd ../server && npm install <package>
# Add to root (dev dependencies)
npm install <package> --save-dev
- Frontend: React 19, TypeScript, Vite, Tailwind CSS, Zustand, Socket.IO Client
- Backend: Node.js, TypeScript, Socket.IO, Express, Drizzle ORM
- Database: PostgreSQL 16, Redis 7
- DevOps: Docker, Docker Compose
- Tools: ESLint, Prettier, Jest, Vitest
Create .env
files in respective apps:
apps/server/.env
NODE_ENV=development
PORT=3001
DATABASE_URL=postgresql://civjs:civjs_secret@localhost:5432/civjs
REDIS_URL=redis://localhost:6379
SOCKET_CORS_ORIGIN=http://localhost:3000
apps/client/.env
VITE_SERVER_URL=http://localhost:3001
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature
- Commit changes:
git commit -m 'Add my feature'
- Push to branch:
git push origin feature/my-feature
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Freeciv Project - Original civilization game implementation
- Freeciv-web - Web client implementation that inspired this port
- Civilization Series - Game mechanics and design inspiration
For questions, issues, or contributions:
- Open an issue on GitHub
- Check the documentation
- Review existing discussions and PRs
Built with โค๏ธ using modern web technologies# Test change for Husky