|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +## Project Purpose & Structure |
| 4 | +This repository contains the **Sysdig Plugin for Backstage**, a frontend plugin that integrates Sysdig Secure vulnerability and posture reports into the Backstage service catalog. |
| 5 | + |
| 6 | +**Key Directories:** |
| 7 | +- **`src/`**: Source code root. |
| 8 | + - **`api/`**: `SysdigApiClient` implementation using `fetchApi`. |
| 9 | + - **`components/`**: React components. |
| 10 | + - `SysdigComponent`: Main dashboard. |
| 11 | + - `Sysdig*FetchComponent`: Individual data widgets (Runtime, Registry, Pipeline, Posture). |
| 12 | + - **`lib/`**: Helpers, constants, and annotation definitions (`annotations.ts`). |
| 13 | +- **`dev/`**: Local development harness using `createDevApp` and mock data. |
| 14 | +- **`img/`**: Assets for documentation. |
| 15 | + |
| 16 | +**Tech Stack:** React, TypeScript, Backstage Plugin API, Material UI. |
| 17 | +**Package Manager:** Yarn. |
| 18 | + |
| 19 | +## Build, Test, & Development |
| 20 | +- **`just install`**: Install dependencies. |
| 21 | +- **`just start`**: Starts the local development server at `http://localhost:3000`. Uses `dev/index.tsx` for context. If address is still in use use `fuser -k 3000/tcp`. |
| 22 | +- **`just test`**: Runs unit tests using Jest. |
| 23 | +- **`just lint`**: Runs ESLint to check code quality. |
| 24 | +- **`just build`**: Builds the plugin for distribution. |
| 25 | +- **`just bump`**: Updates dependencies (requires Nix/Just). |
| 26 | + |
| 27 | +## Onboarding & Known Issues |
| 28 | +**Crucial setup details for new contributors:** |
| 29 | +1. **Package Manager**: Strictly use **Yarn** (wrapped via `just`). |
| 30 | +2. **Dev Dependencies**: If `just start` fails, ensure `react`, `react-dom`, and `react-router-dom` (v6) are explicitly in `devDependencies`. |
| 31 | +3. **Configuration**: `app-config.yaml` is not committed but required for `just start`. Create it with standard proxy settings if missing. |
| 32 | +4. **Entity Context**: The plugin crashes if run in isolation because it uses `useEntity`. The `dev/index.tsx` **must** wrap `SysdigPage` in an `<EntityProvider>` with a valid mock entity object. |
| 33 | +5. **Data & Auth**: Without `SYSDIG_SECURE_TOKEN`, requests fail. For UI work, override `sysdigApiRef` with a **Mock Client** in `dev/index.tsx` (see `dev/MockSysdigClient.ts`). |
| 34 | +6. **Test Execution**: `yarn test` defaults to watch mode and will hang indefinitely. **Always use `just test`** (or `yarn test --watchAll=false`) for a single-run execution. |
| 35 | + |
| 36 | +## Coding Style & Naming |
| 37 | +- **Language**: TypeScript (`.ts`, `.tsx`). Strict mode enabled. |
| 38 | +- **Components**: Functional components with Hooks (`useEntity`, `useAsync`, `useApi`). |
| 39 | +- **Styling**: Use Material UI (`@mui/material`) and Backstage core components (`@backstage/core-components`). |
| 40 | +- **Naming**: PascalCase for components (`SysdigComponent`), camelCase for functions/vars. |
| 41 | +- **Imports**: Prefer relative imports within `src/` but use strict package imports for external deps. |
| 42 | + |
| 43 | +## Testing Guidelines |
| 44 | +- **Framework**: Jest + React Testing Library + MSW (Mock Service Worker). |
| 45 | +- **Location**: Tests are co-located with source files (e.g., `SysdigComponent.test.tsx`). |
| 46 | +- **Requirement**: Components must be tested for rendering and error states. Use `setupRequestMockHandlers` for API mocking. |
| 47 | + |
| 48 | +## Commit & PR Guidelines |
| 49 | +- **Commits**: Follow **Conventional Commits** format: |
| 50 | + - `feat(scope): description` |
| 51 | + - `fix(scope): description` |
| 52 | + - `chore: description` |
| 53 | +- **Pull Requests**: |
| 54 | + - Title must match the commit format. |
| 55 | + - Include screenshots for UI changes. |
| 56 | + - Ensure `just test` and `just lint` pass before requesting review. |
| 57 | + |
| 58 | +## Release Process |
| 59 | +The release process is semi-automated: |
| 60 | +1. **Manual Version Bump**: Before creating a release, the `version` field in `package.json` must be manually updated (e.g., from `1.3.2` to `1.3.3`). |
| 61 | +2. **Automated Release**: Once the version is manually updated and pushed to the `main` branch, the GitHub Actions workflow (`.github/workflows/release.yaml`) automatically: |
| 62 | + * Creates a new GitHub Release with the updated version. |
| 63 | + * Publishes the package to NPM. |
| 64 | + |
| 65 | +## Documentation Maintenance |
| 66 | +- Keep `README.md` updated with new annotations or configuration options. |
| 67 | +- Maintain this `AGENTS.md` to reflect architectural changes. |
| 68 | +- **Agent Note**: If `src/lib/annotations.ts` changes, update the "How to annotate services" section in `README.md`. |
0 commit comments