Skip to main content

Frontend architecture

Grafana’s frontend is built with TypeScript, React, and Redux Toolkit, following modern React patterns and a feature-based architecture.

Directory structure

The frontend code lives in public/app/:

Application initialization

The app bootstraps in public/app/app.ts:

State management with Redux Toolkit

Grafana uses Redux Toolkit (RTK) for state management, moving away from legacy Redux patterns.

Store configuration

The store is configured in public/app/store/configureStore.ts:

Redux Toolkit patterns

Modern slices (preferred)

Use RTK’s createSlice for new features:

RTK Query for data fetching

Use RTK Query for API calls:
Usage in components:

Global store access

The global store is available via public/app/store/store.ts:

React patterns

Function components with hooks (preferred)

Styling with Emotion

Use useStyles2 for CSS-in-JS with Emotion:
Key styling principles:
  • Use theme values, not hardcoded colors
  • Responsive to theme changes (light/dark mode)
  • Type-safe style definitions

Feature-based architecture

Features are organized in public/app/features/:

Feature module example

Core services

Shared services live in public/app/core/services/:

Backend service

Data source service

Location service

Plugin system

Frontend plugins are loaded dynamically using SystemJS.

Plugin loading

Plugin hooks

Extend functionality with plugin hooks:

Routing

Routing uses React Router in public/app/routes/:

Testing patterns

Component tests with React Testing Library

Run tests:

Shared packages

Reusable libraries in packages/:
  • @grafana/data - Data structures, transformations, utilities
  • @grafana/ui - React component library
  • @grafana/runtime - Runtime services and APIs
  • @grafana/schema - CUE-generated TypeScript types
  • @grafana/scenes - Dashboard scene framework

Performance patterns

Code splitting

Memoization

Key patterns summary

  • Redux Toolkit - Modern Redux with slices and RTK Query
  • Function components - Hooks over class components
  • Emotion styling - Theme-aware CSS-in-JS
  • Feature modules - Organized by domain, not by type
  • TypeScript - Type safety throughout
  • SystemJS plugins - Dynamic plugin loading
  • React Testing Library - User-centric component tests