refactor: 重构后端架构,采用 Go 风格四层设计模式
## 主要变更 ### 🏗️ 架构重构 - 采用简洁的四层架构: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:
105
backend/configs/config.dev.yaml
Normal file
105
backend/configs/config.dev.yaml
Normal file
@ -0,0 +1,105 @@
|
||||
# 开发环境配置
|
||||
app:
|
||||
name: "Photography Portfolio Dev"
|
||||
version: "1.0.0"
|
||||
environment: "development"
|
||||
port: 8080
|
||||
debug: true
|
||||
|
||||
# 数据库配置
|
||||
database:
|
||||
host: "localhost"
|
||||
port: 5432
|
||||
username: "postgres"
|
||||
password: "password"
|
||||
database: "photography_dev"
|
||||
ssl_mode: "disable"
|
||||
max_open_conns: 50
|
||||
max_idle_conns: 5
|
||||
conn_max_lifetime: 300
|
||||
|
||||
# Redis配置
|
||||
redis:
|
||||
host: "localhost"
|
||||
port: 6379
|
||||
password: ""
|
||||
database: 1
|
||||
pool_size: 10
|
||||
min_idle_conns: 2
|
||||
|
||||
# JWT配置
|
||||
jwt:
|
||||
secret: "dev-secret-key-not-for-production"
|
||||
expires_in: "24h"
|
||||
refresh_expires_in: "168h"
|
||||
|
||||
# 存储配置
|
||||
storage:
|
||||
type: "local"
|
||||
local:
|
||||
base_path: "./uploads"
|
||||
base_url: "http://localhost:8080/uploads"
|
||||
s3:
|
||||
region: "us-east-1"
|
||||
bucket: "photography-dev-bucket"
|
||||
access_key: ""
|
||||
secret_key: ""
|
||||
endpoint: ""
|
||||
|
||||
# 上传配置
|
||||
upload:
|
||||
max_file_size: 104857600 # 100MB
|
||||
allowed_types:
|
||||
- "image/jpeg"
|
||||
- "image/jpg"
|
||||
- "image/png"
|
||||
- "image/gif"
|
||||
- "image/webp"
|
||||
- "image/tiff"
|
||||
- "image/bmp"
|
||||
thumbnail_sizes:
|
||||
- name: "thumbnail"
|
||||
width: 200
|
||||
height: 200
|
||||
- name: "medium"
|
||||
width: 800
|
||||
height: 600
|
||||
- name: "large"
|
||||
width: 1920
|
||||
height: 1080
|
||||
|
||||
# 日志配置
|
||||
logger:
|
||||
level: "debug"
|
||||
format: "text"
|
||||
output: "stdout"
|
||||
filename: "logs/dev.log"
|
||||
max_size: 50
|
||||
max_age: 7
|
||||
compress: false
|
||||
|
||||
# CORS配置
|
||||
cors:
|
||||
allowed_origins:
|
||||
- "http://localhost:3000"
|
||||
- "http://localhost:3001"
|
||||
- "http://localhost:5173"
|
||||
allowed_methods:
|
||||
- "GET"
|
||||
- "POST"
|
||||
- "PUT"
|
||||
- "DELETE"
|
||||
- "PATCH"
|
||||
- "OPTIONS"
|
||||
allowed_headers:
|
||||
- "Content-Type"
|
||||
- "Authorization"
|
||||
- "X-Requested-With"
|
||||
- "Origin"
|
||||
allow_credentials: true
|
||||
|
||||
# 限流配置
|
||||
rate_limit:
|
||||
enabled: false
|
||||
requests_per_minute: 1000
|
||||
burst: 2000
|
||||
101
backend/configs/config.prod.yaml
Normal file
101
backend/configs/config.prod.yaml
Normal file
@ -0,0 +1,101 @@
|
||||
# 生产环境配置
|
||||
app:
|
||||
name: "Photography Portfolio"
|
||||
version: "1.0.0"
|
||||
environment: "production"
|
||||
port: 8080
|
||||
debug: false
|
||||
|
||||
# 数据库配置
|
||||
database:
|
||||
host: "localhost"
|
||||
port: 5432
|
||||
username: "postgres"
|
||||
password: "${DB_PASSWORD}"
|
||||
database: "photography"
|
||||
ssl_mode: "require"
|
||||
max_open_conns: 200
|
||||
max_idle_conns: 20
|
||||
conn_max_lifetime: 3600
|
||||
|
||||
# Redis配置
|
||||
redis:
|
||||
host: "localhost"
|
||||
port: 6379
|
||||
password: "${REDIS_PASSWORD}"
|
||||
database: 0
|
||||
pool_size: 50
|
||||
min_idle_conns: 10
|
||||
|
||||
# JWT配置
|
||||
jwt:
|
||||
secret: "${JWT_SECRET}"
|
||||
expires_in: "24h"
|
||||
refresh_expires_in: "168h"
|
||||
|
||||
# 存储配置
|
||||
storage:
|
||||
type: "local" # 生产环境建议使用 s3 或 oss
|
||||
local:
|
||||
base_path: "/var/www/photography/uploads"
|
||||
base_url: "https://photography.iriver.top/uploads"
|
||||
s3:
|
||||
region: "${AWS_REGION}"
|
||||
bucket: "${AWS_BUCKET}"
|
||||
access_key: "${AWS_ACCESS_KEY_ID}"
|
||||
secret_key: "${AWS_SECRET_ACCESS_KEY}"
|
||||
endpoint: "${AWS_ENDPOINT}"
|
||||
|
||||
# 上传配置
|
||||
upload:
|
||||
max_file_size: 104857600 # 100MB
|
||||
allowed_types:
|
||||
- "image/jpeg"
|
||||
- "image/jpg"
|
||||
- "image/png"
|
||||
- "image/gif"
|
||||
- "image/webp"
|
||||
- "image/tiff"
|
||||
thumbnail_sizes:
|
||||
- name: "thumbnail"
|
||||
width: 200
|
||||
height: 200
|
||||
- name: "medium"
|
||||
width: 800
|
||||
height: 600
|
||||
- name: "large"
|
||||
width: 1920
|
||||
height: 1080
|
||||
|
||||
# 日志配置
|
||||
logger:
|
||||
level: "info"
|
||||
format: "json"
|
||||
output: "file"
|
||||
filename: "/var/log/photography/app.log"
|
||||
max_size: 100
|
||||
max_age: 30
|
||||
compress: true
|
||||
|
||||
# CORS配置
|
||||
cors:
|
||||
allowed_origins:
|
||||
- "https://photography.iriver.top"
|
||||
- "https://admin.photography.iriver.top"
|
||||
allowed_methods:
|
||||
- "GET"
|
||||
- "POST"
|
||||
- "PUT"
|
||||
- "DELETE"
|
||||
- "OPTIONS"
|
||||
allowed_headers:
|
||||
- "Content-Type"
|
||||
- "Authorization"
|
||||
- "X-Requested-With"
|
||||
allow_credentials: true
|
||||
|
||||
# 限流配置
|
||||
rate_limit:
|
||||
enabled: true
|
||||
requests_per_minute: 60
|
||||
burst: 120
|
||||
Reference in New Issue
Block a user