# Know Foolery ๐ŸŽฏ A web-based quiz game inspired by the French game "Dรฉconnaissance" where players test their knowledge across various themes and compete for the highest score. ## ๐ŸŽฎ Game Features - **Multi-themed Questions**: Questions across Geography, Science, History, Literature, Movies, Sports, Music, and Art - **Scoring System**: 2 points for correct answers without hints, 1 point with hints - **Attempts**: Up to 3 attempts per question - **Time Limit**: 30-minute game sessions - **Leaderboard**: Top 10 players displayed - **Admin Panel**: Secure question management with OAuth ## ๐Ÿ— Architecture ### Frontend (React + TypeScript) - **React 18** with TypeScript - **Material-UI (MUI)** for components - **Vite** for build tooling - **Zustand** for state management - **React Query** for server state ### Backend (Python Microservices) - **FastAPI** microservices architecture - **SQLAlchemy** ORM with SQLite database - **JWT** authentication for admin - **Docker** containerization - **Nginx** reverse proxy ### Services - `api-gateway` - Main API gateway (Port 8000) - `game-service` - Game logic and scoring (Port 8001) - `question-service` - Question management (Port 8002) - `player-service` - Player management (Port 8003) - `admin-service` - Administration panel (Port 8004) ## ๐Ÿš€ Quick Start ### Prerequisites - Docker and Docker Compose - Node.js 18+ (for local development) - Python 3.11+ (for local development) ### Development Setup 1. **Clone and setup**: ```bash git clone cd know_foolery cp .env.example .env ``` 2. **Start with Docker**: ```bash docker compose up --build ``` 3. **Initialize database**: ```bash docker compose exec game-service python /app/shared/database/init_db.py ``` 4. **Access the application**: - Frontend: http://localhost:3000 - API Gateway: http://localhost:8000 - API Docs: http://localhost:8000/docs ### Local Development **Frontend**: ```bash cd frontend npm install npm run dev ``` **Backend Services**: ```bash cd backend pip install -r requirements.txt # Run individual services cd services/api-gateway uvicorn app.main:app --reload --port 8000 cd services/game-service uvicorn app.main:app --reload --port 8001 # ... repeat for other services ``` ## ๐Ÿ“Š Database Schema ### Tables - `themes` - Question categories - `questions` - Quiz questions with hints and answers - `players` - Player information - `game_sessions` - Individual game sessions - `game_answers` - Player answers and attempts ### Sample Data The database comes pre-loaded with: - 8 themes (Geography, Science, History, etc.) - 40+ sample questions across all themes - Varying difficulty levels (1-4) ## ๐ŸŽฏ Game Flow 1. Player enters name on home page 2. Game session starts (30-minute timer) 3. Random question presented with theme 4. Player can submit answer (up to 3 attempts) or use hint 5. Scoring applied based on correctness and hint usage 6. Next question or game end 7. Final score saved to leaderboard ## ๐Ÿ”’ Admin Features - **Authentication**: OAuth integration (Auth0/Firebase) - **Question Management**: Add, edit, delete questions - **Theme Management**: Manage question categories - **Analytics**: Player performance and question difficulty analysis - **Bulk Import**: CSV/JSON question import capability ## ๐Ÿ›  Development Commands ### Frontend ```bash npm run dev # Start development server npm run build # Build for production npm run lint # Run ESLint npm run preview # Preview production build ``` ### Backend ```bash # Database operations python backend/shared/database/init_db.py # Initialize database # Testing pytest backend/ # Run tests # Code formatting black backend/ # Format Python code isort backend/ # Sort imports flake8 backend/ # Lint Python code ``` ### Docker ```bash docker compose up --build # Build and start all services docker compose up -d # Start in background docker compose down # Stop all services docker compose logs -f [service-name] # View logs ``` ## ๐Ÿ“ Project Structure ``` know_foolery/ โ”œโ”€โ”€ frontend/ # React TypeScript app โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”‚ โ”œโ”€โ”€ components/ # React components โ”‚ โ”‚ โ”œโ”€โ”€ pages/ # Page components โ”‚ โ”‚ โ”œโ”€โ”€ types/ # TypeScript types โ”‚ โ”‚ โ””โ”€โ”€ services/ # API services โ”‚ โ””โ”€โ”€ package.json โ”œโ”€โ”€ backend/ โ”‚ โ”œโ”€โ”€ shared/ # Common utilities โ”‚ โ”‚ โ”œโ”€โ”€ database/ # Database models & connection โ”‚ โ”‚ โ”œโ”€โ”€ auth/ # Authentication utilities โ”‚ โ”‚ โ””โ”€โ”€ utils/ # Shared utilities โ”‚ โ”œโ”€โ”€ services/ # Microservices โ”‚ โ”‚ โ”œโ”€โ”€ api-gateway/ # Main API gateway โ”‚ โ”‚ โ”œโ”€โ”€ game-service/ # Game logic โ”‚ โ”‚ โ”œโ”€โ”€ question-service/ # Question management โ”‚ โ”‚ โ”œโ”€โ”€ player-service/ # Player management โ”‚ โ”‚ โ””โ”€โ”€ admin-service/ # Admin operations โ”‚ โ””โ”€โ”€ database/ โ”‚ โ”œโ”€โ”€ schema.sql # Database schema โ”‚ โ””โ”€โ”€ seeds/ # Sample data โ”œโ”€โ”€ docker compose.yml # Container orchestration โ”œโ”€โ”€ nginx.conf # Reverse proxy config โ””โ”€โ”€ README.md ``` ## ๐Ÿ”ง Configuration ### Environment Variables Copy `.env.example` to `.env` and configure: - `DATABASE_URL` - Database connection string - `JWT_SECRET_KEY` - JWT signing key (change in production!) - `OAUTH_*` - OAuth provider configuration - Service URLs and ports - Game configuration (timeouts, scoring) ### Game Configuration - **Max session duration**: 30 minutes (1800 seconds) - **Question timeout**: 2 minutes (120 seconds) - **Max attempts per question**: 3 - **Base scoring**: 2 points (no hint), 1 point (with hint) - **Consecutive bonus**: 1.1x multiplier per consecutive correct answer ## ๐Ÿš€ Deployment ### Production Deployment 1. Set environment variables for production 2. Change `JWT_SECRET_KEY` to a secure value 3. Configure OAuth provider 4. Use production Docker Compose profile: ```bash docker compose --profile production up -d ``` ### Scaling Considerations - Use PostgreSQL instead of SQLite for production - Add Redis for caching and sessions - Configure load balancing with multiple service instances - Use external OAuth provider (Auth0, Firebase Auth) - Implement logging and monitoring ## ๐Ÿค Contributing 1. Fork the repository 2. Create a feature branch: `git checkout -b feature/amazing-feature` 3. Make your changes 4. Run tests: `pytest backend/ && npm test --prefix frontend` 5. Commit changes: `git commit -m 'Add amazing feature'` 6. Push to branch: `git push origin feature/amazing-feature` 7. Open a Pull Request ## ๐Ÿ“ License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Acknowledgments - Inspired by the French game "Dรฉconnaissance" - Built with modern web technologies and best practices - Sample questions curated for educational entertainment