File size: 5,560 Bytes
7aae924
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# πŸš€ SmartEyeSsen Backend μ„€μ • κ°€μ΄λ“œ

νŒ€μ›μ„ μœ„ν•œ 개발 ν™˜κ²½ μ„€μ • κ°€μ΄λ“œμž…λ‹ˆλ‹€.

---

## πŸ“‹ **λͺ©μ°¨**

1. [μ‹œμŠ€ν…œ μš”κ΅¬μ‚¬ν•­](#1-μ‹œμŠ€ν…œ-μš”κ΅¬μ‚¬ν•­)
2. [MySQL μ„€μΉ˜ 및 μ„€μ •](#2-mysql-μ„€μΉ˜-및-μ„€μ •)
3. [ν”„λ‘œμ νŠΈ 클둠 및 μ„€μ •](#3-ν”„λ‘œμ νŠΈ-클둠-및-μ„€μ •)
4. [λ°μ΄ν„°λ² μ΄μŠ€ 생성](#4-λ°μ΄ν„°λ² μ΄μŠ€-생성)
5. [Python ν™˜κ²½ μ„€μ •](#5-python-ν™˜κ²½-μ„€μ •)
6. [μ„œλ²„ μ‹€ν–‰](#6-μ„œλ²„-μ‹€ν–‰)
7. [νŠΈλŸ¬λΈ”μŠˆνŒ…](#7-νŠΈλŸ¬λΈ”μŠˆνŒ…)

---

## **1. μ‹œμŠ€ν…œ μš”κ΅¬μ‚¬ν•­**

### **ν•„μˆ˜ ν”„λ‘œκ·Έλž¨**

- Python 3.9 이상
- MySQL 8.0 이상
- Git

### **μš΄μ˜μ²΄μ œλ³„ 지원**

- βœ… Windows 10/11
- βœ… Windows + WSL2 (Ubuntu 20.04/22.04)
- βœ… macOS
- βœ… Linux (Ubuntu/Debian)

---

## **2. MySQL μ„€μΉ˜ 및 μ„€μ •**

#### **MySQL μ„œλΉ„μŠ€ μ‹œμž‘**

```powershell
# PowerShell (κ΄€λ¦¬μž κΆŒν•œ)
Start-Service MySQL80
```

#### **MySQL 접속 ν…ŒμŠ€νŠΈ**

```powershell
mysql -u root -p
# λΉ„λ°€λ²ˆν˜Έ μž…λ ₯ ν›„ μ ‘μ†λ˜λ©΄ 성곡
```

---

### **2-2. Windows + WSL2 (Ubuntu)**

#### **WSL2 μ„€μΉ˜ (처음 μ‚¬μš©ν•˜λŠ” 경우)**

```powershell
# PowerShell (κ΄€λ¦¬μž κΆŒν•œ)
wsl --install -d Ubuntu-22.04
```

μž¬λΆ€νŒ… ν›„ Ubuntu μ‚¬μš©μžλͺ…/λΉ„λ°€λ²ˆν˜Έ μ„€μ •

#### **MySQL μ„€μΉ˜ (WSL λ‚΄λΆ€)**

```bash
# WSL Ubuntu 터미널
sudo apt update
sudo apt install mysql-server -y

# MySQL μ„œλΉ„μŠ€ μ‹œμž‘
sudo service mysql start

# Root λΉ„λ°€λ²ˆν˜Έ μ„€μ •
sudo mysql
```

```sql
-- MySQL μ½˜μ†”μ—μ„œ
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
FLUSH PRIVILEGES;
EXIT;
```

#### **MySQL 접속 ν…ŒμŠ€νŠΈ**

```bash
mysql -u root -p
# λΉ„λ°€λ²ˆν˜Έ μž…λ ₯ ν›„ μ ‘μ†λ˜λ©΄ 성곡
```

---

## **3. ν”„λ‘œμ νŠΈ 클둠 및 μ„€μ •**

### **3-2. ν™˜κ²½ λ³€μˆ˜ μ„€μ •**

```bash
# .env 파일 생성 (Backend 폴더 λ‚΄)
cd Backend
cp .env.example .env
```

#### **`.env` 파일 μˆ˜μ •**

ν…μŠ€νŠΈ μ—λ””ν„°λ‘œ `.env` νŒŒμΌμ„ μ—΄κ³  λ‹€μŒ ν•­λͺ©μ„ μˆ˜μ •:

```ini
# λ°μ΄ν„°λ² μ΄μŠ€ μ„€μ •
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_actual_password  # ⚠️ 여기에 μ‹€μ œ MySQL λΉ„λ°€λ²ˆν˜Έ μž…λ ₯
DB_NAME=smarteyessen_db

# OpenAI API
OPENAI_API_KEY=  # 이건 바꿔야돼!

# μ„œλ²„ μ„€μ •
API_HOST=0.0.0.0
API_PORT=8000
```

---

## **4. λ°μ΄ν„°λ² μ΄μŠ€ 생성**

### **4-1. μŠ€ν‚€λ§ˆ 적용 (λ°μ΄ν„°λ² μ΄μŠ€ μžλ™ 생성)**

`erd_schema.sql` νŒŒμΌμ—λŠ” λ°μ΄ν„°λ² μ΄μŠ€ 생성뢀터 ν…Œμ΄λΈ” 생성, 초기 데이터 μ‚½μž…κΉŒμ§€ λͺ¨λ“  μž‘μ—…μ΄ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

```bash
# ν”„λ‘œμ νŠΈ 루트 λ””λ ‰ν† λ¦¬μ—μ„œ μ‹€ν–‰
# (SmartEye-FrontWeb 폴더)
mysql -u root -p < Project/DB/erd_schema.sql
```

### **4-4. ν…Œμ΄λΈ” 생성 확인**

```bash
mysql -u root -p smarteyessen_db
```

```sql
-- 12개 ν…Œμ΄λΈ” 확인
SHOW TABLES;

-- μ˜ˆμƒ κ²°κ³Ό:
-- +------------------------------+
-- | Tables_in_smarteyessen_db    |
-- +------------------------------+
-- | ai_descriptions              |
-- | combined_results             |
-- | document_types               |
-- | formatting_rules             |
-- | layout_elements              |
-- | pages                        |
-- | projects                     |
-- | question_elements            |
-- | question_groups              |
-- | text_contents                |
-- | text_versions                |
-- | users                        |
-- +------------------------------+

-- 초기 데이터 확인
SELECT * FROM document_types;
-- 2개 행이 μ‘°νšŒλ˜μ–΄μ•Ό 함 (worksheet, document)

EXIT;
```

---

````

### **5-2. μ˜μ‘΄μ„± μ„€μΉ˜**

```bash
# Backend ν΄λ”λ‘œ 이동
cd Backend

# νŒ¨ν‚€μ§€ μ„€μΉ˜
pip install -r requirements.txt
````

---

## **6. μ„œλ²„ μ‹€ν–‰**

### **6-1. μ„œλ²„ μ‹œμž‘**

#### **Windows (PowerShell) κ΄€ν•™ μ‹€ν–‰ 방법**

```powershell
# pytorch ν™˜κ²½ ν™œμ„±ν™”
conda activate pytorch

# Backend ν΄λ”λ‘œ 이동
cd Backend

# μ„œλ²„ μ‹€ν–‰
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```

#### **WSL/macOS/Linux μ’…μ˜ 싀행방법**

# Backend ν΄λ”λ‘œ 이동

cd Backend

# μ„œλ²„ μ‹€ν–‰

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

```

### **6-2. μ„œλ²„ μ‹€ν–‰ 확인**

λ‹€μŒκ³Ό 같은 좜λ ₯이 λ‚˜νƒ€λ‚˜λ©΄ 성곡:

```

INFO: Will watch for changes in these directories: ['C:\\git\\Smart-Eye-OCR\\SmartEye-FrontWeb\\Backend']
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [12345] using WatchFiles
INFO: Started server process [67890]
INFO: Waiting for application startup.
============================================================
πŸš€ SmartEyeSsen Backend Starting...
============================================================
βœ… Database connection successful!
βœ… Database connection successful
βœ… Database tables created successfully!
βœ… Database tables initialized
============================================================
βœ… SmartEyeSsen Backend Ready!
πŸ“– API Docs: http://localhost:8000/docs
============================================================
INFO: Application startup complete.

````

### **6-3. API λ¬Έμ„œ 접속**

λΈŒλΌμš°μ €μ—μ„œ λ‹€μŒ URL둜 접속:

- 🏠 **메인**: http://localhost:8000
- πŸ“– **API λ¬Έμ„œ (Swagger UI)**: http://localhost:8000/docs
- πŸ“š **API λ¬Έμ„œ (ReDoc)**: http://localhost:8000/redoc
- ❀️ **ν—¬μŠ€ 체크**: http://localhost:8000/health

**ν—¬μŠ€ 체크 응닡 μ˜ˆμ‹œ:**

```json
{
  "status": "healthy",
  "message": "SmartEyeSsen Backend is running",
  "database": "connected",
  "timestamp": "2025-01-22T15:30:00.123456"
}
````