Skip to content

Commit 98fb898

Browse files
wklkenCopilot
authored andcommitted
feat(AGENTS.md): add AGENTS.md for all src projects (TencentBlueKing#2438)
* feat(AGENTS.md): add AGENTS.md for all src projects * Update src/dashboard/AGENTS.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/mcp-proxy/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 93cf107 commit 98fb898

6 files changed

Lines changed: 407 additions & 1 deletion

File tree

src/core-api/AGENTS.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# AGENTS.md
2+
3+
Guidance for coding agents working on the core-api service (BlueKing API Gateway).
4+
5+
## Overview
6+
- Go service (module `core`, Go 1.24.4) using Gin + Cobra.
7+
- Entry: `main.go` -> `cmd/root.go` (`core-api` CLI).
8+
- Config required via `-c/--config` (see `config.yaml.tpl`).
9+
10+
## Architecture (strict flow)
11+
`pkg/api/{microgateway,open}` -> `pkg/service` -> `pkg/cacheimpls` -> `pkg/database/dao` -> `pkg/database`
12+
13+
Support packages: `pkg/server`, `pkg/middleware`, `pkg/config`, `pkg/logging`, `pkg/metric`, `pkg/trace`, `pkg/sentry`, `pkg/util`, `pkg/version`.
14+
15+
## HTTP surface
16+
- Ops: `/ping`, `/healthz` (checks all configured DBs), `/metrics` (Prometheus).
17+
- Swagger: `/swagger/*any` only when `config.debug` is true.
18+
- MicroGateway (`/api/v1/micro-gateway`):
19+
- `GET /:micro_gateway_instance_id/permissions/`
20+
- `GET /:micro_gateway_instance_id/public_keys/`
21+
- `POST /:micro_gateway_instance_id/release/:publish_id/events/`
22+
- Middleware: `APILogger`, `MicroGatewayInstanceMiddleware` (instance ID/secret).
23+
- Open API:
24+
- `/api/v1/open` and `/api/v2/open`
25+
- `GET /gateways/:gateway_name/public_key/`
26+
- Middleware: `BkGatewayJWTAuthMiddlewareV1/V2`.
27+
- Global middleware: `RequestID`, `Metrics`, Sentry recovery; optional OTel gin instrumentation when tracing enabled.
28+
29+
## Caching (cache-first)
30+
- `CacheWithFallback` (`pkg/cacheimpls/cache_with_fallback.go`) wraps `gopkg/cache/memory` with gocache fallback.
31+
- Fallback is used only on non-`sql.ErrNoRows` errors; fallback TTL > primary TTL.
32+
- Primary + fallback TTLs:
33+
- `gateway` 2h + 24h
34+
- `stage` 5m + 12h
35+
- `release` 1m + 12h
36+
- `release_history` 1m + 12h
37+
- `app_gateway_permission` 1m + 12h
38+
- `app_resource_permission` 1m + 12h
39+
- Non-fallback caches: `jwt_public_key` 12h, `resource_version_mapping` 12h.
40+
- `publishEventCache`: in-memory gocache 10m TTL.
41+
- Random extra expiration is added to reduce thundering herd.
42+
43+
## Configuration
44+
- `config.yaml` is required (`-c`); template: `config.yaml.tpl`.
45+
- Required fields: `auth.id`, `auth.secret`, and a `databases` entry with id `apigateway`.
46+
- Key sections: `server`, `auth`, `databases` (supports TLS), `logger`, `tracing`, `sentry`, `debug`.
47+
48+
## Dev commands (Makefile)
49+
- Setup: `make init`, `make dep`
50+
- Build/run: `make build`, `make serve`, `make dev-image`
51+
- Tests: `make test`, `make cov`
52+
- Quality: `make fmt`, `make lint`, `make check-license`
53+
- Codegen: `make mock`, `make doc`
54+
55+
## Tests & Codegen
56+
- Tests use vendor mode (`-mod=vendor`) and Ginkgo/Gomega.
57+
- `make mock` runs `go generate ./...` for `mockgen` directives.
58+
- `make doc` runs `swag init`.
59+
60+
## License
61+
- All non-vendor, non-mock Go files must include the TencentBlueKing license header (checked by `make lint`/`make check-license`).

src/dashboard-front/AGENTS.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# AGENTS.md
2+
3+
## Project Overview
4+
5+
BlueKing API Gateway Dashboard Frontend — a Vue 3 + TypeScript SPA for managing API gateways, resources, stages, permissions, plugins, MCP servers, and more. Part of the larger `blueking-apigateway` monorepo under `src/dashboard-front/`.
6+
7+
## Commands
8+
9+
```bash
10+
# Development (Vite dev server on dev-t.paas3-dev.bktencent.com:8888, basic SSL enabled)
11+
npm run dev
12+
13+
# Preview (uses index.dev.html)
14+
npm run preview
15+
16+
# Production build (type-check + vite build, runs in parallel)
17+
npm run build
18+
19+
# Build without type checking
20+
npm run build-only
21+
22+
# Type checking only
23+
npm run type-check # vue-tsc --build
24+
25+
# Lint (runs oxlint then eslint sequentially)
26+
npm run lint
27+
28+
# Lint individually
29+
npm run lint:oxlint # oxlint . --fix -D correctness --ignore-path .gitignore
30+
npm run lint:eslint # eslint . --fix
31+
```
32+
33+
No test framework is configured — there are no unit or e2e tests.
34+
35+
## Architecture
36+
37+
### Entry & Bootstrap
38+
39+
- `main.ts` — Creates Vue app, installs Pinia, Vue Router, bkui-vue (full import), vue-i18n, mavon-editor, XSS filter directive, and registers global components (`AgIcon`, `IconButton`, `CopyButton`, `CardContainer`).
40+
- `App.vue` — Root layout with `BkNavigation` (top-bottom nav), header menu, language toggle, user info. Fetches environment config and user info on route changes. Feature flags control menu visibility.
41+
- HTML entry points: `index.dev.html` / `index.prod.html` — the `replace-index-html.js` script copies the appropriate one to `index.html` before dev/build (backs up existing `index.html`).
42+
- Build also includes `default.html` as a secondary Rollup input (see `vite.config.ts`).
43+
44+
### Routing (`src/router/index.ts`)
45+
46+
Each feature module exports its own route factory function (e.g., `getStageManagementRoutes()`). Main structure:
47+
- `/` — Home (gateway list)
48+
- `/:id` — Gateway detail layout (`src/layout/my-gateway/`), children: stage-management, resource-management, basic-info, backend-services, permission, operate-data, online-debugging, audit-log, monitor-alarm, mcp-server
49+
- `/platform-tools`, `/mcp-market`, `/components`, `/docs` — Top-level sections with their own layouts under `src/layout/`
50+
51+
### State Management (`src/stores/`)
52+
53+
Pinia stores, all re-exported from `src/stores/index.ts`:
54+
- `useEnv` — Environment config (BK_DASHBOARD_URL, site paths)
55+
- `useUserInfo` — Current user & tenant info
56+
- `useFeatureFlag` — Feature flag toggles
57+
- `useGateway` — Current gateway data (central to most views)
58+
- `useStage`, `usePermission`, `useAccessLog`, `useAuditLog`, `useResourceVersion`, `useResourceSetting`, `useStaff`
59+
60+
### API Layer (`src/services/`)
61+
62+
- `http/index.ts` — Exports an HTTP handler with methods: `get`, `post`, `put`, `patch`, `delete`, `download`. Each call creates a `Request` instance that goes through axios with request/response middleware.
63+
- `http/lib/request.ts` — Core request class. Supports caching, cancel tokens, upload progress, and permission-based error handling (`page` | `dialog` | `catch`).
64+
- `source/*.ts`~28 service modules (gateway, resource, stage, permission, mcp-server, mcp-market, plugin-manage, etc.). Each defines API functions that call `http.get('/gateways/...', params)`.
65+
66+
### UI Components
67+
68+
Two UI libraries in use:
69+
- **bkui-vue** (BlueKing UI) — Primary component library, fully imported
70+
- **tdesign-vue-next** (via `@blueking/tdesign-ui`) — Used for advanced tables and some form components
71+
72+
Custom components in `src/components/` follow `ag-*` naming: `ag-icon`, `ag-editor`, `ag-table`, `ag-dropdown`, `ag-sideslider`, `ag-mcp-card`, etc.
73+
74+
### Hooks (`src/hooks/`)
75+
76+
Composables for common patterns (see `src/hooks/index.ts`): `use-query-list` (paginated data), `use-selection-data` (table selection), `use-table-filter-change`, `use-table-sort-change`, `use-sidebar` (drawer state), `use-gate-way-data` (gateway list with search), `use-max-table-limit` (viewport-based pagination), `use-date-picker`, `use-tdesign-selection`, `use-stage-data`, `use-text-getter`, `use-table-setting`, `use-sticky-bottom`, `use-operation-lock`, `use-mcp-config-divide-ratio`, `use-bk-user-display-name`.
77+
78+
### i18n (`src/locales/`)
79+
80+
vue-i18n with Composition API mode. Locale files live in `src/locales/cn.json` and `src/locales/en.json`, mapped to `zh-cn` (default/fallback) and `en`. Language set via `blueking_language` cookie. Use `t('key')` from the exported `t` function or `useI18n()` (auto-imported).
81+
82+
### Styling
83+
84+
- SCSS for component/global styles (`src/styles/`)
85+
- UnoCSS with Tailwind v3 preset (`uno.config.ts`) for utility classes
86+
- CSS class naming: kebab-case (`^[a-z][a-z0-9_-]+$`, enforced by stylelint)
87+
88+
## Code Style Rules
89+
90+
Enforced by ESLint flat config (`eslint.config.ts`) + oxlint + stylelint:
91+
92+
- **Semicolons required**, single quotes, 2-space indent, 120-char max line length
93+
- **Trailing commas** in multiline (comma-dangle: always-multiline)
94+
- **Sort imports** (declaration sort ignored, member sort enforced)
95+
- **No duplicate imports**
96+
- **Vue**: `<script setup>` with TypeScript. Macro order: `defineOptions``defineModel``defineProps``defineEmits``defineSlots`, `defineExpose` last. Emits declared as type-literal. Props destructuring enforced. Multi-word component names rule disabled.
97+
- **Object/array formatting**: newlines enforced for multiline objects/arrays, consistent bracket newlines
98+
99+
## Commit Conventions
100+
101+
Conventional commits enforced by commitlint. Allowed types: `feat`, `fix`, `perf`, `style`, `docs`, `test`, `refactor`, `build`, `ci`, `chore`, `revert`, `wip`, `workflow`, `types`.
102+
103+
Pre-commit hook runs lint-staged (ESLint --fix on staged `.{js,jsx,ts,tsx,vue}` files).
104+
105+
## Path Aliases
106+
107+
`@``./src` (configured in both vite.config.ts and tsconfig.app.json). Also `bkui-lib``bkui-vue/lib`.
108+
109+
## Auto-Imports
110+
111+
`vue`, `vue-router`, and `useI18n` from `vue-i18n` are auto-imported via `unplugin-auto-import` — no need to explicitly import `ref`, `computed`, `watch`, `onMounted`, `useRouter`, etc. Type declarations generated at `src/types/auto-imports.d.ts`.
112+
113+
## Key Patterns
114+
115+
- **Service functions** take a base path and call `http.get(url, params, payload)`. The `payload` object can include `cache`, `timeout`, `permission` (error handling strategy), and `onUploadProgress`.
116+
- **Views** are organized as feature modules in `src/views/<feature>/`, each with its own `route.ts` and sub-components.
117+
- **Layouts** in `src/layout/` provide the sidebar navigation for each top-level section (my-gateway, platform-tools, mcp-market, etc.).
118+
- **Global components** registered in `main.ts`: `AgIcon`, `IconButton`, `CopyButton`, `CardContainer` — available without import.
119+
- **Custom element**: `<bk-user-display-name>` is treated as a custom element (not parsed as Vue component) in the Vue template compiler config.

src/dashboard/AGENTS.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# AGENTS.md
2+
3+
This file provides guidance for coding agents and automation tools when working with code in this repository.
4+
5+
## Project Overview
6+
7+
BlueKing API Gateway Dashboard — the Django-based control plane for managing API gateways. The data plane uses Apache APISIX. This is the `dashboard` component in a monorepo (siblings: `dashboard-front`, `core-api`, `mcp-proxy`, `esb`).
8+
9+
- Python >=3.11,<3.12, Django 4.2, DRF 3.16
10+
- Dependency management: `uv` (lockfile: `uv.lock`, config: `pyproject.toml`)
11+
- The Django project root is `apigateway/` (contains `manage.py`); the Python package is `apigateway/apigateway/`
12+
13+
## Common Commands
14+
15+
```bash
16+
# Bootstrap local dev env (installs uv, pre-commit, mypy types)
17+
make init
18+
19+
# Install dependencies
20+
uv sync
21+
22+
# Run all tests (uses SQLite, parallel via pytest-xdist)
23+
make test
24+
25+
# Run a single test file or test
26+
cd apigateway && export PYTHONDONTWRITEBYTECODE=1 && . apigateway/conf/unittest_env && \
27+
pytest --ds apigateway.settings --reuse-db -n auto --dist loadscope \
28+
apigateway/apigateway/tests/path/to/test_file.py::TestClass::test_method -v
29+
30+
# Re-run only last-failed tests
31+
make test-lf
32+
33+
# Debug with pdb (single-process, stops on first failure)
34+
make test-pdb
35+
36+
# Run tests with coverage
37+
make test-cov
38+
39+
# Lint (auto-fix + type check + import layer check)
40+
make lint
41+
42+
# Lint (check only, no auto-fix — used in CI)
43+
make lint-check
44+
45+
# Run Django dev server
46+
cd apigateway && python manage.py runserver
47+
```
48+
49+
## Linting Stack
50+
51+
All configured in `pyproject.toml`:
52+
- **ruff** — formatter + linter (line-length 119)
53+
- **mypy** — strict optional, excludes `editions/` and migrations
54+
- **import-linter** (via `lint-imports`) — enforces layered architecture contracts (run from `apigateway/` dir)
55+
56+
`make lint` runs: ruff format → ruff check → mypy → lint-imports.
57+
58+
## Architecture (import-linter enforced layers)
59+
60+
```
61+
apis → biz → controller → service → components → apps → core → common → utils
62+
```
63+
64+
Upper layers may import lower layers only. Violations break `make lint-check`.
65+
66+
### Layer responsibilities
67+
68+
| Layer | Purpose |
69+
|---|---|
70+
| `apis/` | DRF views — three independent API surfaces: `web` (UI), `open` (v1 OpenAPI), `v2` (inner/sync/open) |
71+
| `biz/` | Business logic orchestration (handlers, not models) |
72+
| `controller/` | Release pipeline — converts domain objects into APISIX config via convertor/transformer/distributor |
73+
| `service/` | Shared services (ES, Prometheus, SDK generation, alert flows) |
74+
| `components/` | HTTP clients to external BlueKing systems (bkauth, bkpaas, bkmonitor, etc.) |
75+
| `apps/` | Django apps with models, admin, management commands (gateway, plugin, permission, esb, mcp_server, etc.) |
76+
| `core/` | Central domain models: Gateway, Stage, Resource, ResourceVersion, Release, Backend, Context |
77+
| `common/` | Shared utilities, mixins, permissions, error codes, middleware, encryption |
78+
| `utils/` | Pure utility functions |
79+
80+
The three API modules (`apis.open`, `apis.web`, `apis.v2.*`) are enforced as independent — they cannot import from each other.
81+
82+
### Domain model chain
83+
84+
```
85+
Gateway → Stage → Resource → ResourceVersion → Release → ReleaseHistory
86+
```
87+
88+
Plugins bind at stage/resource scope via `PluginBinding`. Auth settings live in `Context` records. Backends (upstream configs) are per-gateway with stage-specific `BackendConfig`.
89+
90+
## Settings
91+
92+
Settings are loaded dynamically: `apigateway.conf.settings_{BKPAAS_ENVIRONMENT}` (defaults to `dev`). Base config is in `apigateway/conf/default.py`. Local dev config goes in `apigateway/apigateway/conf/.env` (copy from `.env.tpl`).
93+
94+
Tests source `apigateway/conf/unittest_env` which uses SQLite. Alternate env files exist for MySQL and multi-tenant testing.
95+
96+
## Testing Patterns
97+
98+
- Tests mirror source structure under `apigateway/apigateway/tests/`
99+
- Use `ddf` (django-dynamic-fixture) `G()` to create model instances
100+
- Key fixtures in `apigateway/apigateway/tests/conftest.py`: `fake_gateway`, `fake_stage`, `fake_backend`, `fake_resource`, `fake_admin_user`, `request_factory`
101+
- Test settings: `--ds apigateway.settings`, `--reuse-db` for speed, `-n auto --dist loadscope` for parallel
102+
- Tests use two databases: `default` (apigateway) and `bkcore` (ESB)
103+
104+
## Edition System (EE/TE)
105+
106+
The project supports multiple editions (Enterprise/Tencent) via `editionctl`. Edition-specific code lives under `apigateway/apigateway/editions/{ee,te}/` and is symlinked into the main package tree.
107+
108+
```bash
109+
make edition # show current
110+
make edition-te # switch to TE
111+
make edition-ee # switch to EE
112+
make edition-develop # develop mode
113+
make edition-reset # clear edition symlinks
114+
make edition-modules # create __init__.pyi files for mypy compatibility
115+
```
116+
117+
## Naming Convention: Gateway vs API
118+
119+
Legacy code uses `API`/`api`/`api_id` to refer to gateways. All new code must use `Gateway`. The `api` naming persists in:
120+
- DB columns and ORM foreign keys (`api=`, `api_id=`)
121+
- Some frontend request/response payloads

src/esb/AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# AGENTS.md
2+
3+
4+
IT'S ABANDONED! DO NOT NEED TO READ OR UPDATE FILES UNDER CURRENT DIR!

0 commit comments

Comments
 (0)