Skip to content

Commit 969b484

Browse files
NoopDogCopilot
andauthored
chore: add claude.md for (#739) (#740)
* chore: add claude.md for (#739) * Update CLAUDE.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b419e22 commit 969b484

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed

CLAUDE.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Repository Overview
6+
7+
This is a TypeScript library package (`@databiosphere/findable-ui`) that provides reusable UI components and utilities for Data Biosphere applications, particularly the Data Browser. It compiles TypeScript source from `src/` to JavaScript in `lib/` for distribution as an npm package.
8+
9+
**Key Facts:**
10+
11+
- **Node Version:** 22.12.0 (enforced by package.json)
12+
- **UI Framework:** React 18 with Material-UI v7 and Emotion for styling
13+
- **Build System:** TypeScript compiler (`tsc`) with strict mode enabled
14+
- **Import Pattern:** External apps import as `@databiosphere/findable-ui/lib/<path>`
15+
16+
## Development Commands
17+
18+
### Essential Commands
19+
20+
```bash
21+
# Install dependencies (use ci for clean install)
22+
npm ci
23+
24+
# Compile TypeScript to lib/ directory
25+
npx tsc
26+
27+
# Run all validation checks
28+
npm run check-format # Prettier formatting check
29+
npm run lint # ESLint with TypeScript and SonarJS plugins
30+
npm run test # Jest with React Testing Library
31+
npm run test-compile # TypeScript compilation check (no emit)
32+
33+
# Development tools
34+
npm run storybook # Launch Storybook on port 6006
35+
```
36+
37+
### Running Single Tests
38+
39+
```bash
40+
# Run specific test file
41+
npm test -- path/to/file.test.ts
42+
43+
# Run tests in watch mode
44+
npm test -- --watch
45+
```
46+
47+
### Local Development with Data Browser
48+
49+
When developing alongside the Data Browser:
50+
51+
1. Clone both repos in the same parent directory
52+
2. In findable-ui: `npm update && npx tsc`
53+
3. In data-browser/explorer: `npm link ../findable-ui`
54+
4. Rerun `npm link` if you install/uninstall packages (symlink gets removed)
55+
5. May need to comment out `@tanstack/react-table` in Data Browser's `next.config.mjs` webpack config
56+
57+
**Important:** Run `npx tsc` whenever you make changes to source files that need testing in consuming apps.
58+
59+
## Code Architecture
60+
61+
### Directory Structure
62+
63+
- **`/src`** - TypeScript source (compiles to `/lib`)
64+
- `/components` - React UI components (organized by feature)
65+
- `/hooks` - Custom React hooks (useAsync, useExploreMode, etc.)
66+
- `/providers` - React context providers for state management
67+
- `/theme` - MUI theme configuration
68+
- `/config` - Configuration entities and utilities
69+
- `/apis` - API client code (e.g., Azul API integration)
70+
- `/entity` - Entity service layer (api, service, common, tsv, apicf subdirectories)
71+
- `/viewModelBuilders` - Transform API responses to view models
72+
- `/views` - Page-level components
73+
- `/utils` - Utility functions
74+
- `/types` - TypeScript type definitions
75+
- `/routes` - Routing utilities
76+
- `/services` - Business logic services
77+
- `/common` - Shared utilities (analytics, categories, filters, etc.)
78+
- `/styles` - Global styles
79+
- **`/tests`** - Jest test files (separate from src, not co-located)
80+
- **`/lib`** - Compiled JavaScript output (git-ignored, generated by tsc)
81+
82+
### Key Architectural Patterns
83+
84+
**Entity Service Layer:** The `/entity` directory contains a service-oriented architecture for data fetching and transformation:
85+
86+
- `api/` - API-based entity services
87+
- `service/` - Service factory and models
88+
- `common/` - Shared client utilities
89+
- `tsv/` - TSV-specific services
90+
- `apicf/` - API custom field services
91+
92+
**Configuration-Driven Components:** Many components are driven by config objects defined in `/config/entities.ts`. This includes analytics, authentication, export methods, and layout configuration.
93+
94+
**Provider Architecture:** State management uses React Context providers (authentication, exploreState, fileManifestState, dataDictionary, etc.) located in `/providers`.
95+
96+
**Analytics:** Google Analytics 4 integration via `src/common/analytics/`. Events are defined in entities.ts and tracked via the `track` function. See `src/common/analytics/readme-analytics.md` for event inventory.
97+
98+
## Code Style Requirements
99+
100+
### TypeScript Standards
101+
102+
**Strict Mode Enforcement:**
103+
104+
- All TypeScript strict checks enabled
105+
- **Explicit return types required** for all functions (except `.styles.ts(x)` files)
106+
- No `any` type (exceptions allowed in test files)
107+
- Strict null checks enforced
108+
109+
**Sorting Requirements (ESLint enforced):**
110+
111+
- Object keys must be sorted alphabetically
112+
- Destructured keys must be sorted
113+
- Interface properties must be sorted
114+
- String enums must be sorted
115+
- Imports auto-organized by prettier-plugin-organize-imports
116+
117+
**File Naming:** Use kebab-case (e.g., `my-component.tsx`)
118+
119+
### JSDoc Documentation
120+
121+
**Required for all functions:**
122+
123+
```typescript
124+
/**
125+
* Transforms a route by removing inactivity parameters.
126+
* @param routes - Array of route strings to transform.
127+
* @returns The first non-login route without inactivity param, or undefined.
128+
*/
129+
function transformRoute(routes: string[]): string | undefined {
130+
// implementation
131+
}
132+
```
133+
134+
**Requirements:**
135+
136+
- Function description
137+
- `@param` tags with descriptions (hyphen required before description)
138+
- `@returns` tag with description
139+
140+
### React Patterns
141+
142+
- Use functional components with hooks
143+
- **react-hooks/exhaustive-deps is enforced** - include all dependencies in useEffect, useCallback, useMemo
144+
- Styling: Use Emotion styled components in `.styles.ts` or `.styles.tsx` files
145+
- Component structure: Keep components focused and single-responsibility
146+
147+
## Testing
148+
149+
**Test Location:** Tests live in `/tests` directory (not co-located with source)
150+
151+
**Test Framework:** Jest with `@testing-library/react` in jsdom environment
152+
153+
**Test Naming:** Use `.test.ts` or `.test.tsx` extension
154+
155+
**Global Mocks:** Pre-configured for ResizeObserver, TextEncoder, TextDecoder (see `tests/setup.ts`)
156+
157+
**Test Structure:**
158+
159+
```typescript
160+
describe("ComponentName", () => {
161+
it("should do something specific", () => {
162+
// Arrange
163+
const input = "test";
164+
165+
// Act
166+
const result = functionUnderTest(input);
167+
168+
// Assert
169+
expect(result).toBe("expected");
170+
});
171+
});
172+
```
173+
174+
## Dependency Management
175+
176+
**This is a library package - use peer dependencies carefully.**
177+
178+
**Peer Dependencies:** Consuming applications must provide:
179+
180+
- React 18.3+
181+
- Material-UI v7 (@mui/material, @mui/icons-material)
182+
- Next.js 14.2+ and next-auth
183+
- Emotion (@emotion/react, @emotion/styled)
184+
- TanStack Table and Virtual
185+
- Various utilities (ky, uuid, yup, etc.)
186+
187+
**Critical:** New dependencies should go in `peerDependencies` or `devDependencies`, NOT `dependencies`.
188+
189+
## Pre-Commit and CI Checks
190+
191+
**All PRs must pass:**
192+
193+
- Prettier formatting (`npm run check-format`)
194+
- ESLint with no errors (`npm run lint`)
195+
- All Jest tests passing (`npm test`)
196+
- TypeScript compilation (`npm run test-compile`)
197+
198+
**Husky hooks:** Pre-commit hooks configured in `.husky/`
199+
200+
## Common Pitfalls
201+
202+
1. **Don't import from lib/** - Always import from `src/` during development
203+
2. **Don't add to dependencies** - Use peerDependencies or devDependencies
204+
3. **Don't disable ESLint rules** without justification
205+
4. **Don't skip JSDoc** - Required for all public functions
206+
5. **Don't commit lib/ directory** - It's build output and git-ignored
207+
6. **Don't skip return types** - Explicit return types required (except .styles files)
208+
7. **Maintain backward compatibility** - This is a library; breaking changes require major version bumps
209+
210+
## Special Notes
211+
212+
- **Release Management:** Uses release-please for automated versioning and changelog
213+
- **Storybook:** Available for component development and visual testing
214+
- **Import Paths:** Base URL is `./src` (configured in tsconfig.json), allowing absolute imports within src

0 commit comments

Comments
 (0)