grafana/grafana
Backend services
pkg/services/ is the business-logic tree. With 73 service domains it dominates the backend by both file count and surface area.
Naming pattern
Most services follow a common shape:
pkg/services/<domain>/
├── <domain>.go # Service interface + types + errors
├── <domain>impl/ # Concrete implementation (or directly: e.g. <domain>Service struct)
├── <domain>test/ # In-package test fakes
├── api/ # HTTP handlers when the service exposes its own router
├── store/ or database/ # SQL access
└── models/ # Persistent + DTO Go structsSome long-lived services keep handlers and types directly inside pkg/api/<domain>.go; newer ones prefer a service-local api/ package. There is no single canonical layout — match the surrounding code.
Domain catalog (high level)
The 73 services group naturally into themes:
Identity & access
auth/— auth-method abstractionsauthn/— authentication clients (basic, OAuth, JWT, anonymous, render token, …)authz/— authorization (RBAC) glueaccesscontrol/— RBAC primitives, evaluator, middlewareanonymous/— anonymous identity trackingapikey/— legacy API keysserviceaccounts/— service accounts + tokensldap/— LDAP backendlogin/— login flow + remembered usersloginattempt/— bruteforce throttlingoauthtoken/— OAuth refreshsigningkeys/— JWT signingssosettings/— SSO config storageextsvcauth/— auth for external servicesencryption/,secrets/,kmsproviders/— secret encryption
Tenancy
org/— organizationsteam/— teamsuser/— userstemp_user/— invitation/onboarding statepreference/— user/team/org preferencesquota/— quota enforcementstats/— admin stats roll-ups
Dashboards & content
dashboards/— dashboard CRUDfolder/— folder hierarchy + permissionsdashboardimport/— import from JSON /grafana.comdashboardsnapshots/— share-by-snapshotdashboardversion/— version historylibraryelements/,librarypanels/— library panelspublicdashboards/— public dashboard sharingstar/— favoritesshorturls/— share-link shortenerplaylist/— dashboard rotationnavtree/— built-in navigation tree
Datasources & queries
datasources/— datasource registry + secretsdatasourceproxy/—/api/datasources/proxy/*query/— query orchestration over the plugin hostqueryhistory/— Explore query historycorrelations/— Explore correlationsdsquerierclient/— datasource querier client
Alerting
ngalert/— unified alerting (see Alerting)notifications/— email and webhook notificationsscreenshot/— alert image rendering
Plugins & rendering
pluginsintegration/— DI glue aroundpkg/pluginsplugindashboards/— bundled-with-plugin dashboardsrendering/— image rendering plugincaching/— query/dashboard cache hookslive/— Centrifuge-backed channels (see Live)updatemanager/— update notifications
Storage
sqlstore/— xorm SQL gateway + migrationsapiserver/— apiserver registration gluestore/— file/blob store abstractiontag/— tag normalizationannotations/— annotation CRUD
Operations & migration
provisioning/— file-based provisioning at startupcloudmigration/— migrate-to-cloud workflowsfeaturemgmt/— feature flags (see Feature management)gcom/—grafana.comAPI clientgrpcserver/— internal gRPC server scaffoldinghooks/— extension hook registrylicensing/— enterprise licensing surfacesearch/,searchusers/— search APIssetting/— runtime-mutable settingssupportbundles/— diagnostic bundle bundlingpromtypemigration/— Prometheus type migrationsscimutil/— SCIM utilitiesvalidations/— request validators
How services are wired
Each service has a ProvideService(...) constructor (Go's wire idiom). The constructor is added to a wire.NewSet and the entire graph is materialized in pkg/server/wire.go → pkg/server/wire_gen.go after running make gen-go.
Many services also implement registry.BackgroundService — an interface that lets them run a goroutine for the lifetime of the server (e.g. ngalert scheduler, live coordinator, plugin updater). Background services are started by pkg/registry/ after Wire builds the graph.
Cross-cutting helpers
pkg/util/errutil/— typed-error builder for predictable HTTP mapping.pkg/infra/log/— namespaced logger.pkg/infra/db/— DB connection wrapper.pkg/infra/tracing/— OpenTelemetry tracer.pkg/services/sqlstore/searchstore/— generic search query builder used by dashboards/folders.
Where to add a new service
- Create
pkg/services/<name>/<name>.godefining the interface and types. - Implement under
<name>impl/(or directly). - Add a
ProvideServiceconstructor andwire.NewSet. - Reference the new set from
pkg/server/wire.go. - Run
make gen-go. - Add tests under
<name>impl/<name>_test.goand (if HTTP) underpkg/api/. - If HTTP-facing: register routes in
pkg/api/api.goor, preferably, expose via an app-platform resource.
See API layer for HTTP wiring details and Patterns and conventions for naming/error conventions.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.