|
| 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 layout |
| 6 | + |
| 7 | +All application code lives in `apps/nar-v3/`. The repo root contains only CI/CD configuration (`.gitlab-ci.yml`, `.github/workflows/`). |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +All commands run from `apps/nar-v3/`: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm run dev # start Vite dev server |
| 15 | +npm run build # production build |
| 16 | +npm run lint # ESLint (0 warnings allowed) |
| 17 | +npm test # run all tests (requires EBRAINS KG connectivity for "KG" tests) |
| 18 | +npm run testci # run tests that don't require KG connectivity (CI-safe) |
| 19 | +npm run coverage # test coverage |
| 20 | +``` |
| 21 | + |
| 22 | +Run a single test file or filter by name: |
| 23 | +```bash |
| 24 | +npx vitest __tests__/utility.test.js |
| 25 | +npx vitest --grep "test name pattern" |
| 26 | +``` |
| 27 | + |
| 28 | +## Authentication in development |
| 29 | + |
| 30 | +The app uses Keycloak/EBRAINS IAM OAuth. To authenticate in dev mode, copy `apps/nar-v3/.env.local.example` to `apps/nar-v3/.env.local` and paste a valid EBRAINS IAM token as `VITE_DEV_TOKEN`. The dev server will use it automatically — no edits to `main.jsx` needed. `.env.local` is gitignored. Tests that require live KG access have "KG" in their name and are skipped by `testci`. |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +The app is a React SPA that provides a browsable interface to neural activity datasets stored in the **EBRAINS Knowledge Graph (KG)**. Users can explore datasets, subjects, slices, patched cells, and electrophysiology recordings. |
| 35 | + |
| 36 | +### Data flow |
| 37 | + |
| 38 | +``` |
| 39 | +React Router v6 loader |
| 40 | + → datastore.js (fetch + in-memory cache) |
| 41 | + → KG Core API v3 (https://core.kg.ebrains.eu/v3) |
| 42 | + → openMINDS-formatted JSON-LD responses |
| 43 | +``` |
| 44 | + |
| 45 | +Route loaders (in `src/routes/`) fetch data before rendering. `datastore.js` wraps all KG API calls with caching. `queries.js` and `queryLibrary.js` build the KG query payloads. |
| 46 | + |
| 47 | +### Graph database with hierarchical views |
| 48 | + |
| 49 | +The underlying data is a graph database (the EBRAINS KG). The current dataset views impose a particular hierarchical traversal of that graph, but this is just one perspective — future views may root themselves at different nodes (e.g. a recording-centric or subject-centric view). |
| 50 | + |
| 51 | +For patch clamp, the graph path from dataset to recordings looks like: |
| 52 | + |
| 53 | +``` |
| 54 | +Dataset |
| 55 | + └── StudiedSpecimen (Subject) |
| 56 | + └── StudiedState |
| 57 | + └── SlicePreparation → Slice(s) |
| 58 | + └── CellPatching → PatchedCell(s) |
| 59 | + └── RecordingActivity / StimulationActivity |
| 60 | + └── DataFile(s) |
| 61 | +``` |
| 62 | + |
| 63 | +For other electrophysiology modalities, there may be one or more intermediate Activities whose output is another StudiedState (rather than a final recording), before eventually reaching the RecordingActivity. The graph is not strictly a tree. |
| 64 | + |
| 65 | +Each level of this hierarchy has a corresponding card component in `src/components/`. |
| 66 | + |
| 67 | +### Auth and curator access |
| 68 | + |
| 69 | +`auth.js` handles Keycloak login and checks whether the user has curator permissions. Curators see `IN_PROGRESS` stage data; regular users see only `RELEASED` data. This stage flag flows through `datastore.js` into every KG query. |
| 70 | + |
| 71 | +### Key source files |
| 72 | + |
| 73 | +- `src/main.jsx` — app entry, Keycloak init, dev token |
| 74 | +- `src/routes/` — React Router route components with loaders |
| 75 | +- `src/datastore.js` — KG API wrapper with caching |
| 76 | +- `src/queries.js` / `src/queryLibrary.js` — KG query construction |
| 77 | +- `src/auth.js` — Keycloak authentication |
| 78 | +- `src/components/` — display components (one per hierarchy level) |
| 79 | + |
| 80 | +## Docker & deployment |
| 81 | + |
| 82 | +Two-stage Docker build: Node 20 for `npm run build`, then Nginx alpine to serve the static output on port 8080 as a non-root user. GitLab CI pushes `:prod` (main branch) or `:dev` (development branch) to `docker-registry.ebrains.eu/neuralactivity/nar-app-v3`. |
0 commit comments