# intelligent-code-platform **Repository Path**: hw_love_666/intelligent-code-platform ## Basic Information - **Project Name**: intelligent-code-platform - **Description**: AI 代码生成平台后端项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-14 - **Last Updated**: 2025-10-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: nocode ## README AI代码生成平台后端项目 这是一个基于Spring Boot的AI代码生成平台后端项目。该项目使用Spring Boot作为主框架,并使用MyBatis作为数据库访问层。 ## 项目功能 本项目是一个智能化的代码生成平台,主要功能包括: 1. **AI驱动的代码生成**: - 支持多种代码生成模式:原生HTML、多文件静态页面、Vue工程 - 通过AI模型(如DeepSeek)根据用户需求自动生成代码 - 支持流式输出,实时展示代码生成过程 2. **应用管理**: - 用户可以创建、编辑、删除代码生成应用 - 支持应用分页查询和详情查看 - 管理员可以管理所有应用 3. **代码部署**: - 生成的代码可以一键部署 - Vue项目会自动构建后再部署 - 部署后生成可访问的URL 4. **对话历史管理**: - 记录用户与AI的交互历史 - 支持查看历史对话记录 5. **截图服务**: - 部署后自动为应用生成网页截图作为封面 ## 技术架构 ### 核心框架与技术栈 - **后端框架**:Spring Boot 3.5.5 - **Java版本**:Java 21 - **数据库**:MySQL + MyBatis-Flex - **AI框架**:LangChain4j - **缓存**:Redis - **前端技术**:Vue.js(前端项目独立) - **其他工具**: - Hutool(工具库) - Selenium(网页截图) - Knife4j(API文档) - Caffeine(本地缓存) ### 设计模式与架构特点 1. **门面模式(Facade Pattern)**: - [AiCodeGeneratorFacade](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/AiCodeGeneratorFacade.java#L39-L39) 类封装了AI代码生成、解析和保存的复杂流程,为外部提供简单的调用接口 2. **策略模式(Strategy Pattern)**: - 通过 [AiCodeGeneratorServiceFactory](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/ai/AiCodeGeneratorServiceFactory.java) 和 [AiCodeGeneratorService](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/ai/AiCodeGeneratorService.java) 实现不同代码生成类型的策略模式 - [CodeParserExecutor](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/parser/CodeParserExecutor.java) 和 [CodeFileSaverExecutor](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/saver/CodeFileSaverExecutor.java) 分别处理不同代码类型的解析和保存策略 3. **模板方法模式(Template Method Pattern)**: - [HtmlCodeFileSaverTemplate](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/saver/HtmlCodeFileSaverTemplate.java) 和 [MultiFileCodeFileSaverTemplate](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/saver/MultiFileCodeFileSaverTemplate.java) 定义了代码保存的通用流程,子类实现具体步骤 4. **执行器模式(Executor Pattern)**: - [CodeParserExecutor](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/parser/CodeParserExecutor.java) 和 [CodeFileSaverExecutor](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/core/saver/CodeFileSaverExecutor.java) 作为执行器,根据代码类型选择相应的处理逻辑 5. **工厂模式(Factory Pattern)**: - [AiCodeGeneratorServiceFactory](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/java/com/ithw/intelligentcodeplatform/ai/AiCodeGeneratorServiceFactory.java) 根据应用ID动态创建AI代码生成服务实例 6. **责任链模式(Chain of Responsibility Pattern)**: - 使用 LangGraph4j 实现工作流,将代码生成过程分解为多个节点(图片收集、提示词增强、路由、代码生成、项目构建) ### 代码优点 1. **模块化设计**:项目结构清晰,按照功能划分为controller、service、core、ai等模块 2. **良好的扩展性**:通过策略模式和工厂模式,可以轻松添加新的代码生成类型 3. **流式处理**:支持SSE流式输出,提供更好的用户体验 4. **异步处理**:使用虚拟线程处理耗时操作(如截图生成),提高系统响应性 5. **统一异常处理**:全局异常处理器确保系统稳定性 6. **权限控制**:基于注解的权限校验机制 7. **代码复用**:通过工具类和执行器模式,减少重复代码 ## 运行配置 ### 环境要求 - Java 21 - MySQL 8.0+ - Redis - Maven 3.6+ ### 配置步骤 1. **数据库配置**: - 创建MySQL数据库 `intelligent_code_platform` - 执行SQL脚本创建表结构(位于 [sql](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/sql) 目录下) 2. **配置文件**: - 修改 [application.yml](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/resources/application.yml) 中的数据库连接信息 - 在 [application-local.yml](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/resources/application-local.yml) 中配置AI模型API密钥和其他第三方服务密钥 3. **AI模型配置**: - 默认使用DeepSeek模型,需要在 [application-local.yml](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/resources/application-local.yml) 中配置API密钥 - 可以根据需要更换其他AI模型 4. **Redis配置**: - 确保Redis服务正常运行,并在 [application.yml](file:///Users/tianhaowen/Desktop/code/intelligent-code-platform/src/main/resources/application.yml) 中配置正确的连接信息 5. **运行项目**: ```bash mvn spring-boot:run ``` ### API文档 项目集成Knife4j,启动后可通过 `http://localhost:8123/api/doc.html` 访问API文档。