|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +AI-specific guidance for working with the nmstate-console-plugin codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is an OpenShift console dynamic plugin for kubernetes-nmstate. It provides UI views for managing node network configuration policies, states, physical networks, and topology visualization. |
| 8 | + |
| 9 | +**Stack:** React 18, TypeScript, PatternFly 6, OpenShift Dynamic Plugin SDK, Webpack, i18next |
| 10 | + |
| 11 | +## Repository Structure |
| 12 | + |
| 13 | +```text |
| 14 | +src/ |
| 15 | +├── console-models/ # K8s resource model definitions (K8sModel objects) |
| 16 | +├── nmstate-types/ # NMState CRD types and custom models |
| 17 | +├── utils/ |
| 18 | +│ ├── components/ # Shared UI components (Loading, HelpTextIcon, etc.) |
| 19 | +│ ├── hooks/ # Shared React hooks (useNMStateTranslation, etc.) |
| 20 | +│ ├── flags/ # Feature flag detection (NMState operator presence) |
| 21 | +│ ├── resources/ # K8s resource fetching utilities |
| 22 | +│ └── telemetry/ # Usage tracking |
| 23 | +├── views/ |
| 24 | +│ ├── policies/ # NodeNetworkConfigurationPolicy CRUD |
| 25 | +│ │ ├── manifest.ts # Plugin extension registration |
| 26 | +│ │ ├── list/ # List page component |
| 27 | +│ │ ├── details/ # Details page component |
| 28 | +│ │ ├── new/ # Create/edit form |
| 29 | +│ │ ├── actions/ # Action menu items |
| 30 | +│ │ └── components/ # Policy-specific UI components |
| 31 | +│ ├── states/ # NodeNetworkState list + details |
| 32 | +│ ├── physical-networks/ # Physical network overview |
| 33 | +│ └── nodenetworkconfiguration/ # Topology visualization (PatternFly Topology) |
| 34 | +├── __mocks__/ # Jest mocks for SDK and i18n |
| 35 | +└── plugin-manifest.ts # Root plugin metadata and extension aggregation |
| 36 | +``` |
| 37 | + |
| 38 | +## Key Patterns |
| 39 | + |
| 40 | +### Plugin extension registration |
| 41 | + |
| 42 | +Each view has a `manifest.ts` that exports: |
| 43 | +- `{View}ExposedModules` — maps module names to file paths for code splitting |
| 44 | +- `{View}Extensions` — array of `EncodedExtension` objects defining console nav items, pages, and templates |
| 45 | + |
| 46 | +These are aggregated in the root `plugin-manifest.ts`. |
| 47 | + |
| 48 | +### K8s resource models |
| 49 | + |
| 50 | +Models live in `src/console-models/` as individual files exporting `K8sModel` objects. Each model defines `apiGroup`, `apiVersion`, `kind`, `plural`, and a `GroupVersionKind` constant. Import models via `@models` path alias. |
| 51 | + |
| 52 | +### Path aliases |
| 53 | + |
| 54 | +Defined in `tsconfig.json`: |
| 55 | +- `@images/*` → `images/*` |
| 56 | +- `@utils/*` → `src/utils/*` |
| 57 | +- `@models` → `src/console-models/index.ts` |
| 58 | + |
| 59 | +### React components & i18n |
| 60 | + |
| 61 | +For coding standards (component rules, PatternFly usage, i18n, linting), see [CONTRIBUTING.md](CONTRIBUTING.md#coding-standards). |
| 62 | + |
| 63 | +Key details for code generation: |
| 64 | +- Translation keys use the `plugin__nmstate-console-plugin~` prefix |
| 65 | +- In manifest files, use `%plugin__nmstate-console-plugin~Label%` syntax for nav item names |
| 66 | +- Shared hooks (used in 2+ components) live in `src/utils/hooks/`; single-use hooks must be co-located with the component that uses them — do not add to shared utils |
| 67 | +- One component per file — utility functions, types (aside from props), and constants go in a `utils/` folder within the component's directory |
| 68 | +- Prefer PatternFly utility classes (e.g., `pf-v6-u-mt-md`) over custom CSS for spacing and layout |
| 69 | + |
| 70 | +### State management |
| 71 | + |
| 72 | +- No global state library — uses OpenShift SDK's `useK8sWatchResource` for K8s data |
| 73 | +- Local component state via React `useState`/`useReducer` |
| 74 | + |
| 75 | +## Conventions |
| 76 | + |
| 77 | +For full coding standards, linting rules, testing, and PR process, see [CONTRIBUTING.md](CONTRIBUTING.md). |
| 78 | + |
| 79 | +### File & directory naming |
| 80 | +- React components: `PascalCase.tsx` |
| 81 | +- Utilities, hooks, constants: `camelCase.ts` |
| 82 | +- Directories for components use PascalCase, directories for hooks use camelCase, all other directories use kebab-case |
| 83 | +- Each view directory has a `manifest.ts`, `constants.ts`, and optionally `utils.ts` |
| 84 | + |
| 85 | +### Deployment |
| 86 | +- Webpack builds the plugin as a dynamic console remote module |
| 87 | +- Deployed via Helm chart (`deployment/nmstate-console-plugin/`) or OpenShift templates (`oc-manifest.yaml`) |
| 88 | +- Container images published to `quay.io/nmstate/nmstate-console-plugin` |
| 89 | + |
| 90 | +## Review Guidelines |
| 91 | + |
| 92 | +When reviewing changes to this codebase: |
| 93 | + |
| 94 | +1. **SDK compatibility** — verify that `@openshift-console/dynamic-plugin-sdk` APIs are used correctly; the SDK version must match the target release branch (e.g., `release-4.22` uses SDK 4.22.x) |
| 95 | +2. **i18n** — all user-visible strings must use the `useNMStateTranslation` hook or the `Trans` component; never hardcode English text |
| 96 | +3. **PatternFly** — use PatternFly components and PF utility classes instead of custom HTML/CSS; follow PatternFly 6 patterns |
| 97 | +4. **Type safety** — `strict` is `false` in tsconfig, but new code should use explicit types |
| 98 | +5. **Model consistency** — new K8s resources need a model in `console-models/`, a manifest entry, and registration in `plugin-manifest.ts` |
| 99 | +6. **No direct K8s API calls** — use the OpenShift SDK hooks (`useK8sWatchResource`, `k8sCreate`, `k8sPatch`, etc.) |
| 100 | +7. **Component isolation** — one component per file; single-use hooks stay co-located with their component, not in shared `utils/hooks/` |
| 101 | +8. **Naming conventions** — new resource utility files should use `selectors.ts` (not `getters.ts`); some older directories still use `getters.ts` but the project is migrating to the `selectors` naming |
0 commit comments