-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_project.sh
executable file
·445 lines (373 loc) · 12 KB
/
setup_project.sh
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/bin/bash
# 脚本:setup_project.sh
# 用于自动生成 CheckEasyBackend 项目的完整目录结构及所有基础文件
# 创建项目主目录
mkdir -p CheckEasyBackend
cd CheckEasyBackend || exit
# 1. app 目录结构及文件
## app/api/
mkdir -p app/api
echo "# File: CheckEasyBackend/app/api/__init__.py" > app/api/__init__.py
cat <<'EOF' > app/api/api_v1.py
# File: CheckEasyBackend/app/api/api_v1.py
from fastapi import APIRouter
router = APIRouter()
# 示例路由:状态检测接口
@router.get("/status")
def get_status():
return {"status": "API is running"}
EOF
## app/core/
mkdir -p app/core
echo "# File: CheckEasyBackend/app/core/__init__.py" > app/core/__init__.py
cat <<'EOF' > app/core/config.py
# File: CheckEasyBackend/app/core/config.py
import os
from dotenv import load_dotenv
# 加载 .env 环境变量文件
load_dotenv()
class Settings:
DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite:///./test.db")
# 可扩展:OAuth、邮件服务等全局配置
settings = Settings()
EOF
# 生成其他常见核心文件(可按需扩展)
cat <<'EOF' > app/core/db.py
# File: CheckEasyBackend/app/core/db.py
# 数据库连接管理示例
from app.core.config import settings
import sqlalchemy
engine = sqlalchemy.create_engine(settings.DATABASE_URL)
EOF
cat <<'EOF' > app/core/security.py
# File: CheckEasyBackend/app/core/security.py
# 安全模块(JWT、密码加密等)的示例代码
def verify_password(plain_password: str, hashed_password: str) -> bool:
# 密码验证逻辑
return plain_password == hashed_password
EOF
cat <<'EOF' > app/core/oauth.py
# File: CheckEasyBackend/app/core/oauth.py
# OAuth 配置及工具函数示例
def oauth_config():
return {"provider": "Google", "client_id": "YOUR_CLIENT_ID"}
EOF
cat <<'EOF' > app/core/email.py
# File: CheckEasyBackend/app/core/email.py
# 邮件发送工具示例
def send_email(recipient: str, subject: str, body: str):
# 邮件发送逻辑
print(f"Sending email to {recipient}")
EOF
## app/modules/
mkdir -p app/modules
### 1. modules/auth/
mkdir -p app/modules/auth
#### 1.1. auth/login/
mkdir -p app/modules/auth/login
echo "# File: CheckEasyBackend/app/modules/auth/login/__init__.py" > app/modules/auth/login/__init__.py
cat <<'EOF' > app/modules/auth/login/routes.py
# File: CheckEasyBackend/app/modules/auth/login/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/login")
def login():
return {"message": "Login route"}
EOF
cat <<'EOF' > app/modules/auth/login/schemas.py
# File: CheckEasyBackend/app/modules/auth/login/schemas.py
from pydantic import BaseModel
class LoginRequest(BaseModel):
username: str
password: str
EOF
cat <<'EOF' > app/modules/auth/login/utils.py
# File: CheckEasyBackend/app/modules/auth/login/utils.py
def verify_credentials(username: str, password: str) -> bool:
# 示例:简单验证
return True
EOF
#### 1.2. auth/register/
mkdir -p app/modules/auth/register
echo "# File: CheckEasyBackend/app/modules/auth/register/__init__.py" > app/modules/auth/register/__init__.py
cat <<'EOF' > app/modules/auth/register/routes.py
# File: CheckEasyBackend/app/modules/auth/register/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/register")
def register():
return {"message": "Register route"}
EOF
cat <<'EOF' > app/modules/auth/register/schemas.py
# File: CheckEasyBackend/app/modules/auth/register/schemas.py
from pydantic import BaseModel
class RegisterRequest(BaseModel):
username: str
password: str
email: str
verification_code: str
EOF
cat <<'EOF' > app/modules/auth/register/utils.py
# File: CheckEasyBackend/app/modules/auth/register/utils.py
def generate_verification_code() -> str:
return "123456"
EOF
cat <<'EOF' > app/modules/auth/register/models.py
# File: CheckEasyBackend/app/modules/auth/register/models.py
# 用户模型示例
class User:
def __init__(self, username: str, email: str):
self.username = username
self.email = email
EOF
#### 1.3. auth/forgot_password/
mkdir -p app/modules/auth/forgot_password
echo "# File: CheckEasyBackend/app/modules/auth/forgot_password/__init__.py" > app/modules/auth/forgot_password/__init__.py
cat <<'EOF' > app/modules/auth/forgot_password/routes.py
# File: CheckEasyBackend/app/modules/auth/forgot_password/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/forgot-password")
def forgot_password():
return {"message": "Forgot password route"}
EOF
cat <<'EOF' > app/modules/auth/forgot_password/schemas.py
# File: CheckEasyBackend/app/modules/auth/forgot_password/schemas.py
from pydantic import BaseModel
class ForgotPasswordRequest(BaseModel):
email: str
verification_code: str
EOF
cat <<'EOF' > app/modules/auth/forgot_password/utils.py
# File: CheckEasyBackend/app/modules/auth/forgot_password/utils.py
def generate_token():
return "token"
EOF
#### 1.4. auth/oauth/
mkdir -p app/modules/auth/oauth
echo "# File: CheckEasyBackend/app/modules/auth/oauth/__init__.py" > app/modules/auth/oauth/__init__.py
cat <<'EOF' > app/modules/auth/oauth/routes.py
# File: CheckEasyBackend/app/modules/auth/oauth/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/oauth")
def oauth():
return {"message": "OAuth route"}
EOF
cat <<'EOF' > app/modules/auth/oauth/schemas.py
# File: CheckEasyBackend/app/modules/auth/oauth/schemas.py
from pydantic import BaseModel
class OAuthResponse(BaseModel):
token: str
EOF
cat <<'EOF' > app/modules/auth/oauth/utils.py
# File: CheckEasyBackend/app/modules/auth/oauth/utils.py
def process_oauth():
return {"token": "oauth_token"}
EOF
### 2. modules/verification/
mkdir -p app/modules/verification
#### 2.1. verification/ocr/
mkdir -p app/modules/verification/ocr
echo "# File: CheckEasyBackend/app/modules/verification/ocr/__init__.py" > app/modules/verification/ocr/__init__.py
cat <<'EOF' > app/modules/verification/ocr/routes.py
# File: CheckEasyBackend/app/modules/verification/ocr/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/ocr")
def ocr():
return {"message": "OCR route"}
EOF
cat <<'EOF' > app/modules/verification/ocr/schemas.py
# File: CheckEasyBackend/app/modules/verification/ocr/schemas.py
from pydantic import BaseModel
class OCRRequest(BaseModel):
image_path: str
EOF
cat <<'EOF' > app/modules/verification/ocr/models.py
# File: CheckEasyBackend/app/modules/verification/ocr/models.py
class OCRRecord:
def __init__(self, record_id: int):
self.record_id = record_id
EOF
cat <<'EOF' > app/modules/verification/ocr/utils.py
# File: CheckEasyBackend/app/modules/verification/ocr/utils.py
def perform_ocr(image_path: str) -> str:
return "识别结果"
EOF
#### 2.2. verification/manual/
mkdir -p app/modules/verification/manual
echo "# File: CheckEasyBackend/app/modules/verification/manual/__init__.py" > app/modules/verification/manual/__init__.py
cat <<'EOF' > app/modules/verification/manual/routes.py
# File: CheckEasyBackend/app/modules/verification/manual/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/manual-review")
def manual_review():
return {"message": "Manual review route"}
EOF
cat <<'EOF' > app/modules/verification/manual/schemas.py
# File: CheckEasyBackend/app/modules/verification/manual/schemas.py
from pydantic import BaseModel
class ManualReviewRequest(BaseModel):
record_id: int
approve: bool
EOF
cat <<'EOF' > app/modules/verification/manual/models.py
# File: CheckEasyBackend/app/modules/verification/manual/models.py
class ManualReviewRecord:
def __init__(self, record_id: int):
self.record_id = record_id
EOF
cat <<'EOF' > app/modules/verification/manual/utils.py
# File: CheckEasyBackend/app/modules/verification/manual/utils.py
def review_record(record_id: int, approve: bool) -> bool:
return approve
EOF
### 3. modules/checkin/
mkdir -p app/modules/checkin
echo "# File: CheckEasyBackend/app/modules/checkin/__init__.py" > app/modules/checkin/__init__.py
cat <<'EOF' > app/modules/checkin/routes.py
# File: CheckEasyBackend/app/modules/checkin/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.post("/checkin")
def checkin():
return {"message": "Check-in route"}
EOF
cat <<'EOF' > app/modules/checkin/schemas.py
# File: CheckEasyBackend/app/modules/checkin/schemas.py
from pydantic import BaseModel
class CheckinRequest(BaseModel):
user_id: int
document_id: str
EOF
cat <<'EOF' > app/modules/checkin/models.py
# File: CheckEasyBackend/app/modules/checkin/models.py
class CheckinRecord:
def __init__(self, user_id: int):
self.user_id = user_id
EOF
cat <<'EOF' > app/modules/checkin/utils.py
# File: CheckEasyBackend/app/modules/checkin/utils.py
def process_checkin(user_id: int) -> bool:
return True
EOF
### 4. modules/notification/
mkdir -p app/modules/notification
echo "# File: CheckEasyBackend/app/modules/notification/__init__.py" > app/modules/notification/__init__.py
cat <<'EOF' > app/modules/notification/routes.py
# File: CheckEasyBackend/app/modules/notification/routes.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/notification")
def notification():
return {"message": "Notification route"}
EOF
cat <<'EOF' > app/modules/notification/schemas.py
# File: CheckEasyBackend/app/modules/notification/schemas.py
from pydantic import BaseModel
class Notification(BaseModel):
title: str
message: str
EOF
cat <<'EOF' > app/modules/notification/models.py
# File: CheckEasyBackend/app/modules/notification/models.py
class NotificationRecord:
def __init__(self, notification_id: int):
self.notification_id = notification_id
EOF
cat <<'EOF' > app/modules/notification/tasks.py
# File: CheckEasyBackend/app/modules/notification/tasks.py
def send_async_notification(notification):
print("Sending async notification")
EOF
## app/uploads/ (用于存放上传文件)
mkdir -p app/uploads
## app/main.py
cat <<'EOF' > app/main.py
# File: CheckEasyBackend/app/main.py
from fastapi import FastAPI
from app.api.api_v1 import router as api_v1_router
app = FastAPI(
title="CheckEasyBackend",
description="企业级后端服务",
version="1.0.0"
)
# 集成 API 路由
app.include_router(api_v1_router, prefix="/api/v1", tags=["API v1"])
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
EOF
# 2. database 目录及文件
mkdir -p database
echo "-- File: CheckEasyBackend/database/init.sql" > database/init.sql
echo "-- 数据库初始化脚本" >> database/init.sql
# 3. scripts 目录及文件
mkdir -p scripts
cat <<'EOF' > scripts/deploy.sh
#!/bin/bash
# File: CheckEasyBackend/scripts/deploy.sh
# 部署脚本示例
echo "部署项目..."
EOF
chmod +x scripts/deploy.sh
cat <<'EOF' > scripts/backup.sh
#!/bin/bash
# File: CheckEasyBackend/scripts/backup.sh
# 数据库备份脚本示例
echo "备份数据库..."
EOF
chmod +x scripts/backup.sh
# 4. tests 目录及文件
mkdir -p tests
echo "# File: CheckEasyBackend/tests/__init__.py" > tests/__init__.py
cat <<'EOF' > tests/test_auth.py
# File: CheckEasyBackend/tests/test_auth.py
def test_login():
assert True, "测试登录逻辑"
EOF
# 5. 根目录下其他文件
## requirements.txt
cat <<'EOF' > requirements.txt
fastapi==0.95.0
uvicorn==0.21.1
python-dotenv==1.0.0
pydantic==1.10.2
EOF
## Dockerfile
cat <<'EOF' > Dockerfile
# File: CheckEasyBackend/Dockerfile
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
EOF
## docker-compose.yml
cat <<'EOF' > docker-compose.yml
# File: CheckEasyBackend/docker-compose.yml
version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
environment:
- DATABASE_URL=sqlite:///./test.db
EOF
## .env
cat <<'EOF' > .env
# File: CheckEasyBackend/.env
DATABASE_URL=sqlite:///./test.db
EOF
## README.md
cat <<'EOF' > README.md
# CheckEasyBackend
企业级后端服务项目
EOF
echo "项目完整目录结构和所有文件已创建完成!"