File size: 3,703 Bytes
d2f5a24 9d4e305 d2f5a24 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | # 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. |