# ICE-Core **Repository Path**: Intelligent-Class-Ecosystem/ICE-Core ## Basic Information - **Project Name**: ICE-Core - **Description**: ICE(Intelligent Class Ecosystem)冰核智慧课堂生态系统内核(后端)代码仓库 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-25 - **Last Updated**: 2025-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LearnHUB Server LearnHUB的后端 ## 🛠️ 技术栈 - **框架**: FastAPI 0.116.1+ - **数据库**: asyncpg 0.30.0+ - **缓存**: Redis 5.0.0+ - **认证**: 简化Session认证系统 - **加密**: argon2-cffi-bindings 25.1.0+ - **数据验证**: Pydantic 2.5.0+ ## 🚀 快速开始 ### 1. 环境准备 ```bash # 克隆项目 # 创建虚拟环境 python -m venv venv # 激活虚拟环境 # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate ``` ### 2. 安装依赖 ```bash # 使用现代Python项目管理 pip install -e . # 或者安装开发依赖 pip install -e ".[dev]" ``` ### 3. 配置环境变量 ```bash # 复制环境变量模板 copy .env.example .env # 编辑.env文件,配置数据库连接等参数 # 建议在生产环境中使用PostgreSQL和Redis ``` ### 4. 启动服务 ```bash # 开发模式启动 fastapi dev main.py ``` ### 5. 访问API文档 - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## 📁 项目结构 ``` LearnHUB_Server/ ├── main.py # 应用入口,包含路由和中间件配置 ├── config.py # 应用配置管理 ├── pyproject.toml # 现代Python项目管理 ├── .env.example # 环境变量示例 ├── core/ # 核心功能模块 │ ├── database.py # 数据库管理器(asyncpg) │ ├── auth.py # Redis+内存Session认证系统 │ ├── redis.py # Redis连接管理器 │ └── init_db.py # 数据库初始化 ├── user/ # 用户模块 │ ├── router.py # 用户路由 │ └── services.py # 用户服务 ├── course/ # 课程模块 │ ├── router.py # 课程路由 │ ├── services.py # 课程服务 │ └── models.py # 课程数据模型 └── schemas/ # 通用数据验证模式 └── schemas.py # Pydantic数据模型 ``` ## 📊 性能监控 ### 健康检查 ```bash curl http://localhost:8000/health ``` 返回系统健康状态,包括数据库连接、连接池状态和性能指标。 ### 性能指标 ```bash curl http://localhost:8000/metrics ``` 返回详细的性能指标: - 请求数量和平均响应时间 - 数据库连接池状态 - 系统运行时间 - 活跃session数量 ### 系统维护 ```bash # 优化系统性能 curl -X POST http://localhost:8000/api/v1/maintenance/optimize # 清理系统资源 curl -X POST http://localhost:8000/api/v1/maintenance/cleanup # 清理系统资源 curl -X POST http://localhost:8000/api/v1/maintenance/cleanup ``` ### Session配置 ```python # 简化的session管理 SESSION_TIMEOUT=1800 # 30分钟过期 REDIS_URL=redis://localhost:6379/0 # Redis连接 ``` **特性:** - 简化的Redis存储session管理 - 提供基本的认证和会话管理功能 - 支持用户登录、登出和基本权限验证 ## 🔄 API端点 ### 认证相关 - `POST /api/v1/users/login` - 用户登录 - `POST /api/v1/users/register` - 用户注册 - `POST /api/v1/users/logout` - 用户登出 ### 用户管理 - `GET /api/v1/users/me` - 获取当前用户信息 - `PUT /api/v1/users/me` - 更新用户信息 - `GET /api/v1/users` - 获取用户列表 - `GET /api/v1/users/{user_id}` - 获取指定用户 ### 课程管理 - `GET /api/v1/courses` - 获取课程列表 - `POST /api/v1/courses` - 创建课程 - `GET /api/v1/courses/{course_id}` - 获取课程详情 - `PUT /api/v1/courses/{course_id}` - 更新课程 - `DELETE /api/v1/courses/{course_id}` - 删除课程 ### 系统监控 - `GET /health` - 健康检查 - `GET /metrics` - 性能指标 - `POST /api/v1/maintenance/optimize` - 系统优化 - `POST /api/v1/maintenance/cleanup` - 资源清理 ## 🧪 开发指南 ### 数据库迁移 ```bash # 初始化数据库 python -c "from core.core import init_db; init_db()" # 清理数据库 python -c "from core.core import clear_db; clear_db()" ``` ## 🚀 部署说明 ### 生产环境配置 1. **环境变量**: 配置生产环境变量 2. **数据库**: 使用PostgreSQL数据库 3. **缓存**: 配置Redis缓存 4. **监控**: 启用性能监控和日志 5. **安全**: 配置HTTPS和防火墙 ## 📄 许可证 GPLv3 License ## 🤝 贡献 欢迎提交Issue和Pull Request!