Files
jiebanke/docs/architecture.md

403 lines
7.9 KiB
Markdown
Raw Normal View History

2025-09-01 02:20:36 +08:00
# 🏗️ 系统架构文档
2025-09-01 02:20:36 +08:00
## 📋 项目概述
结伴客项目是一个综合性的管理系统,包含后台管理、微信小程序和官网三个主要模块。
2025-09-01 02:20:36 +08:00
## 🎯 技术栈
### 后端技术栈
- **运行时**: Node.js + Express.js
- **数据库**: MySQL 8.0
- **ORM**: Sequelize
- **认证**: JWT + bcrypt
- **缓存**: Redis (可选)
- **消息队列**: RabbitMQ (可选)
### 前端技术栈
- **后台管理系统**: Vue 3 + Element Plus
- **微信小程序**: 原生小程序 + Vant Weapp
- **官方网站**: Vue 3 + Vue Router
### 开发工具
- **包管理**: npm
- **容器化**: Docker + Docker Compose
- **代码质量**: ESLint + Prettier
- **测试**: Jest + Supertest
## 🏢 系统架构
2025-08-30 14:33:49 +08:00
```mermaid
graph TB
2025-09-01 02:20:36 +08:00
subgraph "前端应用"
A[后台管理系统]
B[微信小程序]
C[官方网站]
end
2025-09-01 02:20:36 +08:00
subgraph "后端服务"
D[API Gateway]
E[用户服务]
F[业务服务]
G[文件服务]
end
2025-09-01 02:20:36 +08:00
subgraph "数据层"
H[MySQL]
I[Redis]
J[MinIO]
end
A --> D
B --> D
C --> D
D --> E
D --> F
D --> G
2025-09-01 02:20:36 +08:00
E --> H
F --> H
G --> J
E --> I
```
## 🗄️ 数据库设计
### 核心表结构设计
```mermaid
erDiagram
USERS ||--o{ TRAVEL_PLANS : creates
USERS ||--o{ TRAVEL_INVITATIONS : sends
USERS ||--o{ TRAVEL_INVITATIONS : receives
USERS ||--o{ ANIMAL_CLAIMS : claims
USERS ||--o{ FLOWER_ORDERS : places
MERCHANTS ||--o{ ANIMALS : owns
MERCHANTS ||--o{ FLOWER_PRODUCTS : sells
ANIMALS ||--o{ ANIMAL_CLAIMS : claimed_by
FLOWER_PRODUCTS ||--o{ FLOWER_ORDERS : ordered
TRAVEL_PLANS ||--o{ TRAVEL_INVITATIONS : has
USERS {
int id PK
string openid
string nickname
string avatar
string gender
date birthday
string phone
string email
int travel_count
int animal_claim_count
datetime created_at
datetime updated_at
}
TRAVEL_PLANS {
int id PK
int user_id FK
string destination
date start_date
date end_date
decimal budget
string interests
string description
string visibility
string status
datetime created_at
datetime updated_at
}
2025-09-01 02:20:36 +08:00
TRAVEL_INVITATIONS {
int id PK
int travel_plan_id FK
int inviter_id FK
int invitee_id FK
string message
string status
datetime created_at
datetime updated_at
}
2025-09-01 02:20:36 +08:00
ANIMALS {
int id PK
int merchant_id FK
string name
string species
string breed
date birth_date
string personality
string farm_location
decimal price
json images
int claim_count
datetime created_at
datetime updated_at
}
2025-09-01 02:20:36 +08:00
ANIMAL_CLAIMS {
int id PK
int user_id FK
int animal_id FK
int duration
decimal total_amount
string status
date start_date
date end_date
datetime created_at
datetime updated_at
}
2025-09-01 02:20:36 +08:00
MERCHANTS {
int id PK
string business_name
string contact_person
string contact_phone
string business_license
string address
string status
datetime created_at
datetime updated_at
}
2025-09-01 02:20:36 +08:00
FLOWER_PRODUCTS {
int id PK
int merchant_id FK
string name
string description
decimal price
decimal original_price
json images
string category
int sales_count
decimal rating
string status
datetime created_at
datetime updated_at
}
FLOWER_ORDERS {
int id PK
int user_id FK
int product_id FK
string order_number
int quantity
decimal total_amount
json recipient_info
date delivery_date
string message
string status
datetime created_at
datetime updated_at
}
```
2025-09-01 02:20:36 +08:00
## 🌐 环境配置
2025-09-01 02:20:36 +08:00
### 开发环境 (Development)
```env
DB_HOST=mysql.jiebanke.com
2025-09-01 02:20:36 +08:00
DB_PORT=3306
DB_USER=root
DB_PASSWORD=rootpassword
DB_DATABASE=jiebanke_dev
NODE_ENV=development
```
2025-09-01 02:20:36 +08:00
### 测试环境 (Test)
```env
DB_HOST=192.168.0.240
DB_PORT=3306
DB_USER=root
DB_PASSWORD=aiotAiot123!
DB_DATABASE=jiebandata_test
NODE_ENV=test
```
2025-09-01 02:20:36 +08:00
### 生产环境 (Production)
```env
DB_HOST=129.211.213.226
DB_PORT=9527
DB_USER=root
DB_PASSWORD=Aiot123
DB_DATABASE=jiebandata
NODE_ENV=production
```
2025-09-01 02:20:36 +08:00
## 🔌 API 设计
### 用户模块接口
#### 微信用户登录
- **Endpoint:** `POST /api/v1/auth/wechat-login`
- **Method:** POST
- **Description:** 微信用户登录获取Token
- **Request Body:**
```json
{
"code": "string, required",
"userInfo": {
"nickName": "string, required",
"avatarUrl": "string, required",
"gender": "number, optional",
"province": "string, optional",
"city": "string, optional"
}
}
```
- **Response:**
```json
{
"code": 200,
"message": "登录成功",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"openid": "wx1234567890",
"nickname": "旅行达人",
"avatar": "https://avatar.url",
"gender": "male",
"phone": "13800138000"
}
}
}
```
#### 获取用户信息
- **Endpoint:** `GET /api/v1/users/profile`
- **Method:** GET
- **Description:** 获取当前登录用户详细信息
- **Headers:** `Authorization: Bearer <token>`
- **Response:**
```json
{
"code": 200,
"message": "获取成功",
"data": {
"id": 1,
"openid": "wx1234567890",
"nickname": "旅行达人",
"avatar": "https://avatar.url",
"gender": "male",
"birthday": "1990-01-01",
"phone": "13800138000",
"email": "test@jiebanke.com",
2025-09-01 02:20:36 +08:00
"travelCount": 5,
"animalClaimCount": 2,
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
}
```
## 🚀 部署架构
### 开发部署
```mermaid
graph LR
A[本地开发机] --> B[Docker Compose]
B --> C[MySQL容器]
B --> D[Node.js应用]
B --> E[Redis容器]
```
2025-09-01 02:20:36 +08:00
### 生产部署
```mermaid
graph TB
subgraph "云服务器"
A[Nginx]
B[Node.js集群]
C[MySQL主从]
D[Redis哨兵]
end
A --> B
B --> C
B --> D
```
2025-09-01 02:20:36 +08:00
## 📊 监控与日志
- **应用监控**: PM2 + Keymetrics
- **日志管理**: Winston + ELK Stack
- **性能监控**: New Relic / Datadog
- **错误追踪**: Sentry
## 🔒 安全架构
### 认证授权
- JWT Token 认证
- RBAC (基于角色的访问控制)
- API 速率限制
### 数据安全
- HTTPS 加密传输
- 密码加盐哈希存储
- SQL 注入防护
- XSS 攻击防护
### 网络安全
- 防火墙规则
- IP 白名单
- DDoS 防护
## 📈 性能优化
### 数据库优化
- 索引优化
- 查询缓存
- 读写分离
### 应用优化
- 响应压缩
- 静态资源CDN
- 内存缓存
### 前端优化
- 代码分割
- 懒加载
- 图片优化
## 🛠️ 开发规范
### 代码规范
- ESLint + Prettier 统一代码风格
- Git Commit 消息规范
- 代码审查流程
### 分支策略
- Git Flow 工作流
- 功能分支开发
- 发布分支管理
### 测试策略
- 单元测试覆盖核心逻辑
- 集成测试API接口
- E2E测试用户流程
## 📝 文档体系
1. **ARCHITECTURE.md** - 系统架构文档 (当前文件)
2. **README.md** - 项目说明文档
3. **API_DOCS.md** - API接口文档
4. **DEPLOYMENT.md** - 部署指南
5. **DEVELOPMENT.md** - 开发指南
## 🎯 后续规划
### 短期目标
- [ ] 完善用户管理系统
- [ ] 实现订单业务流程
- [ ] 部署测试环境
### 中期目标
- [ ] 微服务架构改造
- [ ] 容器化部署
- [ ] 自动化测试覆盖
### 长期目标
- [ ] 大数据分析平台
- [ ] AI智能推荐
- [ ] 多语言国际化
---
*最后更新: 2024年* 📅