abd44fe467
- Updated docker-compose.yml to rename backend and frontend container names for clarity. - Added volume mappings for frontend and backend services to persist data. - Removed obsolete files related to frequency response extraction, including Python scripts and output data files. - Adjusted backend port configuration in main.py to align with new service architecture. - Enhanced logging for file upload paths in models.py for better traceability.
Audio Dashboard Backend
耳机品牌与型号管理平台后端 API
技术栈
- FastAPI - 现代高性能 Web 框架
- SQLAlchemy - ORM 框架
- PyMySQL - MySQL 数据库驱动
- Pydantic - 数据验证
项目结构
backend/
├── main.py # 应用入口
├── database.py # 数据库配置
├── models/ # 数据模型
│ ├── __init__.py
│ ├── brand.py # 品牌模型
│ └── model.py # 型号模型
├── routes/ # API 路由
│ ├── __init__.py
│ ├── brands.py # 品牌 API
│ └── models.py # 型号 API
├── schemas.py # Pydantic 模式
├── requirements.txt # 依赖
├── .env # 环境变量
└── .env.example # 环境变量示例
安装
- 创建虚拟环境(可选但推荐):
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
- 安装依赖:
pip install -r requirements.txt
- 配置环境变量:
复制
.env.example为.env并根据需要修改配置
运行
# 开发模式
python main.py
# 或使用 uvicorn
uvicorn main:app --reload --host 0.0.0.0 --port 8000
API 文档
启动后访问:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API 端点
品牌管理
GET /api/brands/- 获取品牌列表GET /api/brands/{id}- 获取单个品牌POST /api/brands/- 创建品牌PUT /api/brands/{id}- 更新品牌DELETE /api/brands/{id}- 删除品牌
型号管理
GET /api/models/- 获取型号列表GET /api/models/{id}- 获取单个型号POST /api/models/- 创建型号PUT /api/models/{id}- 更新型号DELETE /api/models/{id}- 删除型号
数据库配置
默认配置:
- Host: localhost
- Port: 3306
- Database: audio
- User: root
- Password: root1
可在 .env 文件中修改配置。
注意事项
- 首次运行前请确保数据库已创建且表结构存在
- 生产环境请修改 CORS 配置,限制允许的域名
- 生产环境请使用更安全的密码管理方式