K9 Sak Web Development
Expert development assistant for NAV's K9 case handling system (k9-sak-web), a React/TypeScript monorepo for processing benefits cases with strict architectural patterns and security requirements.
What This Skill Does
Provides comprehensive guidance for developing, testing, and maintaining the K9 Sak Web monorepo, ensuring adherence to NAV's standards, proper package management with yarn, V2 modernization patterns, and accessibility requirements for sensitive case handling applications.
Step-by-Step Instructions
1. Environment Setup and Package Management
**CRITICAL: Always use yarn, never npm**
Verify yarn version: `yarn --version` (must be 4.6.0)Install dependencies: `yarn install`This is a yarn workspaces monorepo with packages under `packages/`Never use npm commands in this project2. Understanding Monorepo Structure
**V2 Modernization Pattern:**
`packages/v2/` contains modernized code with stricter TypeScript rulesV2 code CANNOT import from non-V2 packages (one-way dependency)Old code CAN import from V2When refactoring, prefer moving code to V2V2 has its own stricter `tsconfig.json`**Path aliases:**
`@fpsak-frontend/*` and `@k9-sak-web/*` map to `./packages/*/src`**Package categories:**
`behandling-*`: Treatment/case type packages`fakta-*`: Facts/information gathering components`prosess-*`: Process step components`sak-*`: Case-related functionalityShared utilities: `utils`, `types`, `kodeverk`, `rest-api`3. TypeScript Configuration
Strict null checks: ENABLEDStrict mode: DISABLED (legacy)Target: esnext, Module: es2020JSX: react-jsx (new transform)Check `loosely-type-checked-files.json` for files with relaxed checkingAlways run `yarn ts-check` before committing4. Dependency Management
**CRITICAL: These dependencies MUST be synchronized across all packages:**
`@navikt/aksel-icons``@navikt/ds-css``@navikt/ds-react``@navikt/ds-tailwind``@navikt/ft-plattform-komponenter``react-hook-form``react-router-dom`When updating these, ensure all `@navikt/ft-*` packages are compatible or use `resolutions` in package.json.
5. Styling Approach
Use CSS Modules for component-specific styles (`.module.css`)Generate CSS module type definitions: `yarn css:modules:typegen`Use Tailwind utilities via `@navikt/ds-tailwind` for spacing/layoutFollow NAV Design System patterns (@navikt/ds-react components)Run `yarn css:lint` for CSS lintingNo inline styles6. Testing Strategy
**Priority order:**
1. **Storybook interaction tests** for UI components (primary choice)
2. **Vitest** for pure logic, utilities, and hooks (non-UI)
3. **Playwright** for E2E tests
**Testing rules:**
Add accessibility tests in Storybook stories (addon-a11y)Prefer test data builders and module-level mocksAvoid MSW in new testsAvoid `vi.spyOn` for HTTP (if needed, test belongs in Storybook)Run tests: `yarn test` or `yarn test:watch`Follow `packages/storybook/README.md` when creating stories7. Naming Conventions
**Components (files + names):** PascalCase (`MyComponent.tsx`, export `MyComponent`)**Hooks (files + names):** camelCase with `use` prefix (`useMyHook.ts`, export `useMyHook`)**Utilities (files):** camelCase (`myUtils.ts`)**Types/Interfaces:** PascalCase**Constants:** SCREAMING_SNAKE_CASE**CSS Modules (classes):** camelCase**CSS Modules (files):** camelCase (`myComponent.module.css`)**Tests:** Mirror target naming (`MyComponent.spec.tsx`, `myUtils.spec.ts`)**Storybook:** Match component filename (`MyComponent.stories.tsx`)8. Language and Text Handling
Use Norwegian for domain terms and user-facing text ("Saksoversikt", "Send vedtak")Keep technical terms in English ("endpoint", "API", "fetch", "mock", "feature toggle")No runtime i18n layer; use plain strings/constantsDon't translate technical terms to Norwegian or use English for domain content9. Component Development Patterns
Use React function components with hooksProperly type props, state, and hooksFollow WCAG accessibility guidelinesUse semantic HTMLUse react-hook-form for form managementReusable components go in `packages/v2/gui/shared/`Use React.memo, useMemo, useCallback appropriately10. Development Workflow Commands
```bash
yarn dev # Start K9 dev server
yarn dev:ung # Start Ungdomsytelse dev server
yarn ts-check # Type check all code
yarn lint:fix # Fix linting issues
yarn test # Run tests
yarn test:watch # Run tests in watch mode
yarn storybook # Start Storybook
yarn ltb # Full check (lint, type, build)
yarn build # Build K9 for production
yarn build:ung # Build Ungdomsytelse for production
yarn css:modules:typegen # Generate CSS module types
yarn css:lint # Lint CSS
yarn knip # Find unused files/exports
```
11. Pre-Commit Checklist
Before committing changes:
1. Run `yarn ts-check` to verify types
2. Run `yarn lint:fix` to fix style issues
3. Run `yarn test` to ensure tests pass
4. Add/update tests for changed functionality
5. Update Storybook stories if changing shared components
6. Generate CSS types if adding/changing CSS modules: `yarn css:modules:typegen`
7. Check V2 dependency rules (V2 cannot import from non-V2)
12. Feature Toggles
Configured in `feature-toggles.json` and `ung.feature-toggles.json`Activate via `.env.development` in `envDir/` directory13. Build and Deployment
Docker-based deploymentSentry integration for error tracking (release via commit SHA)Environment-specific configs in `envDir/`Main branch deploys to https://k9.dev.intern.nav.no then productiondev-next1 branch for experimental features (10-day TTL)Critical Anti-Patterns to Avoid
1. ❌ Using `npm` instead of `yarn`
2. ❌ Importing from non-V2 code in V2 packages
3. ❌ Inconsistent NAV Design System package versions
4. ❌ Ignoring TypeScript errors
5. ❌ Using i18n
6. ❌ Inline styles
7. ❌ Missing accessibility attributes
8. ❌ Not running type-check before committing
9. ❌ Introducing MSW in new tests
10. ❌ Using `vi.spyOn` for HTTP in tests
Important Context
NAV (Norwegian Labour and Welfare Administration) projectHandles sensitive case data - security and privacy are paramountUsed by case workers for processing benefits (Pleiepenger, Omsorgspenger, Opplæringspenger, Ungdomsytelse, etc.)Slack channel: #k9-frontendRepository: https://github.com/navikt/k9-sak-webExamples
Starting Development
```bash
yarn install
yarn dev
In another terminal
yarn storybook
```
Creating a New Component in V2
```typescript
// packages/v2/gui/shared/MyComponent.tsx
import React from 'react';
import { Button } from '@navikt/ds-react';
import styles from './myComponent.module.css';
interface MyComponentProps {
title: string;
onSubmit: () => void;
}
export const MyComponent: React.FC<MyComponentProps> = ({ title, onSubmit }) => {
return (
<div className={styles.container}>
<h2>{title}</h2>
<Button onClick={onSubmit}>Send</Button>
</div>
);
};
```
Adding a Storybook Story
```typescript
// packages/v2/gui/shared/MyComponent.stories.tsx
import type { Meta, StoryObj } from '@storybook/react';
import { MyComponent } from './MyComponent';
const meta = {
title: 'Shared/MyComponent',
component: MyComponent,
parameters: {
a11y: {
config: {
rules: [{ id: 'color-contrast', enabled: true }],
},
},
},
} satisfies Meta<typeof MyComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
title: 'Eksempel tittel',
onSubmit: () => console.log('Submitted'),
},
};
```
Constraints
Must use yarn 4.6.0 (never npm)V2 code cannot import from non-V2 packagesMust maintain synchronized versions of NAV Design System packagesMust follow accessibility standards (WCAG)Security and privacy are paramount (sensitive case data)Must run `yarn ts-check` before commitsPrefer Storybook for UI component tests