Dev

Writing GitHub READMEs with badges, alerts, and Mermaid

Use Shields.io badges, GitHub Markdown alerts, and small Mermaid diagrams to make project status, setup requirements, and architecture easy to find.

Writing GitHub READMEs with badges, alerts, and Mermaid

A README has to answer different questions quickly. I put status in a few badges, call attention to setup hazards with GitHub alerts, and keep a small architecture diagram alongside the code.

The examples use GitHub Flavored Markdown and the Shields.io v1 static badge endpoint as of December 2024.

Decide what belongs in the README

When I open a repository, I look for the runtime, what the project does, and how to run it. A wall of prose makes these details hard to find. Screenshots of the architecture also fall behind the code if every change requires someone to re-export an image.

Three small additions solve different problems.

  1. Badges show state at a glance. Useful examples include the runtime version, license, and CI status.
  2. Alerts separate operational caveats from ordinary setup steps. A missing environment variable or a destructive reset command deserves a distinct treatment.
  3. Mermaid describes the system in source text. The diagram can change in the same pull request as the implementation.

I keep each addition focused. A badge should answer a question, and a diagram should help a reader follow one workflow.

Add static and dynamic badges

Shields.io static badges accept a label, message, and color in the URL. The style parameter selects a rendering style such as flat, flat-square, or for-the-badge. Use the logo parameter for a Simple Icons identifier and logoColor if you need a specific contrast.

1
2
3
![Java 21](https://img.shields.io/badge/Java-21-ED8B00?style=flat&logo=openjdk&logoColor=white)
![Spring Boot 3.4](https://img.shields.io/badge/Spring_Boot-3.4-6DB33F?style=for-the-badge&logo=springboot&logoColor=white)
![License MIT](https://img.shields.io/badge/License-MIT-blue?style=flat-square)

In a path-based badge, a single hyphen separates fields and a single underscore represents a space. Double a hyphen or underscore when you need it to appear literally. The /static/v1 query format can be easier to read if the label or message contains several special characters.

1
2
3
4
5
6
<!-- Escape hyphens (--) and underscores (__) -->
![Build Status](https://img.shields.io/badge/build--status-passing-brightgreen)
![Spring Boot RC](https://img.shields.io/badge/Spring__Boot-3.4--RC1-6DB33F)

<!-- Use the query format for punctuation-heavy labels -->
![Spring Boot RC](https://img.shields.io/static/v1?label=Spring+Boot&message=3.4-RC1&color=6DB33F)

I use static badges when the value changes alongside the README, as with a runtime version or license. For CI status or an image tag, an external result is the source of truth. A dynamic badge can show that result as the underlying job or registry changes.

BadgeUpdatesUseful forDetail to check
Shields.io staticManuallyRuntime and licenseUpdate after a version change
GitHub ActionsPer workflow runBuild and test statusSelect the branch with ?branch=
SonarCloudAfter analysisQuality gateSupply the project key and metric
Docker Hub via Shields.ioAfter data becomes visible through the cacheTag and image sizeRegistry updates may take a few minutes to appear
1
2
3
4
5
6
7
8
9
<!-- GitHub Actions workflow badge -->
[![CI](https://github.com/OWNER/REPO/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/OWNER/REPO/actions/workflows/ci.yml)

<!-- SonarCloud quality gate badge -->
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=PROJECT_KEY&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=PROJECT_KEY)

<!-- Docker Hub version and image size badges -->
![Docker Version](https://img.shields.io/docker/v/USER/REPO?sort=semver)
![Docker Size](https://img.shields.io/docker/image-size/USER/REPO/latest)

An external badge service cannot fetch a private repository without suitable access. For private CI status, use GitHub’s native workflow badge and verify what authenticated collaborators see.

When a badge is tied to a workflow, I link the image to the workflow run list. The small badge tells me whether to investigate, and the link takes me to the logs. Check the branch query as part of review. A badge for a deployment branch and a badge for the default branch can both be valid while answering different questions.

Reserve Markdown alerts for information that needs it

GitHub offers five alert types. I choose the marker that describes what a reader should do with the message.

MarkerIntentionExample
[!NOTE]Provide helpful backgroundSupported runtime
[!TIP]Offer an optional shortcutStarting services with Docker Compose
[!IMPORTANT]State a prerequisiteRequired JDK or environment file
[!WARNING]Prevent a foreseeable problemA setting restricted to the local profile
[!CAUTION]Explain a serious riskA script that deletes database volumes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
> [!NOTE]
> Tested with Java 21 and virtual threads enabled.

> [!TIP]
> Start PostgreSQL and Redis together with `docker compose up -d`.

> [!IMPORTANT]
> Copy `.env.example` to `.env` and fill in the required values before starting.

> [!WARNING]
> Use `ddl-auto=create` only in the local profile.

> [!CAUTION]
> Running `scripts/reset-db.sh` deletes all existing volume data.

Alerts cannot be nested. Outside GitHub, a Markdown renderer may display the marker as plain quote text, including on package pages. Keep the sentence clear enough to stand on its own there. GitHub documentation on alerts

Keep architecture diagrams in the diff

A Mermaid fence keeps the diagram’s source in the same Markdown file as the rest of the README. GitHub renders it in the page, and reviewers can see the text change when a component moves or an edge is added. A short vertical flow is also easier to read in narrow viewports.

flowchart TD
    Client["Client (Web / Mobile)"] --> Gateway["API Gateway (/api/v1)"]
    Gateway -->|"Validate JWT"| App["Spring Boot App"]
    App --> Cache["Redis (Session / Cache)"]
    App --> DB["PostgreSQL (Primary DB)"]

Characters such as parentheses, brackets, slashes, colons, and ampersands can be mistaken for Mermaid syntax. Quote labels that contain them. GitHub’s bundled Mermaid version may differ from the one in your editor, so I check the pull request preview instead of assuming both renderers behave identically.

Describe the edge when it carries information a reader needs. In this example, the label marks where JWT validation happens. Keeping that label short leaves room to read the actual component names on a phone.

Review the rendered README

I start with three to five badges that answer questions about the project, one or two alerts for setup or operational risks, and a diagram with four to six nodes. Preview the Markdown on GitHub. Check that badge links open their source, alerts are readable as plain quotes, and the diagram fits on a narrow screen. Add details where onboarding questions recur.

This post is licensed under CC BY 4.0 by the author.