Skip to content

Commit e757ac5

Browse files
authored
Merge pull request #379 from fastapiadmin/dev
Dev
2 parents 842d1a5 + c4ce0c5 commit e757ac5

1,031 files changed

Lines changed: 162280 additions & 36146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.en.md

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,57 @@ This is about **how source directories are split** (package by feature vs by lay
9898
```sh
9999
FastapiAdmin
100100
├─ backend # Backend project (FastAPI + Python)
101-
├─ frontend # Web frontend project (Vue3 + Element Plus)
102-
├─ devops # Deployment configurations
103-
├─ docker-compose.yaml # Docker orchestration file
104-
├─ deploy.sh # One-click deployment script
101+
├─ frontend # Frontend project directory
102+
│ ├── web # Web frontend (Vue3 + Element Plus)
103+
│ ├── app # Mobile (UniApp)
104+
│ └── docs # Documentation site (VitePress)
105+
├─ docker # Docker configuration
106+
│ ├── backend # Backend Dockerfile
107+
│ ├── nginx # Nginx configuration and static files
108+
│ ├── mysql # MySQL data directory
109+
│ └── redis # Redis data directory
110+
├─ deploy.sh # One-click deployment script (Linux)
111+
├─ deploy.bat # One-click startup script (Windows)
105112
├─ LICENSE # Open source license
106113
|─ README.en.md # English documentation
107114
└─ README.md # Chinese documentation
108115
```
109116

110117
## 🏗️ Local Architecture & Default Ports
111118

112-
Aligned with **`backend/env/.env.dev.example`** and **`frontend/.env.development.example`**; if you changed `.env.dev` / `.env.development`, use your local values.
119+
Aligned with **`backend/env/.env.dev.example`** and **`frontend/web/.env.development`**; if you changed `.env.dev` / `.env.development`, use your local values.
113120

114121
```mermaid
115122
flowchart LR
116123
subgraph client[Browser]
117124
U[User]
118125
end
119-
subgraph fe[frontend dev]
120-
V[Vue3 + Vite]
126+
subgraph fe[Frontend Development]
127+
V[Vue3 Web] -->|5173| U
128+
A[UniApp H5] -->|8080| U
129+
D[VitePress Docs] -->|5174| U
121130
end
122-
subgraph be[backend]
123-
A[FastAPI / Uvicorn]
131+
subgraph be[Backend]
132+
F[FastAPI / Uvicorn] -->|8001| V
133+
F -->|8001| A
134+
F -->|8001| D
124135
end
125-
subgraph data[Data]
136+
subgraph data[Data Layer]
126137
DB[(Database)]
127138
R[(Redis)]
128139
end
129-
U --> V
130-
V -->|REST via VITE_API_BASE_URL| A
131-
A --> DB
132-
A --> R
140+
F --> DB
141+
F --> R
133142
```
134143

135144
| Component | Config key | Example default (dev template) |
136145
|-------------|------------|--------------------------------|
137-
| Web UI | `frontend/.env.development``VITE_APP_PORT` | **5180****`http://127.0.0.1:5180`** |
146+
| Web Frontend | `frontend/web/.env.development``VITE_PORT` | **5173****`http://127.0.0.1:5173`** |
147+
| Mobile H5 | `frontend/app` dev server | **8080****`http://127.0.0.1:8080`** |
148+
| Docs Site | `frontend/docs` dev server | **5174****`http://127.0.0.1:5174`** |
138149
| Backend HTTP | `backend/env/.env.dev``SERVER_HOST` / `SERVER_PORT` | **`0.0.0.0:8001`****`http://127.0.0.1:8001`** |
139150
| API base URL | `VITE_API_BASE_URL` | **`http://127.0.0.1:8001`** |
140-
| API prefix | `ROOT_PATH` + `VITE_APP_BASE_API` | **`/api/v1`** on both sides |
151+
| API prefix | `ROOT_PATH` (backend) | **`/api/v1`** |
141152
| Swagger / Redoc || **`http://127.0.0.1:8001/docs`**, `/redoc` |
142153
| WebSocket (optional) | `VITE_APP_WS_ENDPOINT` | e.g. **`ws://127.0.0.1:8001`** |
143154
| DB port | `DATABASE_PORT` | Template uses MySQL **`3306`**; PostgreSQL often **`5432`** |
@@ -255,27 +266,52 @@ python main.py run --env=dev
255266

256267
### Frontend Setup
257268

269+
#### Web Frontend (Vue3)
270+
271+
```bash
272+
cd frontend/web
273+
pnpm install
274+
pnpm run dev
275+
# Build production version
276+
pnpm run build
277+
```
278+
279+
#### Mobile (UniApp)
280+
281+
```bash
282+
cd frontend/app
283+
pnpm install
284+
pnpm run dev:h5 # Start H5 development server
285+
# Build production version
286+
pnpm run build:h5
287+
```
288+
289+
#### Documentation Site (VitePress)
290+
258291
```bash
259-
cd frontend
292+
cd frontend/docs
260293
pnpm install
261294
pnpm run dev
295+
# Build production version
262296
pnpm run build
263297
```
264298

265299
### After startup
266300

267-
When using **`.env.dev.example` / `.env.development.example`** as-is:
301+
When using **`.env.dev.example` / `.env.development`** as-is:
268302

269303
| Service | URL (example) |
270304
|---------|----------------|
271-
| Web UI (Vite) | `http://127.0.0.1:5180` |
305+
| Web Frontend (Vite) | `http://127.0.0.1:5173` |
306+
| Mobile H5 (UniApp) | `http://127.0.0.1:8080` |
307+
| Documentation Site (VitePress) | `http://127.0.0.1:5174` |
272308
| Backend base | `http://127.0.0.1:8001` |
273309
| Swagger | `http://127.0.0.1:8001/docs` |
274310
| API prefix | `http://127.0.0.1:8001/api/v1` (matches `ROOT_PATH`) |
275311

276312
### 🐳 Docker Deployment
277313

278-
#### Method 1: Execute script inside project (Recommended)
314+
#### Method 1: Use deploy.sh script (Recommended)
279315

280316
```bash
281317
# 1. Clone the repository to server
@@ -291,6 +327,18 @@ chmod +x deploy.sh
291327

292328
# Stop services
293329
./deploy.sh stop
330+
331+
# Restart services
332+
./deploy.sh restart
333+
334+
# Only update code and restart (without rebuilding images)
335+
./deploy.sh update
336+
337+
# Skip frontend build (use uploaded static files)
338+
./deploy.sh --skip-frontend
339+
340+
# Enable frontend build (build on server)
341+
./deploy.sh --build-frontend
294342
```
295343

296344
#### Method 2: Execute script outside project

README.md

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,57 @@
9898
```sh
9999
FastapiAdmin
100100
├─ backend # 后端工程 (FastAPI + Python)
101-
├─ frontend # Web前端工程 (Vue3 + Element Plus)
102-
├─ devops # 部署配置
103-
├─ docker-compose.yaml # Docker编排文件
104-
├─ deploy.sh # 一键部署脚本
101+
├─ frontend # 前端工程目录
102+
│ ├── web # Web前端 (Vue3 + Element Plus)
103+
│ ├── app # 移动端 (UniApp)
104+
│ └── docs # 文档网站 (VitePress)
105+
├─ docker # Docker 配置
106+
│ ├── backend # 后端 Dockerfile
107+
│ ├── nginx # Nginx 配置和静态文件
108+
│ ├── mysql # MySQL 数据目录
109+
│ └── redis # Redis 数据目录
110+
├─ deploy.sh # 一键部署脚本 (Linux)
111+
├─ deploy.bat # 一键启动脚本 (Windows)
105112
├─ LICENSE # 开源协议
106113
|─ README.en.md # 英文文档
107114
└─ README.md # 中文文档
108115
```
109116

110117
## 🏗️ 本地架构与默认端口
111118

112-
与仓库内 **`backend/env/.env.dev.example`****`frontend/.env.development.example`** 保持一致;若你本地已改 `.env.dev` / `.env.development`,以实际文件为准。
119+
与仓库内 **`backend/env/.env.dev.example`****`frontend/web/.env.development`** 保持一致;若你本地已改 `.env.dev` / `.env.development`,以实际文件为准。
113120

114121
```mermaid
115122
flowchart LR
116123
subgraph client[浏览器]
117124
U[用户]
118125
end
119-
subgraph fe[frontend 开发]
120-
V[Vue3 + Vite]
126+
subgraph fe[前端开发]
127+
V[Vue3 Web] -->|5173| U
128+
A[UniApp H5] -->|8080| U
129+
D[VitePress 文档] -->|5174| U
121130
end
122-
subgraph be[backend]
123-
A[FastAPI / Uvicorn]
131+
subgraph be[后端]
132+
F[FastAPI / Uvicorn] -->|8001| V
133+
F -->|8001| A
134+
F -->|8001| D
124135
end
125136
subgraph data[数据层]
126137
DB[(数据库)]
127138
R[(Redis)]
128139
end
129-
U --> V
130-
V -->|REST 见 VITE_API_BASE_URL| A
131-
A --> DB
132-
A --> R
140+
F --> DB
141+
F --> R
133142
```
134143

135144
| 组件 | 配置项 | 示例默认值(开发模板) |
136145
|------|--------|------------------------|
137-
| 前端页面 | `frontend/.env.development``VITE_APP_PORT` | **5180**,即 **`http://127.0.0.1:5180`** |
146+
| Web前端 | `frontend/web/.env.development``VITE_PORT` | **5173**,即 **`http://127.0.0.1:5173`** |
147+
| 移动端H5 | `frontend/app` 开发服务器 | **8080**,即 **`http://127.0.0.1:8080`** |
148+
| 文档服务 | `frontend/docs` 开发服务器 | **5174**,即 **`http://127.0.0.1:5174`** |
138149
| 后端 HTTP | `backend/env/.env.dev``SERVER_HOST` / `SERVER_PORT` | **`0.0.0.0:8001`**,本机访问 **`http://127.0.0.1:8001`** |
139150
| 前端请求后端 | `VITE_API_BASE_URL` | **`http://127.0.0.1:8001`** |
140-
| API 前缀 | `ROOT_PATH`(后端)+ `VITE_APP_BASE_API`(前端) | 后端 **`/api/v1`**;前端代理前缀 **`/api/v1`** |
151+
| API 前缀 | `ROOT_PATH`(后端) | 后端 **`/api/v1`** |
141152
| Swagger / Redoc || **`http://127.0.0.1:8001/docs`**`/redoc` |
142153
| WebSocket(可选) | `VITE_APP_WS_ENDPOINT` | 示例 **`ws://127.0.0.1:8001`** |
143154
| 数据库端口 | `DATABASE_PORT` | 模板为 MySQL **`3306`**;PostgreSQL 常见 **`5432`** |
@@ -259,8 +270,30 @@ python main.py run --env=dev
259270

260271
### 前端启动
261272

273+
#### Web前端 (Vue3)
274+
275+
```bash
276+
cd frontend/web
277+
pnpm install
278+
pnpm run dev
279+
# 构建生产版本
280+
pnpm run build
281+
```
282+
283+
#### 移动端 (UniApp)
284+
285+
```bash
286+
cd frontend/app
287+
pnpm install
288+
pnpm run dev:h5 # 启动H5开发服务器
289+
# 构建生产版本
290+
pnpm run build:h5
291+
```
292+
293+
#### 文档网站 (VitePress)
294+
262295
```bash
263-
cd frontend
296+
cd frontend/docs
264297
pnpm install
265298
pnpm run dev
266299
# 构建生产版本
@@ -269,18 +302,20 @@ pnpm run build
269302

270303
### 启动后访问
271304

272-
**`.env.dev.example` / `.env.development.example`** 对齐时:
305+
**`.env.dev.example` / `.env.development`** 对齐时:
273306

274307
| 服务 | 地址(示例) |
275308
|------|----------------|
276-
| 前端 Web(Vite) | `http://127.0.0.1:5180` |
309+
| Web前端 (Vite) | `http://127.0.0.1:5173` |
310+
| 移动端H5 (UniApp) | `http://127.0.0.1:8080` |
311+
| 文档网站 (VitePress) | `http://127.0.0.1:5174` |
277312
| 后端 API 根 | `http://127.0.0.1:8001` |
278313
| Swagger | `http://127.0.0.1:8001/docs` |
279314
| 业务接口前缀 | `http://127.0.0.1:8001/api/v1`(与 `ROOT_PATH` 一致) |
280315

281316
### 🐳 Docker 部署
282317

283-
#### 方式一:脚本放在项目内执行(推荐)
318+
#### 使用 deploy.sh 脚本(推荐)
284319

285320
```bash
286321
# 1. 克隆代码到服务器
@@ -300,32 +335,14 @@ chmod +x deploy.sh
300335
# 重启服务
301336
./deploy.sh restart
302337

303-
# 更新代码并重启(不重新构建镜像,适合后端代码热更新
338+
# 仅更新代码并重启(不重新构建镜像)
304339
./deploy.sh update
305-
```
306340

307-
#### 方式二:脚本放在项目外执行
341+
# 跳过前端构建(使用已上传的静态文件)
342+
./deploy.sh --skip-frontend
308343

309-
```bash
310-
# 1. 将部署脚本复制到服务器
311-
cp deploy.sh /home/
312-
cd /home
313-
chmod +x deploy.sh
314-
315-
# 2. 执行一键部署(会自动克隆项目)
316-
./deploy.sh
317-
318-
# 查看容器日志
319-
./deploy.sh logs
320-
321-
# 停止服务
322-
./deploy.sh stop
323-
324-
# 重启服务
325-
./deploy.sh restart
326-
327-
# 更新代码并重启(不重新构建镜像,适合后端代码热更新)
328-
./deploy.sh update
344+
# 启用前端构建(在服务器上构建)
345+
./deploy.sh --build-frontend
329346
```
330347

331348
> **注意**

0 commit comments

Comments
 (0)