<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged idp</title>
<link>https://coderlegion.com/tag/idp</link>
<description>Powered by Question2Answer</description>
<item>
<title>Build an AI-Powered Developer Portal with Backstage and .NET</title>
<link>https://coderlegion.com/17940/build-an-ai-powered-developer-portal-with-backstage-and-net</link>
<description>&lt;h3 id=&quot;build-an-ai-powered-developer-portal-with-backstage-and-net&quot;&gt;Build an AI-Powered Developer Portal with Backstage and .NET&lt;/h3&gt;
&lt;p&gt;Want to apply AI, not just read about it? Most tutorials stop at a &quot;Hello World&quot; chatbot. We are going to build something that actually solves a common engineering headache: stale documentation.&lt;/p&gt;
&lt;h4 id=&quot;who-this-is-for&quot;&gt;Who this is for&lt;/h4&gt;
&lt;p&gt;This guide is for platform engineers and .NET developers who need to organize a growing software landscape without forcing teams to manually write YAML files.&lt;/p&gt;
&lt;h4 id=&quot;what-you-will-build&quot;&gt;What you will build&lt;/h4&gt;
&lt;p&gt;You will build a &lt;strong&gt;dynamic developer portal&lt;/strong&gt; using &lt;a rel=&quot;nofollow&quot; href=&quot;https://backstage.io/&quot;&gt;Backstage&lt;/a&gt; that automatically populates its service catalog. We will use a .NET CLI tool to scan source code and use local AI (&lt;a rel=&quot;nofollow&quot; href=&quot;https://ollama.com/&quot;&gt;Ollama&lt;/a&gt;) to generate summaries.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Source repo:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/bgener/demo-backstage-catalog-generator&quot;&gt;demo-backstage-catalog-generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constraint:&lt;/strong&gt; We use local inference only. No source code ever leaves your machine.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Have you ever needed to update a service, but forgot what it does? Or spent time trying to understand code you have not touched in months? We usually solve this with a README.md that nobody updates, or a wiki nobody keeps current.&lt;/p&gt;
&lt;p&gt;An Internal Developer Portal (IDP) solves this by making the software landscape visible, but only if the data is fresh. Automation is the only way to avoid the &quot;stale metadata&quot; trap.&lt;/p&gt;

