|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +KubernetesJS is a monorepo providing a fully-typed, zero-dependency TypeScript client for the entire Kubernetes API, plus React hooks, CLIs, and operational tooling. Code is generated from the Kubernetes OpenAPI spec using `schema-sdk`. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install dependencies |
| 13 | +pnpm install |
| 14 | + |
| 15 | +# Build all packages (excludes ops-dashboard) |
| 16 | +pnpm build |
| 17 | + |
| 18 | +# Build everything including apps |
| 19 | +pnpm build:all |
| 20 | + |
| 21 | +# Lint all packages (uses eslint --fix) |
| 22 | +pnpm lint |
| 23 | + |
| 24 | +# Build a specific package |
| 25 | +pnpm --filter kubernetesjs build |
| 26 | +pnpm --filter @kubernetesjs/react build |
| 27 | + |
| 28 | +# Run tests in a specific package |
| 29 | +cd packages/kubernetesjs && pnpm test |
| 30 | +cd packages/kubernetesjs && pnpm test:watch |
| 31 | + |
| 32 | +# Run a single test file |
| 33 | +cd packages/kubernetesjs && npx jest path/to/test.ts |
| 34 | + |
| 35 | +# Regenerate TypeScript client from Kubernetes OpenAPI spec |
| 36 | +cd packages/kubernetesjs && pnpm codegen |
| 37 | +cd packages/react && pnpm codegen |
| 38 | + |
| 39 | +# Kubernetes API proxy (required for integration tests and local dev) |
| 40 | +kubectl proxy --port=8001 --accept-hosts='^.*$' --address='0.0.0.0' |
| 41 | +``` |
| 42 | + |
| 43 | +## Monorepo Structure |
| 44 | + |
| 45 | +- **pnpm workspaces** with `packages/*` and `apps/*` |
| 46 | +- **Lerna** for independent versioning and publishing |
| 47 | +- **makage** as the build tool (generates CJS + ESM dual output to `dist/`) |
| 48 | + |
| 49 | +| Package | npm name | Description | |
| 50 | +|---|---|---| |
| 51 | +| `packages/kubernetesjs` | `kubernetesjs` | Core zero-dependency K8s client | |
| 52 | +| `packages/react` | `@kubernetesjs/react` | React hooks with TanStack Query | |
| 53 | +| `packages/cli` | `@kubernetesjs/cli` | CLI tool (`k8s` / `kubernetes` commands) | |
| 54 | +| `packages/client` | `@kubernetesjs/client` | Enhanced client wrapper | |
| 55 | +| `packages/ops` | `@kubernetesjs/ops` | Ops library | |
| 56 | +| `packages/ops-cli` | `@kubernetesjs/ops-cli` | High-level ops CLI | |
| 57 | +| `packages/manifests` | `@kubernetesjs/manifests` | Curated operator manifests | |
| 58 | +| `apps/ops-dashboard` | private | Next.js dashboard UI | |
| 59 | + |
| 60 | +## Architecture |
| 61 | + |
| 62 | +### Code Generation Pipeline |
| 63 | + |
| 64 | +The core `kubernetesjs` and `@kubernetesjs/react` packages have their source generated from the Kubernetes OpenAPI spec (`swagger.json`). The codegen scripts in `packages/*/scripts/codegen.ts` use `schema-sdk` to produce `src/index.ts`. **Do not manually edit generated `src/index.ts` files in these packages** — modify the codegen scripts or `swagger.json` instead. |
| 65 | + |
| 66 | +Key codegen configuration: |
| 67 | +- Excludes beta APIs (`v1beta1`, `v2beta1`) and flowcontrol resources |
| 68 | +- Uses `namingStrategy.renameMap` to resolve type name conflicts (e.g., `EndpointPort`, `ServiceReference`) |
| 69 | +- Patches `IntOrString` to a proper `oneOf` union type |
| 70 | + |
| 71 | +### Client Architecture |
| 72 | + |
| 73 | +`KubernetesClient` takes `{ restEndpoint: string }` and provides typed methods for all K8s API operations (list, get, create, update, patch, delete, watch). The core package has zero runtime dependencies by design. |
| 74 | + |
| 75 | +### React Integration |
| 76 | + |
| 77 | +`@kubernetesjs/react` wraps the client in a React Context (`KubernetesProvider`) with TanStack Query for caching/fetching. Generated hooks follow the pattern `use{OperationName}Query` / `use{OperationName}Mutation`. |
| 78 | + |
| 79 | +### Workspace Dependencies |
| 80 | + |
| 81 | +Packages reference each other via `workspace:^` in package.json. The core `kubernetesjs` package is depended on by `react`, `cli`, `client`, `ops`, and `manifests`. |
| 82 | + |
| 83 | +## Code Style |
| 84 | + |
| 85 | +- **ESLint** with `@typescript-eslint`, `simple-import-sort`, `unused-imports`, and Prettier integration |
| 86 | +- **Prettier**: double quotes, trailing commas (es5), 2-space indent, semicolons |
| 87 | +- **ESLint enforces**: single quotes in JS/TS source (note: Prettier uses double quotes — ESLint rule takes precedence in `.ts` files) |
| 88 | +- `no-explicit-any` is off; `strictNullChecks` is off in tsconfig |
| 89 | +- Unused vars with prefix `_` or matching `React|res|next` are allowed |
| 90 | + |
| 91 | +## CI |
| 92 | + |
| 93 | +GitHub Actions runs `pnpm build` and `pnpm lint` on push/PR to `main` and `release/*` branches (Node 20, pnpm 10.12.2). |
| 94 | + |
| 95 | +## Publishing |
| 96 | + |
| 97 | +```bash |
| 98 | +pnpm install && pnpm -r build && pnpm -r test |
| 99 | +pnpm lerna version # independent versioning with conventional commits |
| 100 | +pnpm lerna publish from-package |
| 101 | +``` |
0 commit comments