ai-native-core 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Java 后端适配器(Spring Boot)
|
|
2
|
+
|
|
3
|
+
适配目标:Java 17+ + Spring Boot 3.x + Spring Data JPA / MyBatis-Plus + Maven/Gradle
|
|
4
|
+
|
|
5
|
+
## 提供的默认模板
|
|
6
|
+
|
|
7
|
+
- 无设计因子(后端项目不需要 design-foundation)
|
|
8
|
+
- 新增:
|
|
9
|
+
- api-contract.md:RESTful 规范、统一响应体、分页格式、错误码
|
|
10
|
+
- database-rules.md:JPA/MyBatis 约束、migration 规范、N+1 防范
|
|
11
|
+
- security-rules.md:Spring Security、JWT、RBAC、输入校验
|
|
12
|
+
- architecture-paradigm.md:分层架构、依赖注入、事务边界
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Java 后端(Spring Boot)— 架构不变性规则
|
|
2
|
+
|
|
3
|
+
以下规则由适配器内置,定义了 Spring Boot 项目的基础架构边界。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 分层架构
|
|
8
|
+
|
|
9
|
+
- 禁止 Controller 层直接操作数据库(必须通过 Service → Repository)
|
|
10
|
+
- 禁止 Service 层之间循环依赖(必须通过接口 + 事件解耦)
|
|
11
|
+
- 禁止跨层调用(Controller → Repository 跳过 Service)
|
|
12
|
+
- 禁止在 Entity/Domain 对象中引入 Web 层依赖
|
|
13
|
+
- 禁止在 Mapper/Repository 层编写业务逻辑
|
|
14
|
+
|
|
15
|
+
## 事务管理
|
|
16
|
+
|
|
17
|
+
- 禁止在 Controller 层使用 @Transactional
|
|
18
|
+
- 禁止在 private 方法上使用 @Transactional(AOP 不生效)
|
|
19
|
+
- 禁止在同一个 Service 类中自调用 @Transactional 方法
|
|
20
|
+
- 禁止在只读查询中使用默认事务传播级别(必须 readOnly = true)
|
|
21
|
+
- 禁止忽略 @Transactional 的 rollbackFor(必须显式声明 rollbackFor = Exception.class)
|
|
22
|
+
|
|
23
|
+
## 异常处理
|
|
24
|
+
|
|
25
|
+
- 禁止在 Service 层 catch 异常后不处理也不重新抛出
|
|
26
|
+
- 禁止在 Controller 层使用 try-catch 返回不同结构响应体(必须用 @ControllerAdvice)
|
|
27
|
+
- 禁止将数据库异常直接暴露给前端
|
|
28
|
+
|
|
29
|
+
## API 契约
|
|
30
|
+
|
|
31
|
+
- 禁止修改已发布 API 的请求/响应字段名或类型(breaking change 必须走 /api/v2/)
|
|
32
|
+
- 禁止在响应体中直接返回 Entity 对象(必须通过 DTO/VO 转换)
|
|
33
|
+
- 禁止使用 Map<String, Object> 作为 API 响应体
|
|
34
|
+
- 禁止在 GET 请求中使用 @RequestBody
|
|
35
|
+
|
|
36
|
+
## 安全
|
|
37
|
+
|
|
38
|
+
- 禁止在代码或配置文件中硬编码密钥、token、密码
|
|
39
|
+
- 禁止在 Controller 中手动解析 JWT(必须使用 Spring Security filter chain)
|
|
40
|
+
- 禁止绕过 SecurityContext 直接获取用户信息
|
|
41
|
+
- 禁止在日志中输出完整 JWT token、密码或身份证号
|
|
42
|
+
|
|
43
|
+
## 数据库操作
|
|
44
|
+
|
|
45
|
+
- 禁止在循环中执行数据库查询(N+1 问题)
|
|
46
|
+
- 禁止在 JPA Entity 中使用 FetchType.EAGER(@OneToMany/@ManyToMany)
|
|
47
|
+
- 禁止在 MyBatis XML mapper 中拼接动态 SQL 而不使用 `<where>` / `<if>` 防注入
|
|
48
|
+
- 禁止生产环境使用 ddl-auto: create / create-drop
|
|
49
|
+
- 禁止 migration 脚本中使用 DROP TABLE / DROP COLUMN 不经审批
|
|
50
|
+
- 禁止使用 SELECT *
|
|
51
|
+
|
|
52
|
+
## 依赖注入
|
|
53
|
+
|
|
54
|
+
- 禁止在 @Service/@Component 类中使用 new 创建依赖对象
|
|
55
|
+
- 禁止使用字段注入(@Autowired on field),必须使用构造器注入
|
|
56
|
+
- 禁止在非 Spring 管理的类中使用 @Autowired
|
|
57
|
+
|
|
58
|
+
## 测试
|
|
59
|
+
|
|
60
|
+
- 禁止单元测试启动完整 Spring 上下文(必须用 @WebMvcTest / @DataJpaTest)
|
|
61
|
+
- 禁止测试之间共享可变状态
|
|
@@ -18,7 +18,7 @@ description = ""
|
|
|
18
18
|
# =============================================================================
|
|
19
19
|
[stack]
|
|
20
20
|
# 适配器 ID,决定默认模板和规则
|
|
21
|
-
# 可选值:react-spa | nextjs | vue |
|
|
21
|
+
# 可选值:react-spa | nextjs | vue | backend-go | backend-python | backend-java
|
|
22
22
|
adapter = "react-spa"
|
|
23
23
|
|
|
24
24
|
# 包管理器:pnpm | npm | yarn | bun
|
|
@@ -30,7 +30,7 @@ css = "tailwind-v4"
|
|
|
30
30
|
# UI 组件库(前端项目):shadcn | radix | mui | antd | none
|
|
31
31
|
ui_library = "shadcn"
|
|
32
32
|
|
|
33
|
-
# 测试框架:vitest | jest | playwright | go-test | pytest
|
|
33
|
+
# 测试框架:vitest | jest | playwright | go-test | pytest | junit
|
|
34
34
|
test_framework = "vitest"
|
|
35
35
|
|
|
36
36
|
# TypeScript(前端/Node 项目)
|
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-native-core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "让任何项目拥有 AI Native 开发能力的运行时框架",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai-native",
|
|
7
|
+
"ai-agent",
|
|
8
|
+
"claude-code",
|
|
9
|
+
"developer-tools"
|
|
10
|
+
],
|
|
6
11
|
"license": "MIT",
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/xxin1438-lang/ai-native-core.git"
|
|
14
|
+
"url": "git+https://github.com/xxin1438-lang/ai-native-core.git"
|
|
10
15
|
},
|
|
11
16
|
"bin": {
|
|
12
|
-
"ai-native": "
|
|
17
|
+
"ai-native": "bin/ai-native.js"
|
|
13
18
|
},
|
|
14
19
|
"files": [
|
|
15
20
|
"bin/",
|
package/src/commands/init.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
const VALID_STACKS = ['react-spa', 'nextjs', 'vue', 'backend-go', 'backend-python'];
|
|
6
|
+
const VALID_STACKS = ['react-spa', 'nextjs', 'vue', 'backend-go', 'backend-python', 'backend-java'];
|
|
7
7
|
|
|
8
8
|
function run(args) {
|
|
9
9
|
const idx = args.indexOf('--stack');
|