**Want to skip ahead?** Check out the [complete working demo on
GitHub](https://github.com/bgener/demo-backstage-catalog-generator) with all
the code ready to run.

&lt;h4 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h4&gt;
&lt;p&gt;Before we start, make sure you have the following installed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://dotnet.microsoft.com/en-us/download&quot;&gt;.NET SDK 8+&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://nodejs.org/&quot;&gt;Node.js&lt;/a&gt; (includes &lt;code&gt;npx&lt;/code&gt; and &lt;code&gt;yarn&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ollama.com/&quot;&gt;Ollama&lt;/a&gt; with the &lt;code&gt;llama3:8b&lt;/code&gt; model pulled&lt;/li&gt;
&lt;li&gt;A GitHub account (for hosting and deployment)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;why-does-an-internal-developer-portal-matter-&quot;&gt;Why Does an Internal Developer Portal Matter?&lt;/h4&gt;
&lt;p&gt;The term &quot;Internal Developer Portal&quot; (IDP) can be a little misleading, since it sounds like a tool exclusively for developers only. In reality, it functions as an &lt;strong&gt;internal organizational portal focused entirely on your software portfolio&lt;/strong&gt;. Unlike a general-purpose SharePoint site where everything is dumped in one place and nothing is easy to find, an IDP is deliberately narrow in scope. It covers your software landscape and nothing else, which is exactly what makes it powerful.&lt;/p&gt;
&lt;p&gt;An IDP becomes the &lt;strong&gt;single source of truth&lt;/strong&gt; for your engineering organization. It answers critical questions across every role:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Engineers:&lt;/strong&gt; Which services exist, who owns them, what they do, and where the APIs are.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Team leads and architects:&lt;/strong&gt; Team composition, squad ownership, and architectural decisions with their rationale.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New joiners:&lt;/strong&gt; How to get up to speed on a codebase they have never seen.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Platform and operations teams:&lt;/strong&gt; What is running in production, who is responsible, and the lifecycle status.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Beyond just listing services, a mature IDP centralizes &lt;strong&gt;Architecture Decision Records (ADRs)&lt;/strong&gt;. I'd argue those are more valuable than the service catalog itself, because they capture &lt;em&gt;why&lt;/em&gt; a decision was made. Without a central place to surface them, they end up in forgotten wiki pages or git repositories nobody checks.&lt;/p&gt;
&lt;p&gt;The challenge is keeping all of this populated and accurate. If you rely on engineers to manually maintain metadata YAML files, the data grows stale within weeks. Automation is the only sustainable path.&lt;/p&gt;
&lt;h4 id=&quot;formulating-the-architecture&quot;&gt;Formulating the Architecture&lt;/h4&gt;
&lt;p&gt;Here's the plan to extract metadata from source code and present it visually:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Backstage:&lt;/strong&gt; the UI layer where engineers browse and discover services, APIs, documentation, and team ownership&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.NET Core:&lt;/strong&gt; a CLI tool that scans project folders, extracts metadata, and generates Backstage-compatible YAML&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ollama:&lt;/strong&gt; runs AI inference locally. No source code leaves the machine, no API costs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static hosting:&lt;/strong&gt; deploy to Netlify, Azure Static Web Apps, or any provider of your choice&lt;/li&gt;
&lt;/ul&gt;

*Why Ollama?* Because it runs locally and you do not want to expose your code
to the AI agents over the public internet. You do not know what and how they
use it for, and it does not feel safe. If your employer finds out, you're
done.

&lt;h4 id=&quot;setting-up-the-project-infrastructure&quot;&gt;Setting Up the Project Infrastructure&lt;/h4&gt;
&lt;p&gt;You can either follow along and build everything from scratch, or clone the &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/bgener/demo-backstage-catalog-generator&quot;&gt;demo repository&lt;/a&gt; to get started immediately.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To clone the demo:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git clone https://github.com/bgener/demo-backstage-catalog-generator.git
cd demo-backstage-catalog-generator
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;To build from scratch&lt;/strong&gt;, start by downloading and running the LLM model we will use in this guide:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;ollama pull llama3:8b
ollama serve
&lt;/code&gt;&lt;/pre&gt;

We use `llama3:8b` specifically. It is significantly faster for local
inference than the full-size model and produces more consistent, concise
output for our use case. If you have a powerful GPU, feel free to use `llama3`
instead.

&lt;p&gt;Next, scaffold the baseline .NET services. We’ll create one Web API and one MVC project:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mkdir Backstage-Dev-Portal
cd Backstage-Dev-Portal

dotnet new webapi -n ServiceA
dotnet new mvc -n ServiceB

dotnet new sln -n Backstage-Dev-Portal
dotnet sln add ServiceA/ServiceA.csproj
dotnet sln add ServiceB/ServiceB.csproj
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can replace the default controllers with real logic later. These raw services represent the uncataloged microservices in your organization.&lt;/p&gt;
&lt;h4 id=&quot;building-a-smart-catalog-generator-in-net&quot;&gt;Building a Smart Catalog Generator in .NET&lt;/h4&gt;
&lt;p&gt;We will build a .NET CLI tool using &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/awaescher/OllamaSharp&quot;&gt;OllamaSharp&lt;/a&gt;. It scans each project, sends relevant files to the local AI model, and generates a single &lt;code&gt;catalog-info.yaml&lt;/code&gt; file containing all services, ready for Backstage to consume.&lt;/p&gt;
&lt;p&gt;Create the tool and add the required package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet new console -n ProjectSummarizer
cd ProjectSummarizer
dotnet add package OllamaSharp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead of sending every file to the AI, we take a smarter approach to avoid token limits and save compute time. We will send only &lt;code&gt;*.csproj&lt;/code&gt;, &lt;code&gt;Program.cs&lt;/code&gt;, and the folder structure. This is all the context the AI needs to understand the project structure and purpose.&lt;/p&gt;
&lt;p&gt;Replace &lt;code&gt;Program.cs&lt;/code&gt; with the implementation below. The full version is in the &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/bgener/demo-backstage-catalog-generator&quot;&gt;demo repository&lt;/a&gt;. Here we focus on the key parts.&lt;/p&gt;
&lt;p&gt;First, set up the Ollama client and configure the system prompt. This is the most fragile part of the chain: the system prompt has to force the model into a YAML-safe format without it hallucinating markdown backticks:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var ollamaApiClient = new OllamaApiClient(
    new Uri(&quot;http://localhost:11434&quot;)) { SelectedModel = &quot;llama3:8b&quot; };

var chat = new Chat(ollamaApiClient, systemPrompt:
    &quot;You are a technical documentation assistant. &quot; +
    &quot;You produce concise, YAML-safe summaries of .NET projects. &quot; +
    &quot;Output only plain text, no markdown, no bullet points, no quotes, no colons, no newlines.&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead of sending every file to the AI, we only send &lt;code&gt;*.csproj&lt;/code&gt;, &lt;code&gt;Program.cs&lt;/code&gt;, and the folder structure. This is all the context the model needs.&lt;/p&gt;

**Prompt sanitization is critical.** If your `Program.cs` contains complex
string literals or nested colons, the AI might pass them through to your YAML,
breaking the Backstage parser. Always sanitize the output before writing the
file.

&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var sb = new StringBuilder();
sb.AppendLine($&quot;Project: {projectName}&quot;);
sb.AppendLine(&quot;Folder structure:&quot;);
AppendFolderStructure(projectDir, sb, &quot;&quot;);
sb.AppendLine(File.ReadAllText(csprojPath));

var programPath = Directory.GetFiles(projectDir, &quot;Program.cs&quot;, SearchOption.AllDirectories)
    .FirstOrDefault();
if (programPath != null)
    sb.AppendLine(File.ReadAllText(programPath));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The prompt itself uses few-shot examples to guide the model toward the output format we want:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var prompt = &quot;Summarize the project in 1-2 sentences based on the files provided. &quot; +
             &quot;Do not output anything else. &quot; +
             &quot;Examples of good output: &quot; +
             &quot;REST API service providing weather forecasts with temperature data\n&quot; +
             &quot;ASP.NET MVC application with React frontend for managing todo items\n\n&quot;
             + sb.ToString();

await foreach (var token in chat.SendAsync(prompt, cts.Token))
    summaryBuilder.Append(token);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, each summary is sanitized and assembled into a Backstage-compatible YAML entry:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var summary = summaryBuilder.ToString().Trim()
    .Replace(&quot;\n&quot;, &quot; &quot;).Replace(&quot;:&quot;, &quot; -&quot;).Replace(&quot;\&quot;&quot;, &quot;'&quot;);

var yamlEntry = $@&quot;
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: {projectName.ToLowerInvariant()}
  description: &quot;&quot;{summary}&quot;&quot;
spec:
  type: service
  lifecycle: production
  owner: group:default/engineering&quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run the generator against the target directory (use &lt;code&gt;.&lt;/code&gt; if you are already in the project root):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet run --project ProjectSummarizer -- .
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see the AI streaming its summaries in real time:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8w473r4i4y839n02e56.png&quot; alt=&quot;Image description&quot;&gt;&lt;/p&gt;
&lt;p&gt;Most of the real work here is figuring out the prompt. Even a tiny change can produce a completely different output. I encourage you to experiment with the system prompt and the user prompt to see how it affects quality. That is the real learning here.&lt;/p&gt;
&lt;h4 id=&quot;integrating-the-ai-catalog-with-backstage&quot;&gt;Integrating the AI Catalog with Backstage&lt;/h4&gt;
&lt;p&gt;With the &lt;code&gt;catalog-info.yaml&lt;/code&gt; ready, we can integrate it into a Backstage instance. Install Backstage:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npx @backstage/create-app
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Follow the prompts to name it &lt;code&gt;dev-portal&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now point Backstage to your generated catalog file. Open &lt;code&gt;app-config.yaml&lt;/code&gt; in the &lt;code&gt;dev-portal&lt;/code&gt; directory and add the following under the &lt;code&gt;catalog&lt;/code&gt; section:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;catalog:
  locations:
    - type: file
      target: ../Backstage-Dev-Portal/catalog-info.yaml
      rules:
        - allow: [Component]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This tells Backstage where to find the AI-generated service metadata. The &lt;code&gt;target&lt;/code&gt; path is relative to the Backstage root directory. Adjust it to point to wherever your generator wrote the &lt;code&gt;catalog-info.yaml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To run it locally:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd dev-portal
yarn dev
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Open &lt;code&gt;http://localhost:3000&lt;/code&gt; in your browser. You should see all your services listed in the &lt;strong&gt;Software Catalog&lt;/strong&gt; with AI-generated summaries visible in the description column.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gnd3uy6sjadiwto76lv.png&quot; alt=&quot;Image description&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;deploying-the-portal&quot;&gt;Deploying the Portal&lt;/h4&gt;
&lt;p&gt;To host this, build your portal as a static site:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;yarn build:static
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Push the output to GitHub and deploy to any &lt;strong&gt;static hosting provider&lt;/strong&gt;: Netlify, Azure Static Web Apps, Vercel, or even self-hosted on Kubernetes. Set the build command to &lt;code&gt;yarn build:static&lt;/code&gt; and the publish directory to &lt;code&gt;dist&lt;/code&gt;.&lt;/p&gt;

A static Backstage build is great for read-only catalogs. If you need dynamic
features like **authentication**, **real-time plugin backends**, or **write
operations**, you will need to deploy the full Backstage backend as a Node.js
service instead.

&lt;p&gt;The part that is easy to miss is that a static Backstage portal has no live catalog refresh. The catalog is baked at build time, so there is always a lag between a code change and the portal showing it.&lt;/p&gt;
&lt;h3 id=&quot;automating-with-ci-cd&quot;&gt;Automating with CI/CD&lt;/h3&gt;
&lt;p&gt;The catalog only stays current if the generator runs automatically. Here is a GitHub Actions workflow that regenerates summaries on every push to &lt;code&gt;main&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;name: Update Backstage Catalog
on:
  push:
    branches: [main]

jobs:
  generate-catalog:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ‘8.0.x’

      - name: Install and start Ollama
        run: |
          curl -fsSL https://ollama.com/install.sh | sh
          ollama serve &amp;amp;
          sleep 5
          ollama pull llama3:8b

      - name: Generate catalog
        run: dotnet run --project ProjectSummarizer -- &quot;$GITHUB_WORKSPACE&quot;

      - name: Commit updated catalog
        run: |
          git config user.name &quot;github-actions&quot;
          git config user.email &quot;*Emails are not allowed*&quot;
          git add catalog-info.yaml
          git diff --cached --quiet || git commit -m &quot;chore: regenerate AI catalog summaries&quot;
          git push
&lt;/code&gt;&lt;/pre&gt;

**CI Performance:** Running Ollama in CI uses CPU-only inference by default. A
`llama3:8b` summary takes about 20-30 seconds per project on a standard GitHub
runner. For a large monorepo, your CI bill will spike. Consider using a
persistent self-hosted runner with a GPU if you scale this.

&lt;h4 id=&quot;final-thoughts&quot;&gt;Final thoughts&lt;/h4&gt;
&lt;p&gt;Automate the metadata generation where the code lives, and keep the UI (Backstage) as a thin, static client. That is the whole trick. Once those two are separate, the &quot;stale documentation&quot; problem mostly goes away.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use narrow context:&lt;/strong&gt; Don't send the whole repo. Files like &lt;code&gt;Program.cs&lt;/code&gt; and &lt;code&gt;*.csproj&lt;/code&gt; are usually enough context for the model.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sanitize strictly:&lt;/strong&gt; AI output is non-deterministic. Always strip colons and newlines before writing to YAML.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Start static:&lt;/strong&gt; Read-only is much easier to maintain. Add a backend only when you actually need write operations or auth.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would not use this in production unless I had tested the sanitization logic against a few real codebases first. The &lt;code&gt;Replace&lt;/code&gt; calls that strip colons and newlines are intentionally minimal. They break on YAML with complex string values, like connection strings or environment variable blocks.&lt;/p&gt;
&lt;h3 id=&quot;faq&quot;&gt;FAQ&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Can I use OpenAI instead of Ollama?&lt;/strong&gt;&lt;br&gt;
Yes, but you will be sending your source code (or at least your &lt;code&gt;Program.cs&lt;/code&gt;) to a third party. Use a local model if security is a concern.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Does this replace README files?&lt;/strong&gt;&lt;br&gt;
No. It replaces the &quot;Service Directory&quot; that usually lives in a spreadsheet. It points engineers to the README they actually need.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How do I handle project renames?&lt;/strong&gt;&lt;br&gt;
The generator uses the folder or &lt;code&gt;.csproj&lt;/code&gt; name. If you rename them, Backstage will see it as a new component unless you map the identity stably.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;I help teams build exactly this kind of internal tooling, from developer portals to platform engineering. &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.bgener.nl/resume&quot;&gt;See my work&lt;/a&gt; or &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.bgener.nl/contact&quot;&gt;get in touch&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/17940/build-an-ai-powered-developer-portal-with-backstage-and-net</guid>
<pubDate>Fri, 15 May 2026 09:51:01 +0000</pubDate>
</item>
</channel>
</rss>