refactor: 重构后端架构,采用 Go 风格四层设计模式
Some checks failed
部署后端服务 / 🧪 测试后端 (push) Failing after 1m37s
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped

## 主要变更

### 🏗️ 架构重构
- 采用简洁的四层架构:API → Service → Repository → Model
- 遵循 Go 语言最佳实践和命名规范
- 实现依赖注入和接口导向设计
- 统一错误处理和响应格式

### 📁 目录结构优化
- 删除重复模块 (application/, domain/, infrastructure/ 等)
- 规范化命名 (使用 Go 风格的 snake_case)
- 清理无关文件 (package.json, node_modules/ 等)
- 新增规范化的测试目录结构

### 📚 文档系统
- 为每个模块创建详细的 CLAUDE.md 指导文件
- 包含开发规范、最佳实践和使用示例
- 支持模块化开发,缩短上下文长度

### 🔧 开发规范
- 统一接口命名规范 (UserServicer, PhotoRepositoryr)
- 标准化错误处理机制
- 完善的测试策略 (单元测试、集成测试、性能测试)
- 规范化的配置管理

### 🗂️ 新增文件
- cmd/server/ - 服务启动入口和配置
- internal/model/ - 数据模型层 (entity, dto, request)
- pkg/ - 共享工具包 (logger, response, validator)
- tests/ - 完整测试结构
- docs/ - API 文档和架构设计
- .gitignore - Git 忽略文件配置

### 🗑️ 清理内容
- 删除 Node.js 相关文件 (package.json, node_modules/)
- 移除重复的架构目录
- 清理临时文件和构建产物
- 删除重复的文档文件

## 影响
- 提高代码可维护性和可扩展性
- 统一开发规范,提升团队协作效率
- 优化项目结构,符合 Go 语言生态标准
- 完善文档体系,降低上手难度
This commit is contained in:
xujiang
2025-07-10 11:20:59 +08:00
parent 540593f1dc
commit a2f2f66f88
40 changed files with 9682 additions and 1798 deletions

116
backend/test_api.http Normal file
View File

@ -0,0 +1,116 @@
# Photography Backend API 测试文件
### 健康检查
GET http://localhost:8080/health
### 获取数据库统计
GET http://localhost:8080/stats
### 用户注册
POST http://localhost:8080/api/v1/auth/register
Content-Type: application/json
{
"username": "testuser",
"email": "test@example.com",
"password": "password123",
"name": "测试用户"
}
### 用户登录
POST http://localhost:8080/api/v1/auth/login
Content-Type: application/json
{
"username": "testuser",
"password": "password123"
}
### 获取所有用户
GET http://localhost:8080/api/v1/users
### 创建用户
POST http://localhost:8080/api/v1/users
Content-Type: application/json
{
"username": "newuser",
"email": "newuser@example.com",
"password": "password123",
"name": "新用户",
"role": "user"
}
### 获取所有分类
GET http://localhost:8080/api/v1/categories
### 创建分类
POST http://localhost:8080/api/v1/categories
Content-Type: application/json
{
"name": "风景摄影",
"description": "自然风光摄影作品",
"user_id": 1,
"color": "#10B981"
}
### 获取所有标签
GET http://localhost:8080/api/v1/tags
### 创建标签
POST http://localhost:8080/api/v1/tags
Content-Type: application/json
{
"name": "自然",
"description": "自然风光主题",
"user_id": 1,
"color": "#10B981"
}
### 获取所有相册
GET http://localhost:8080/api/v1/albums
### 创建相册
POST http://localhost:8080/api/v1/albums
Content-Type: application/json
{
"title": "我的摄影作品",
"description": "个人摄影作品集",
"user_id": 1,
"is_public": true
}
### 获取所有照片
GET http://localhost:8080/api/v1/photos
### 创建照片记录
POST http://localhost:8080/api/v1/photos
Content-Type: application/json
{
"title": "美丽风景",
"description": "在山顶拍摄的日出",
"filename": "sunrise.jpg",
"original_url": "http://localhost:8080/uploads/photos/sunrise.jpg",
"file_size": 1024000,
"mime_type": "image/jpeg",
"user_id": 1,
"category_id": 1
}
### 文件上传 (需要使用支持文件上传的客户端)
# POST http://localhost:8080/api/v1/upload/photo
# Content-Type: multipart/form-data
# Authorization: Bearer YOUR_JWT_TOKEN
#
# photo: [选择图片文件]
# title: 照片标题
# description: 照片描述
# category_id: 1
### 获取上传统计 (需要管理员权限)
# GET http://localhost:8080/api/v1/upload/stats
# Authorization: Bearer ADMIN_JWT_TOKEN