Spaces:
Build error

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.