File size: 6,062 Bytes
5f3e9f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# Migration Guide - Old to New Structure

This document explains the changes from the old structure to the new organized structure.

## Structure Changes

### Old Structure
```
project/
β”œβ”€β”€ ai_client.py
β”œβ”€β”€ app.py
β”œβ”€β”€ config.py
β”œβ”€β”€ html_generator.py
β”œβ”€β”€ screenshot_playwright.py
β”œβ”€β”€ system_prompt.txt
β”œβ”€β”€ template.html
β”œβ”€β”€ templates/index.html
β”œβ”€β”€ generated_html/
└── screenshots/
```

### New Structure
```
project/
β”œβ”€β”€ app.py                      # Updated with new imports
β”œβ”€β”€ start.py                    # New startup script
β”œβ”€β”€ requirements.txt            # Updated dependencies
β”œβ”€β”€ README.md                   # Comprehensive documentation
β”œβ”€β”€ SETUP_GUIDE.md             # Setup instructions
β”‚
β”œβ”€β”€ src/                        # NEW: Source code organization
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ ai_client.py       # Moved from root
β”‚   β”‚   └── html_generator.py  # Moved from root
β”‚   └── screenshot_engines/
β”‚       └── playwright_engine.py # Renamed from screenshot_playwright.py
β”‚
β”œβ”€β”€ config/                     # NEW: Configuration folder
β”‚   β”œβ”€β”€ config.py              # Moved from root
β”‚   β”œβ”€β”€ config.example.py      # NEW: Template
β”‚   β”œβ”€β”€ system_prompt.txt      # Moved from root
β”‚   └── template.html          # Moved from root
β”‚
β”œβ”€β”€ static/                     # Frontend assets
β”‚   β”œβ”€β”€ css/styles.css         # NEW: Extracted from index.html
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ navigation.js      # NEW: Extracted from index.html
β”‚   β”‚   β”œβ”€β”€ text-to-image.js   # NEW: Extracted from index.html
β”‚   β”‚   β”œβ”€β”€ html-to-image.js   # NEW: Extracted from index.html
β”‚   β”‚   └── utils.js           # NEW: Extracted from index.html
β”‚   └── README.md              # NEW: Frontend documentation
β”‚
β”œβ”€β”€ templates/
β”‚   └── index.html             # Refactored to use external CSS/JS
β”‚
└── output/                     # NEW: Organized output
    β”œβ”€β”€ screenshots/           # Replaces root screenshots/
    └── html/                  # Replaces generated_html/
```

## Import Changes

### Old Imports (app.py)
```python
from ai_client import get_ai_response
from html_generator import generate_html
from screenshot_playwright import take_screenshot_playwright
```

### New Imports (app.py)
```python
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

from core.ai_client import get_ai_response
from core.html_generator import generate_html
from screenshot_engines.playwright_engine import take_screenshot_playwright
```

## Path Changes

### Output Folders

**Old:**
```python
OUTPUT_FOLDER = "screenshots"
HTML_FOLDER = "generated_html"
```

**New:**
```python
OUTPUT_FOLDER = "output/screenshots"
HTML_FOLDER = "output/html"
```

### Config Files

**Old:**
```python
# Direct import
import config
```

**New:**
```python
# Import from config folder
sys.path.insert(0, 'config')
import config
```

## Migration Steps

### Automatic Migration (Recommended)

The new structure is already set up. Old files remain for reference.

### Manual Migration (If needed)

1. **Move core files:**
   ```bash
   mkdir -p src/core
   cp ai_client.py src/core/
   cp html_generator.py src/core/
   ```

2. **Move screenshot engine:**
   ```bash
   mkdir -p src/screenshot_engines
   cp screenshot_playwright.py src/screenshot_engines/playwright_engine.py
   ```

3. **Move config files:**
   ```bash
   mkdir -p config
   cp config.py config/
   cp system_prompt.txt config/
   cp template.html config/
   ```

4. **Create output folders:**
   ```bash
   mkdir -p output/screenshots output/html
   ```

5. **Update app.py** with new imports (already done)

6. **Test the application:**
   ```bash
   python start.py
   ```

## Backward Compatibility

### Old Files

Old files are kept in the root for reference:
- `ai_client.py` (use `src/core/ai_client.py`)
- `html_generator.py` (use `src/core/html_generator.py`)
- `screenshot_playwright.py` (use `src/screenshot_engines/playwright_engine.py`)
- `config.py` (use `config/config.py`)

### Old Output Folders

Old output folders still work:
- `screenshots/` (use `output/screenshots/`)
- `generated_html/` (use `output/html/`)

You can safely delete old files after verifying the new structure works.

## Benefits of New Structure

### Organization
- βœ… Clear separation of concerns
- βœ… Modular code structure
- βœ… Easy to navigate

### Scalability
- βœ… Easy to add new tools
- βœ… Easy to add new screenshot engines
- βœ… Easy to add new features

### Maintainability
- βœ… Easier to find files
- βœ… Easier to update code
- βœ… Easier to debug

### Professional
- βœ… Industry-standard structure
- βœ… Better for collaboration
- βœ… Better for version control

## Cleanup (Optional)

After verifying everything works, you can remove old files:

```bash
# Remove old Python files (keep as backup first!)
# rm ai_client.py
# rm html_generator.py
# rm screenshot_playwright.py
# rm config.py
# rm system_prompt.txt
# rm template.html

# Remove old test files
rm test_*.py
rm check_*.py
rm list_models.py
rm main.py
rm css_template.txt

# Move old output (optional)
# mv screenshots/* output/screenshots/
# mv generated_html/* output/html/
# rmdir screenshots generated_html
```

## Rollback (If needed)

If you need to go back to the old structure:

1. The old files are still in the root directory
2. Revert `app.py` to use old imports
3. Use old output folders

## Testing Checklist

After migration, test:

- [ ] Server starts without errors
- [ ] Text to Image tool works
- [ ] HTML to Image tool works
- [ ] Screenshots are generated
- [ ] HTML files are saved
- [ ] Custom settings work
- [ ] Advanced settings work
- [ ] File serving works

## Questions?

If you encounter issues:
1. Check terminal for error messages
2. Verify all files are in correct locations
3. Check imports in `app.py`
4. Review `SETUP_GUIDE.md`