Architecture overview
Grafana is a full-stack observability platform built with a Go backend and a TypeScript/React frontend. This architecture guide covers the key components and design patterns that power Grafana.High-level architecture
Grafana follows a modular, service-oriented architecture:Core components
Backend (pkg/)
The Go backend is organized into several key areas:
pkg/server/- Server initialization and Wire dependency injection setuppkg/services/- Business logic organized by domain (dashboards, alerting, users, etc.)pkg/api/- HTTP API handlers and routingpkg/plugins/- Plugin system and backend plugin communicationpkg/tsdb/- Data source query backends (Prometheus, Loki, etc.)pkg/infra/- Infrastructure concerns (logging, metrics, database)
Frontend (public/app/)
The TypeScript/React frontend follows a feature-based architecture:
public/app/core/- Shared services, components, and utilitiespublic/app/features/- Feature modules (dashboard, alerting, explore, etc.)public/app/plugins/- Built-in frontend pluginspublic/app/store/- Redux store configuration with RTK
Plugin system
Grafana’s extensibility is powered by a sophisticated plugin system:- Panel plugins - Visualization types (graph, table, etc.)
- Data source plugins - Connect to data sources
- App plugins - Full applications within Grafana
Database layer
Grafana supports multiple database backends:- SQLite (default) - Embedded database for single-server deployments
- PostgreSQL - Recommended for production
- MySQL - Alternative production option
Key design patterns
Dependency injection with Wire
The backend uses Google Wire for compile-time dependency injection. Service dependencies are declared inpkg/server/wire.go and Wire generates the initialization code.
Benefits:
- Compile-time safety (no runtime DI failures)
- Circular dependency detection
- Clear dependency graphs
State management with Redux Toolkit
The frontend uses Redux Toolkit (RTK) for state management:- RTK Slices - Modern Redux pattern with reducers and actions
- RTK Query - Data fetching and caching
- Middleware - API clients and side effects
public/app/store/configureStore.ts.
Service-oriented architecture
Both frontend and backend follow service-oriented patterns:- Business logic lives in service layers, not in API handlers or React components
- Services implement interfaces defined in the same package
- Clear separation between data access, business logic, and presentation
Communication patterns
HTTP APIs
The backend exposes RESTful APIs for the frontend:- Standard CRUD operations for resources
- JSON request/response bodies
- JWT-based authentication
gRPC for plugins
Backend plugins communicate with Grafana core via gRPC:- QueryData - Execute queries
- CallResource - Custom API endpoints
- CheckHealth - Health checks
- Stream - Streaming data
WebSockets (Grafana Live)
Real-time features use WebSocket connections:- Dashboard activity
- Alert notifications
- Live measurements
Development workflow
The architecture supports hot-reload for both frontend and backend:Monorepo structure
Grafana uses a monorepo with:- Go workspaces (
go.work) - Backend module management - Yarn workspaces (
package.json) - Frontend package management - Shared packages (
packages/) - Reusable libraries
Next steps
- Backend architecture - Deep dive into Go backend
- Frontend architecture - React and Redux patterns
- Plugin architecture - Build and extend Grafana
- Database architecture - Data persistence layer