feat: complete Kra admin backend migration

This commit is contained in:
2026-08-14 00:28:37 +08:00
parent c4bf7ee03b
commit acba9624d7
88 changed files with 1765 additions and 8623 deletions
+46 -56
View File
@@ -1,67 +1,57 @@
# Kratos Admin Template
# Kra
## Best Practice
Google AIP(https://google.aip.dev/general):
1. Resource-oriented design
2. Filtering
3. Pagination
4. Field masks
5. Field behavior
Kra 是基于 Kratos 生命周期与 Wire 依赖注入、使用 Gin 提供管理端 HTTP API 的前后端管理系统。
## 目录
```text
cmd/kratos-admin/ 服务入口与 Wire
configs/ 运行配置
internal/biz/ 领域对象、用例和仓储接口
internal/data/ 数据库、缓存、对象存储及仓储实现
internal/server/ Gin 服务、路由和定时任务调度
internal/service/ HTTP 输入输出与领域对象转换
web/ Vue 管理端
```
## 启动后端
先修改 `configs/config.yaml`。首次启动时,如果目标数据库不可用,服务会保留初始化接口;在管理端初始化页面完成建库、建表和种子数据写入后即可登录。
```shell
go run ./cmd/kratos-admin -conf ./configs
```
默认 HTTP 地址为 `http://127.0.0.1:8000`。生产环境必须替换 JWT 签名密钥和数据库凭据。
## 启动前端
```shell
cd web
pnpm install
pnpm dev
```
构建产物和依赖目录 `web/dist/`、`web/node_modules/` 已加入 Git 忽略规则。
## 生成代码
修改 `internal/conf/conf.proto` 后执行:
## Generate API files
Proto generation is driven by [buf](https://buf.build). Dependencies such as
googleapis are resolved from the Buf Schema Registry (`buf.build/googleapis/googleapis`),
so there is no vendored `third_party/` directory.
```shell
# Install tooling (buf + wire)
make init
# Generate API files (pb.go, grpc, kratos http, openapi.yaml, web TS clients) from api/*.proto
make api
# Generate internal config (internal/conf/conf.pb.go) from internal/*.proto
make config
```
## Run Web Application
修改 Wire Provider 或构造函数后执行:
```shell
# Enter web directory, install dependencies and start development server
cd web
npm install
npm run dev
go generate ./cmd/kratos-admin
```
The generated clients work with any Promise-based HTTP client that returns JSON.
Services are defined and re-exported from this file: `web/src/services/index.ts`.
```typescript
import { createAdminServiceClient } from "@/services/kratos/admin/v1/index";
## 检查
type Request = {
path: string;
method: string;
body: string | null;
};
function requestHandler({ path, method, body }: Request) { ... }
export function createAdminService() {
return createAdminServiceClient(requestHandler);
}
```
Example using the generated client:
```typescript
import { createAdminService } from "@/services/index";
const adminService = createAdminService();
const handleLogin = async (username: string, password: string) => {
try {
const response = await adminService.Login({
username: username,
password: password,
});
console.log("Login successful:", response);
} catch (error) {
console.error("Login failed:", error);
}
};
```shell
go test ./...
go vet ./...
cd web && pnpm lint && pnpm build
```