|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +`@devtron-labs/devtron-fe-common-lib` is a React component and utility library for the Devtron platform. It is built with Vite and published to npm as an ES module. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Type-check + lint (strict, max-warnings=0) |
| 13 | +npm run lint |
| 14 | + |
| 15 | +# Auto-fix lint issues |
| 16 | +npm run lint-fix |
| 17 | + |
| 18 | +# Build with source maps (development/local linking) |
| 19 | +npm run build |
| 20 | + |
| 21 | +# Watch mode rebuild with source maps |
| 22 | +npm run build-watch |
| 23 | + |
| 24 | +# Build without source maps (CI/CD, publishing) |
| 25 | +npm run build-lib |
| 26 | + |
| 27 | +# Vite dev server |
| 28 | +npm run dev |
| 29 | + |
| 30 | +# Generate icon/illustration components from SVGs |
| 31 | +npm run generate-icon |
| 32 | +npm run generate-illustration |
| 33 | +``` |
| 34 | + |
| 35 | +There are no tests currently (`npm test` is a no-op). |
| 36 | + |
| 37 | +## Architecture |
| 38 | + |
| 39 | +### Entry & Exports |
| 40 | + |
| 41 | +`src/index.ts` re-exports everything from four top-level modules: |
| 42 | + |
| 43 | +- **`src/Common/`** — Legacy utilities, hooks, and components (BreadCrumb, SearchBar, Checkbox, etc.) |
| 44 | +- **`src/Shared/`** — Primary reusable code: 100+ UI components, hooks, providers, services, API utilities, types, helpers, constants, validations |
| 45 | +- **`src/Pages/`** — Full-page components (Applications, BulkEdit, GlobalConfigurations, ResourceBrowser) |
| 46 | +- **`src/Pages-Devtron-2.0/`** — New Devtron 2.0 features (ApplicationManagement, Navigation, SecurityCenter, etc.) |
| 47 | + |
| 48 | +### Component Structure Convention |
| 49 | + |
| 50 | +Components follow a consistent directory layout: |
| 51 | + |
| 52 | +``` |
| 53 | +ComponentName/ |
| 54 | +├── ComponentName.component.tsx # Main component (forwardRef + React.memo typical) |
| 55 | +├── types.ts # TypeScript interfaces/types |
| 56 | +├── constants.ts # Component-level constants |
| 57 | +├── utils.ts # Helper functions |
| 58 | +├── component.scss # Scoped SCSS styles |
| 59 | +└── index.ts # Barrel export |
| 60 | +``` |
| 61 | + |
| 62 | +### Key Architectural Patterns |
| 63 | + |
| 64 | +**State management**: React Context API only — `MainContextProvider`, `ThemeProvider`, `UserEmailProvider`. No Redux/Zustand. |
| 65 | + |
| 66 | +**API layer**: TanStack Query (React Query v4) via `CoreAPI` class. API queuing handled via `APIQueuing`. Custom query hooks live in `Shared/API/reactQueryHooks.ts`. |
| 67 | + |
| 68 | +**Styling**: SCSS with BEM naming. CSS is injected into JS chunks via `vite-plugin-lib-inject-css`. No CSS modules. |
| 69 | + |
| 70 | +**SVG icons**: Imported as React components via `vite-plugin-svgr`. Two icon generations: `src/Assets/Icon/` and `src/Assets/IconV2/`. Do **not** use `IconBase` or `IllustrationBase` directly — use the `Icon` and `Illustration` wrapper components. |
| 71 | + |
| 72 | +**Toasts**: Do **not** import from `react-toastify` directly — use `ToastManager` from the library. |
| 73 | + |
| 74 | +**Forms**: Dynamic forms use `@rjsf` (React JSON Schema Form). Custom form hooks in `Shared/Hooks/`. |
| 75 | + |
| 76 | +**Router**: React Router v6 (`useBlocker` etc.). The `usePrompt` hook handles navigation blocking. |
| 77 | + |
| 78 | +### TypeScript & Path Aliases |
| 79 | + |
| 80 | +`tsconfig.json` configures path aliases used throughout the codebase: |
| 81 | + |
| 82 | +| Alias | Maps to | |
| 83 | +| -------------------- | ------------------------- | |
| 84 | +| `@Icons/*` | `src/Assets/Icon/*` | |
| 85 | +| `@IconsV2/*` | `src/Assets/IconV2/*` | |
| 86 | +| `@Common/*` | `src/Common/*` | |
| 87 | +| `@Shared/*` | `src/Shared/*` | |
| 88 | +| `@Pages/*` | `src/Pages/*` | |
| 89 | +| `@PagesDevtron2.0/*` | `src/Pages-Devtron-2.0/*` | |
| 90 | + |
| 91 | +Strict mode is **off** in tsconfig. Target is ES2020, module is ESNext. |
| 92 | + |
| 93 | +### Build Output |
| 94 | + |
| 95 | +Vite splits the bundle into named chunks: `@vendor`, `@code-editor`, `@framer-motion`, `@moment`, `@react-select`, `@react-virtualized-sticky-tree`, `@common-rjsf`, `@src-assets-*`. Output is ES modules only, landing in `dist/`. Type declarations are generated via `vite-plugin-dts` at `dist/index.d.ts`. |
| 96 | + |
| 97 | +## Code Style |
| 98 | + |
| 99 | +- **Prettier**: No semicolons, single quotes, 120-char print width, 4-space tabs, trailing commas everywhere. |
| 100 | +- **ESLint**: Airbnb + TypeScript + Prettier. Import order enforced by `eslint-plugin-simple-import-sort`. |
| 101 | +- **Pre-commit**: `lint-staged` runs ESLint on staged `.{js,jsx,ts,tsx}` files via Husky. |
| 102 | +- JSX only in `.tsx` files (not `.jsx`). |
| 103 | +- `no-console` is a warning (not error). |
| 104 | + |
| 105 | +## CI/CD |
| 106 | + |
| 107 | +- **PRs**: Node version from `.nvmrc`, `npm ci`, `npm run lint`, `npm run build-lib`. |
| 108 | +- **Releases**: Triggered by GitHub release creation, runs `npm test` + `npm run build-lib` + `npm publish --access public` using `NPM_TOKEN` secret. |
0 commit comments