Created by: Paweł Zentała (@zentala)
Purpose: Reference implementation & Copy-Paste Development Resource
Welcome! This repository serves as a well-commented, practical example of a Catalog Processor for Backstage, an open platform for building developer portals (IDP - Internal Developer Platform).
What is Backstage? Think of Backstage as a central hub for your development teams. It helps organize your microservices, libraries, websites, ML models, documentation, and infrastructure using a unified Software Catalog.
What is the Software Catalog? The Catalog is the core of Backstage. It's a system for tracking ownership and metadata for all your software assets (we call them Entities). Entities can be things like:
Component: A piece of software (service, website, library).API: An interface exposed by a Component.Resource: Infrastructure needed by a Component (database, S3 bucket).Group: A team owning software.User: An individual developer.Location: A pointer to where entity metadata is stored (e.g., acatalog-info.yamlfile in a Git repo).
You can find more details in the Backstage Catalog documentation.
What is a Catalog Processor? The Catalog needs to be populated and kept up-to-date. That's where Processors come in. They are backend plugins that automatically:
- Discover metadata (e.g., by scanning Git repositories pointed to by
Locationentities). - Validate the discovered metadata against rules.
- Process the metadata (e.g., enriching it with data from external systems, like code owners or analysis results).
- Emit the final
Entitydata into the Catalog database.
Processors are crucial for automating catalog maintenance and extending its capabilities. Learn more about the Catalog processing pipeline.
This module (catalog-backend-module-example-processor) provides a concrete example: the ExampleLocationAnalyzerProcessor.
Core Functionality:
- Acts on Locations: It specifically processes
Locationentities that point to URLs (spec.type: url). Locations are often the starting point for discovering other entities defined in files likecatalog-info.yaml. - Analyzes Targets: It includes a placeholder
ExampleLocationAnalyzerclass. In a real-world scenario, this analyzer would perform tasks based on theLocation's target URL, such as:- Cloning the repository using Backstage's
ScmIntegrationRegistry. - Reading and parsing files (e.g., checking for specific configurations, running linters).
- Calling external APIs.
- Generating reports or metrics.
- Cloning the repository using Backstage's
- Filters Locations: It demonstrates how to use configuration (
app-config.yaml) to allow processing only specific URL patterns (using glob matching viaminimatch). - Enriches Data (Potentially): Although the current example is basic, a processor like this could emit new
Entitiesbased on its analysis or add annotations to existing entities. - Provides Clear Logging: It shows how to use the Backstage logger service effectively.
Why This Example is Useful for Developers (Especially Juniors):
- Well-Commented Code: The TypeScript code (
./src/) includes detailed JSDoc comments explaining the purpose of classes, methods, and parameters. - Clear Structure: It follows the standard structure for a Backstage backend module.
- Focus on Core Concepts: It demonstrates key Backstage backend concepts: Modules, Extension Points, Services (Logger, Config, Integrations), and the Catalog processing flow.
- Configuration Example: Shows practical usage of
app-config.yamlfor controlling plugin behavior. - Copy-Paste Ready: You can use this code as a starting point for building your own custom catalog processors. Adapt the
ExampleLocationAnalyzerlogic to fit your specific needs.
src/processor.ts: Defines the mainExampleLocationAnalyzerProcessorclass implementing theCatalogProcessorinterface. This is the entry point for the catalog processing steps.analyzer.ts: Defines theExampleLocationAnalyzerclass containing the logic for analyzing a location. This is separated for clarity – the processor handles integration with Backstage, while the analyzer handles the core task.allowLocation.ts: Contains the helper functionisAllowedLocationfor filtering locations based on configuration.module.ts: Defines the Backstage Backend Module. This file registers the processor with thecatalogProcessingExtensionPoint, wiring up dependencies like config, logger, and integrations.index.ts: Exports the module for use in the main backend.
package.json: Defines dependencies and build scripts.README.md: This file..eslintrc.js: Linting configuration..gitignore: Specifies files to ignore in Git (likenode_modules).
To enable and configure this processor in your Backstage instance, add the following to your app-config.yaml:
catalog:
processors:
exampleLocationAnalyzer:
# Set to true to enable the processor
enabled: true # Default is likely false if not specified
# Optional: Specify glob patterns for allowed location targets.
# If omitted or empty, all 'url' locations matching Backstage integrations will be processed.
# Use patterns understood by 'minimatch' library.
allowedLocationTargets:
- 'https://github.com/my-org/important-repo/*'
- 'https://dev.azure.com/my-org/project/_git/another-repo?path=/catalog-info.yaml'
# Add more patterns as neededImportant: The catalog.processors.exampleLocationAnalyzer.enabled key controls whether the processor runs. The allowedLocationTargets provide fine-grained control over which URLs it analyzes.
-
Add Dependency: Add this module as a dependency to your main backend package (usually
packages/backend):# Run from your Backstage root directory yarn --cwd packages/backend add file:../plugins/catalog-backend-module-example-processor(Adjust the path if your structure differs)
-
Register Module: Import and add the module in your backend's entry point (usually
packages/backend/src/index.ts):// packages/backend/src/index.ts import { createBackend } from '@backstage/backend-defaults'; // Import the module import { catalogModuleExampleProcessor } from '@internal/backstage-plugin-catalog-backend-module-example-processor'; // Ensure package name matches your setup const backend = createBackend(); // ... add other plugins and modules // Add the example processor module backend.add(catalogModuleExampleProcessor); backend.start();
-
Install Dependencies: Run
yarn installin your main Backstagesrc/directory (or project root depending on your setup) to ensure all dependencies are correctly linked. -
Configure: Update your
app-config.yamlas shown in the "Configuration" section. -
Restart Backend: Restart your Backstage backend process. You should see log messages indicating the processor is initializing if enabled.
Feel free to explore the code, adapt it, and use it as a learning resource!