# WordGame Refactoring Guide ## New Project Structure The project has been refactored to a modern, scalable structure following Python best practices: ``` wordGame/ ├── src/ │ └── wordgame/ │ ├── __init__.py # Package initialization │ ├── main.py # FastAPI application entry point │ │ │ ├── core/ # Core module │ │ ├── __init__.py │ │ ├── config.py # Configuration management (pydantic-settings) │ │ └── database.py # Supabase client initialization │ │ │ ├── api/ # API layer │ │ ├── __init__.py │ │ ├── router.py # Main router aggregation │ │ └── routes/ # Route modules │ │ ├── __init__.py │ │ ├── game_routes.py # Main game logic │ │ ├── auth_routes.py # Authentication │ │ ├── room_routes.py # Multiplayer rooms │ │ ├── slang_routes.py # Slang word import │ │ ├── paddle_routes.py # Payment webhooks │ │ └── dashboard_routes.py # User dashboard │ │ │ └── features/ # Feature modules (optional, for complex features) │ └── user_dashboard/ # Example feature module │ ├── __init__.py │ ├── services/ │ ├── repositories/ │ ├── schemas/ │ ├── utils/ │ └── templates/ │ ├── templates/ # HTML templates ├── static/ # Static assets (CSS, JS, images) │ ├── .env.example # Environment variables template ├── .gitignore # Git ignore rules ├── requirements.txt # Python dependencies ├── README.md # Project documentation └── REFACTOR_GUIDE.md # This file ``` ## Key Changes ### 1. Source Layout (`src/`) - All Python code is now in `src/wordgame/` - Prevents import conflicts and follows modern Python packaging ### 2. Configuration Management - Uses `pydantic-settings` for environment-based configuration - All settings in `.env` file (copy from `.env.example`) - Type-safe configuration with validation ### 3. Modular Routes - Each feature has its own route module - Routes are aggregated in `api/router.py` - Easy to add/remove features ### 4. Separation of Concerns - `core/` - Configuration and database - `api/` - HTTP routes and request handling - `features/` - Complex feature modules (optional) ## Setup Instructions 1. **Install dependencies:** ```bash pip install -r requirements.txt ``` 2. **Configure environment:** ```bash cp .env.example .env # Edit .env with your Supabase credentials ``` 3. **Run the application:** ```bash # From project root python -m src.wordgame.main # Or with uvicorn uvicorn src.wordgame.main:app --reload ``` ## Benefits - **Scalable** - Easy to add new features - **Maintainable** - Clear separation of concerns - **Testable** - Each module can be tested independently - **Type-safe** - Full type hints and pydantic validation - **Modern** - Follows current Python best practices ## Migration Notes The old files (`main.py`, `database.py`, `room.py`, etc.) in the root directory are kept for reference but are no longer used. The new structure in `src/` is the authoritative codebase.