Spaces:
Build error

WordGame / REFACTOR_GUIDE.md
0Mart00
Verbumix rebrand: emojis removed, multi-jurisdictional legal docs, cookie consent, footer links
9d4e305
|
Raw History Blame Contribute Delete
3.7 kB
# 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.