metadata
title: Crossword Puzzle Generator
emoji: π§©
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
Crossword Puzzle Generator
A full-stack web application that generates custom crossword puzzles based on selected topics using React frontend and Node.js backend.
Features
- Topic Selection: Choose from various categories (Animals, Science, Geography, Technology)
- Dynamic Grid Generation: Automatically creates crossword grids with word intersections
- Interactive Interface: Click-to-fill crossword grid with real-time validation
- Difficulty Levels: Easy, Medium, and Hard puzzle generation
- Responsive Design: Works on desktop and mobile devices
Tech Stack
Frontend
- React 18 with hooks and functional components
- Vite for fast development and building
- CSS Grid for puzzle layout
- Vanilla CSS for styling (no external UI libraries)
Backend
- Node.js with Express.js framework
- File-based word storage (JSON files by topic)
- CORS enabled for cross-origin requests
- Rate limiting for API protection
- Helmet for security headers
Database (Optional)
- PostgreSQL schema included for advanced features
- Migration and seed scripts provided
- Currently uses JSON files for simplicity
Project Structure
crossword-app/
βββ frontend/ # React frontend application
β βββ src/
β β βββ components/ # React components
β β β βββ TopicSelector.jsx
β β β βββ PuzzleGrid.jsx
β β β βββ ClueList.jsx
β β β βββ LoadingSpinner.jsx
β β βββ hooks/ # Custom React hooks
β β β βββ useCrossword.js
β β βββ utils/ # Utility functions
β β β βββ gridHelpers.js
β β βββ styles/ # CSS styling
β β β βββ puzzle.css
β β βββ App.jsx # Main app component
β β βββ main.jsx # React entry point
β βββ public/ # Static assets
β βββ package.json
β βββ vite.config.js
βββ backend/ # Node.js backend API
β βββ src/
β β βββ controllers/ # Request handlers
β β β βββ puzzleController.js
β β βββ services/ # Business logic
β β β βββ crosswordGenerator.js
β β β βββ wordService.js
β β βββ models/ # Data models
β β β βββ Word.js
β β β βββ Topic.js
β β βββ routes/ # API routes
β β β βββ api.js
β β βββ app.js # Express application
β βββ data/
β β βββ word-lists/ # JSON word files by topic
β βββ package.json
β βββ .env # Environment variables
βββ database/ # Database schema (optional)
βββ migrations/
βββ seeds/
Getting Started
Prerequisites
- Node.js 18+ and npm 9+
- PostgreSQL (optional, for advanced features)
Installation
Clone the repository
git clone <repository-url> cd crossword-app
Install backend dependencies
cd backend npm install
Install frontend dependencies
cd ../frontend npm install
Configure environment variables
cd ../backend cp .env.example .env # Edit .env with your configuration
Development
Start the backend server
cd backend npm run dev
Backend runs on http://localhost:3000
Start the frontend development server
cd frontend npm run dev
Frontend runs on http://localhost:5173
Access the application Open http://localhost:5173 in your browser
API Endpoints
GET /api/topics
- Get available topicsPOST /api/generate
- Generate a crossword puzzlePOST /api/validate
- Validate user answersGET /api/words/:topic
- Get words for a topic (admin)GET /api/health
- Health check
Example API Usage
Generate a puzzle:
curl -X POST http://localhost:3000/api/generate \
-H "Content-Type: application/json" \
-d '{
"topics": ["animals", "science"],
"difficulty": "medium"
}'
Algorithm Details
Crossword Generation Process
- Word Selection: Picks 6-12 words from selected topics based on difficulty
- Grid Sizing: Automatically calculates optimal grid size
- Placement Algorithm: Uses backtracking to place words with intersections
- Validation: Ensures valid crossword structure with proper letter matching
Core Algorithm Features
- Backtracking: Tries all possible word placements and backtracks on conflicts
- Intersection Logic: Words can only cross where letters match
- Grid Optimization: Minimizes grid size while maximizing word density
- Difficulty Scaling: Adjusts word length and complexity based on difficulty
Deployment
Docker (Hugging Face Spaces/Local)
Build and run locally:
# Build the Docker image
docker build -t crossword-app .
# Run the container (production mode)
docker run -p 7860:7860 -e NODE_ENV=production crossword-app
# Or run in background
docker run -d -p 7860:7860 -e NODE_ENV=production --name crossword-app crossword-app
Test the deployment:
# Test API endpoint
curl http://localhost:7860/api/topics
# Test frontend (should return HTML)
curl http://localhost:7860/
# View container logs
docker logs crossword-app
# Stop and cleanup
docker stop crossword-app && docker rm crossword-app
The app will be available at http://localhost:7860
For Hugging Face Spaces:
- Create a new Space with "Docker" SDK
- Upload the entire
crossword-app/
directory - The container will build automatically and deploy on port 7860
Frontend (Vercel/Netlify)
cd frontend
npm run build
# Deploy dist/ folder to your hosting service
Backend (Railway/Heroku)
cd backend
# Set environment variables in your hosting service
# Deploy with git or Docker
Environment Variables for Production
NODE_ENV=production
PORT=7860
DATABASE_URL=postgresql://user:pass@host:port/db (optional)
CORS_ORIGIN=https://your-frontend-domain.com (for separate deployments)
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Future Enhancements
- User accounts and saved puzzles
- Puzzle sharing and social features
- Advanced word filtering and custom topics
- Print-friendly puzzle format
- Mobile app versions
- Multiplayer crossword solving
- AI-generated clues
License
This project is licensed under the MIT License - see the LICENSE file for details.