A training exercise needs more than a picture of a pitch. A coach needs to show where a player starts, which gate to pass through and what happens next. We need that drawing in a web catalogue and in a coach's Android or iPhone app, at both card and full-screen sizes.
We extracted that drawing layer into Football Diagrams: an MIT-licensed JSON format with a React SVG renderer and a Kotlin/Compose Canvas renderer. You can use it independently of CobraHQ, with your own exercises, storage and controls.
The useful unit to share turned out to be the drawing document. A screenshot fixes one view. A document lets the gate stay three metres wide whether the host draws a small card or a full-screen Canvas. The exercise author works in metres; the renderer works out the pixels.
A drawing you can keep as data
The document describes a rectangular playing area, positioned players and equipment, movement arrows, labels and frames. Positions and dimensions use metres. The origin is the top-left of the area: x increases to the right, y downwards.
There are 13 player and equipment kinds, including cones, gates, goals, mannequins and ladders. Passes use solid arrows, runs use dashed arrows, dribbles use waves and shots use heavier strokes. Each renderer draws the frame you select. Your application decides when to change frames and where to show coaching captions; the library does not animate players or invent their positions.
What can you draw?
These synthetic examples use the released React renderer, with the same document format accepted by Compose. Each drawing starts with positions in metres, rather than a fixed image size.
Possession: find the spare player
A 24 × 20 metre rondo uses four blue players, two red opponents and a yellow neutral player marked N. Numbered passes show the ball moving through the spare player; a dashed run shows a supporting movement. The shaded, labelled area marks the space to support in. Teams, player numbers and zones can explain an exercise without a full-size pitch.
Finishing: build an equipment circuit
A ladder and poles mark a warm-up station; a coach and spare ball sit beside the start. Player 7 carries the ball through the three-metre gate, around the mannequin, then shoots at a six-metre goal. Cones and a flat marker complete the setup. The wavy dribble and heavier shot distinguish carrying the ball from striking it.
An attack in two frames
A single document can hold successive phases with different player positions and ball ownership. Here, the first frame switches play to player 7; the second starts later, after the players have moved, and shows the final pass and shot. These are authored snapshots. Your application chooses the frame and presents the coaching explanation.
Across these drawings and the small example below, you can see all 13 player and equipment kinds and all four arrow styles. The library supplies the notation; you supply the football decisions, frame sequence and coaching content.
Start with one document
Save this as diagram.json. Player 7 passes through a three-metre gate to player 9, then follows the supporting run. The goal and gate use explicitly authored widths and angles, so the document selects format_version: 2.
{
"format_version": 2,
"title": "Pass through the gate",
"area": { "shape": "rectangle", "length_m": 30, "width_m": 20 },
"frames": [{
"id": "setup",
"title": "Pass and support",
"objects": [
{ "kind": "player", "x": 5, "y": 10,
"number": 7, "colour": "blue", "ball": true },
{ "kind": "player", "x": 22, "y": 10,
"number": 9, "colour": "red", "label": "Receiver" },
{ "kind": "gate", "x": 15, "y": 10,
"width": 3, "angle": 90, "colour": "yellow" },
{ "kind": "mini_goal", "x": 28, "y": 10,
"width": 3, "angle": 90 }
],
"arrows": [
{ "kind": "pass", "sequence": 1,
"points": [{ "x": 6, "y": 10 }, { "x": 21, "y": 10 }] },
{ "kind": "run", "sequence": 2,
"points": [
{ "x": 5, "y": 12 },
{ "x": 12, "y": 16 },
{ "x": 21, "y": 12 }
] }
]
}]
}A gate's width is the distance between its cone centres. For a goal, the angle describes its mouth axis: 90 degrees gives a vertical mouth, with the net extending to the right. These meanings are defined in the Format and compatibility reference. The parsers validate the chosen version locally and reject unsupported fields and versions.
Render it in React
In an existing React application, install the tagged source release. Version 0.3.0 ships built ESM and TypeScript declarations and supports React 18.3.1 and 19. Commit the lockfile so the tag resolves to the reviewed full source commit.
npm install github:nick-cobra/football-diagrams#v0.3.0Put this component beside diagram.json in an application with JSON imports, such as Vite. Parse once for this static example; for changing content, validate at your document boundary and pass a new snapshot when it changes.
import { parseDiagram } from 'football-diagrams';
import { DiagramSvg } from 'football-diagrams/react';
import source from './diagram.json';
const diagram = parseDiagram(source);
export function TrainingDiagram() {
return <DiagramSvg diagram={diagram} frameIndex={0} />;
}DiagramSvg fills the available width and derives its natural height from the drawing. The diagram above uses this same JSON and the public renderer. For a fixed-size card, size both the container and its SVG, and use thumbnail to omit badges and the area label:
<div className="thumbnail">
<DiagramSvg diagram={diagram} frameIndex={0} thumbnail />
</div>
/* Host stylesheet */
.thumbnail { width: 100%; height: 168px; }
.thumbnail svg { display: block; width: 100%; height: 100%; }The renderer can produce server markup without browser globals. After hydration it measures the actual viewport and fonts. Keep the figure's purpose available as text or an accessible description, particularly when a small thumbnail makes labels hard to read.
Use the same document in Compose
In a Compose Multiplatform application, the Kotlin renderer draws directly on a Canvas; it does not send an SVG through a WebView. Version 0.3.0 is distributed as source, so include its standalone Gradle project as a composite. These commands assume your application and the checkout are siblings:
git clone --branch v0.3.0 --depth 1 https://github.com/nick-cobra/football-diagrams.git// Application settings.gradle.kts
includeBuild("../football-diagrams/kotlin") {
dependencySubstitution {
substitute(module("io.github.nick-cobra:football-diagrams"))
.using(project(":library"))
}
}
// Application shared/build.gradle.kts
kotlin {
sourceSets.commonMain.dependencies {
implementation("io.github.nick-cobra:football-diagrams:0.3.0")
}
}Read the same JSON file through your application's resource or storage layer. CalldecodeDiagram when preparing the document, handle validation errors there, then pass the admitted result to Compose:
import androidx.compose.runtime.Composable
import io.github.footballdiagrams.Diagram
import io.github.footballdiagrams.Diagrams
import io.github.footballdiagrams.FootballDiagram
fun decodeDiagram(jsonText: String): Diagram = Diagrams.parse(jsonText)
@Composable
fun TrainingDiagram(diagram: Diagram) {
FootballDiagram(diagram = diagram, frameIndex = 0)
}Prepare changed documents away from the UI thread and reuse each snapshot while it is unchanged. The drawing composable has no loading or parsing work to repeat. Your host still owns navigation, frame controls, themes and safe-area insets.
The released source targets Android, JVM, iOS arm64 and iOS Simulator arm64. Its documented toolchain uses JDK 21, Gradle 9.5.1, Kotlin 2.4.20 and Compose Multiplatform 1.12.1; Android requires API 26 or later. Native builds also need a compatible Xcode. Use the runnable Android example or Compose/iOS example for the complete setup, including the UIKit scene host and required iOS plist settings. The composite substitution above supplies the dependency; these instructions do not assume Maven Central or npm-registry publication.
How Cobra uses it
Cobra stores complete exercises: the drawing, coaching content, catalogue metadata and publication information. Thin adapters project the drawing fields into the public format. React renders the result in our web surfaces; the mobile adapter passes the corresponding domain data to Compose. Account access, permissions, caching and saved training plans stay in Cobra.
Three version numbers have different jobs. The package is 0.3.0, the drawing format is 2, and Cobra's stored exercise schema also happens to be 2. That last match is coincidental. Our adapter selects public format 2 without rewriting the stored exercise document.
The 0.3.0 reader also accepts format 1 with its original geometry. Upgrading the package does not turn a format-1 gate width or goal angle into format-2 semantics. An older 0.2.1 reader rejects format 2, so a rollback needs a compatible reader or a deliberate document conversion. We keep the web source pin and Kotlin source composite on the same reviewed revision and verify both consumers when updating.
What we learned at the edges
A schema check tells us whether a document belongs to the format. Rendering it also needs a finite amount of work. Extracting the renderer made those assumptions easier to test: an extremely small pitch can turn a decorative grass stripe into far too much work. A distant dribble path can generate vertices nobody will see. Crowded, long labels and zero-size native layouts need explicit behaviour too.
The released renderers clip to the host viewport and bound grass stripes and active-frame dribble geometry. Compose reuses prepared paths and bounds its text-layout cache; React keeps its server rendering independent of browser font measurements. Rendered detail can decrease at extreme constraints while the authored document stays intact. These are finite rendering policies, not a promise that arbitrary input is cheap or that every crowded label can avoid overlap.
Standalone SVG export exposed another boundary: a string can be valid JSON but contain characters XML cannot represent. Version 0.3.0 declares the SVG namespace and replaces XML-forbidden characters in SVG output while preserving the original JSON strings. Our adoption checks exercise actual server-rendered SVG as XML, alongside adapter, geometry and native rendering tests.
A renderer's budget cannot limit how many full documents an application keeps in memory. Bound input before parsing, handle validation failures, keep changed inputs immutable and set your own catalogue, draft and response budgets. We continue to harden those consumer boundaries in Cobra; the library release does not make that separate work disappear. SVG and Canvas share notation and proportions, while fonts and rasterisation remain platform-specific.
Open source at CobraHQ
Try it in your application
Start with the small document above, render it in the platform you use, then add your own content and controls. The repository contains the versioned schemas, shared valid and invalid fixtures, and independent web and Kotlin examples. No Cobra account, backend or stylesheet is required. The examples are synthetic; the package does not bundle a drill catalogue or customer data.
View Football Diagrams on GitHub