grafana/grafana
Backend
The Go backend lives under pkg/ and a complementary apps/ tree of Kubernetes-style API modules. It is responsible for HTTP/gRPC API serving, persistence, alert evaluation, plugin hosting, datasource query execution, and live streaming.
What's in pkg/
pkg/
├── api/ # Legacy REST/HTTP handlers (one file per resource)
├── apis/ # New k8s-style group/version/kind manifests
├── apimachinery/ # Shared k8s-flavored helpers
├── apiserver/ # apiserver scaffolding glue
├── aggregator/ # k8s aggregator-style routing
├── build/ # Build helpers (used by `scripts/build/`)
├── cmd/grafana/ # Server binary entry point (main.go)
├── cmd/grafana-cli/ # CLI subcommands (admin, plugins, db, …)
├── cmd/grafana-server/ # `grafana server` subcommand
├── codegen/ # Generators (CUE → Go, etc.)
├── components/ # Cross-cutting components (engine helpers)
├── expr/ # Expression engine for alerting/server-side queries
├── extensions/ # Build-tag-gated enterprise extension hooks
├── infra/ # Logging, tracing, metrics, DB connection
├── kinds/ # Bridges legacy "kinds" registry
├── middleware/ # HTTP middleware (auth, recovery, request ID, …)
├── modules/ # Optional service modes (e.g. backend-only)
├── operators/ # Pluggable side-process operators
├── plugins/ # Plugin host (loader, registry, sandbox)
├── registry/ # Service registry (background services lifecycle)
├── server/ # Wire DI graph + Server/HTTPServer init
├── services/ # Domain services (the bulk of business logic)
├── setting/ # Configuration (INI parsing & defaults)
├── storage/ # Unified storage layer (app-platform backend)
├── tests/ # Cross-package integration test helpers
├── tsdb/ # Backend datasource implementations
├── util/ # Generic helpers (errutil, retry, …)
└── web/ # HTTP routing primitives (mux, contexts)pkg/services/ is the largest single tree in the repo with 73 service domains. Most services follow the same pattern: an interface + types in <svc>.go, a concrete implementation under <svc>impl/ (or directly), an HTTP boundary either embedded inside pkg/api/ or under a per-service api/, and a store/ (or database/) for SQL access.
Sub-pages
- API layer —
pkg/api/and HTTP routing. - Services overview — survey of domains under
pkg/services/. - Authentication & access control — auth, authn, accesscontrol, sso, ldap, anonymous.
- Dashboards (backend) — folder/dashboard/library-element services.
- Alerting (ngalert) —
pkg/services/ngalert/. - Datasources & expressions —
pkg/services/datasources,pkg/expr, plugin proxy. - Plugin host —
pkg/plugins/andpkg/services/pluginsintegration/. - TSDB query backends —
pkg/tsdb/<name>/. - SQL store and migrations —
pkg/services/sqlstore/. - Unified storage / app-platform —
pkg/storage/,pkg/services/apiserver/. - Server init and wiring —
pkg/server/,pkg/registry/,pkg/modules/. - Live streaming —
pkg/services/live/. - Feature management —
pkg/services/featuremgmt/.
Key entry points
| File | Role |
|---|---|
pkg/cmd/grafana/main.go |
Binary entry point — wires grafana cli and grafana server subcommands |
pkg/cmd/grafana-server/commands/server.go |
Server boot |
pkg/server/server.go |
Server struct that owns lifecycle |
pkg/server/wire.go |
Wire DI graph (regenerate with make gen-go) |
pkg/api/api.go |
Legacy REST route registration |
pkg/api/http_server.go |
HTTPServer container that holds dependencies for handlers |
pkg/middleware/middleware.go |
Request middleware chain |
pkg/registry/registry.go |
Background service lifecycle controller |
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
Tooling
Next
API layer