This file provides guidance to AI agents when working with code in this repository.
This is the Altinn 3 app frontend - a React application that renders dynamic forms and layouts for Norwegian government services. The app is built to work with the Altinn Studio platform and communicates with .NET app backends.
yarn start- Start development server (runs codegen first)yarn build- Production build (runs codegen and copy-schemas)yarn gen- Run code generation for schemasyarn copy-schemas- Copy JSON schemas to dist
yarn test- Run Jest unit tests (runs codegen first)yarn test:watch- Run tests in watch modeyarn test:watchall- Run all tests in watch modeyarn cy:open- Open Cypress for e2e testingyarn cy:run- Run Cypress tests headlessly
yarn lint- Run ESLint (runs codegen first)yarn tsc- Run TypeScript compiler checkyarn tsc:watch- Run TypeScript in watch mode
To run files that partly matches path: yarn test -- partlyMatchingPathOrFilename
The codebase uses a hybrid approach with plans to modernize:
Current State (Legacy):
- Multiple nested React Contexts creating
- A Node Hierarchy in NodesContext that keeps state for all components/nodes
- Zustand stores wrapping data in custom context providers to avoid rerenders
- Tight coupling between contexts and components
Desired Future State:
- React Query for server state management
- Reduced dependency on React Context
- Zustand potentially replaced by React Query patterns
- Migration from Webpack to Vite, Jest to Vitest, Cypress to Playwright
- Migration to wrap Designsystemet component and our own smaller components that Designsystemet doesn't have in our own dumb components in
src/app-components/.
- Custom context creation utility in
src/core/contexts/context.tsx - Zustand context wrapper in
src/core/contexts/zustandContext.tsx - Many feature-specific providers in
src/features/*/Provider.tsx
- Layout components in
src/layout/with generated config files - App-level components in
src/app-components/ - Shared components in
src/components/ - Each layout component has:
Component.tsx,config.ts,index.tsx
- Extensive use of TypeScript code generation from JSON schemas
- Generated files have
.generated.tssuffix - Run
yarn genbefore most operations
src/core/- Core utilities, contexts, and base functionalitysrc/features/- Feature-specific code organized by domainsrc/layout/- Layout components that render form elementssrc/app-components/- Reusable UI componentssrc/utils/- Utility functions and helpersadr/- Architecture Decision Records
src/features/formData/- Form data management and validationsrc/features/layout/- Layout rendering and structuresrc/features/language/- Internationalization and text resourcessrc/features/validation/- Form validation logicsrc/features/attachments/- File upload and attachment handling
- Frontend: React 18 with TypeScript
- Build: Webpack (migrating to Vite)
- Testing: Jest + React Testing Library (migrating to Vitest), Cypress (migrating to Playwright)
- State: React Context + Zustand (evolving to React Query focus)
- Styling: CSS Modules + Digdir Design System
- Package Manager: Yarn 4 with Corepack
Most commands automatically run yarn gen first. The codegen system generates TypeScript definitions from JSON schemas, which are essential for the app to function.
The app has a complex provider tree with many nested contexts. When making changes, be aware of:
- Provider order dependencies
- Context value propagation
- Performance implications of context changes
There are many usages of any or type casting (as type) in the codebase. This skips TypeScript completely and is, in most cases, not what we want. We would like to improve the typing by avoiding this moving forward whilst also refactoring and improving existing types by removing such casts and anys.
Use objects for managing query keys and functions and queryOptions for sharing these across the system and central management.
Please see TkDodo's blog for more best practices, insights and tips and tricks.
Layout components use a standardized structure:
config.ts- Component configuration and propsComponent.tsx- Main component implementationindex.tsx- Export and registrationconfig.generated.ts- Generated type definitions
- Most tests require form layout context to be provided
- Use
renderWithProvidersfromsrc/test/renderWithProviders.tsx - Mock external dependencies in
src/__mocks__/
- Create directory in
src/layout/NewComponent/ - Add
config.ts,Component.tsx,index.tsx - Register component in layout system
- Run
yarn gento update generated files
- Use CSS Modules for component styling
- Follow existing patterns in
*.module.cssfiles - Leverage Digdir Design System components when possible