Skip to content

12 API and Data Models

Vicky Patel edited this page Nov 18, 2026 · 1 revision

12. API & Data Models Reference

Go Data Structures, JSON Payloads, and Endpoint Contracts


πŸ“ Core Domain Types (internal/catalog/types.go)

GitVerse models the GitHub gamification domain through strongly typed Go structures:

package catalog

import "time"

// Status represents the operational availability of an achievement.
type Status string

const (
    StatusEarnable Status = "earnable" // Actively earnable by all users
    StatusDisabled Status = "disabled" // Temporarily disabled or inactive
    StatusRetired  Status = "retired"  // Historical, permanently closed
    StatusInternal Status = "internal" // Exclusive to GitHub staff
)

// Provenance classifies the certainty and origin of a metric.
type Provenance string

const (
    ProvenanceOfficial   Provenance = "official"   // Read from verified profile HTML
    ProvenanceCalibrated Provenance = "calibrated" // Inferred from milestone events
    ProvenanceCounted    Provenance = "counted"    // Dynamically tallied via API
)

// Tier represents an unlocked or target level of an achievement.
type Tier struct {
    Level       int       `json:"level"`       // 1, 2, 3, 4
    Name        string    `json:"name"`        // e.g. "Bronze", "Silver", "Gold"
    Multiplier  string    `json:"multiplier"`  // "x1", "x2", "x3", "x4"
    Threshold   int       `json:"threshold"`   // Required metric count
    UnlockedAt  *time.Time `json:"unlocked_at,omitempty"`
    AssetURL    string    `json:"asset_url"`   // SVG or PNG asset
}

// Achievement represents the state of a single badge for a developer.
type Achievement struct {
    ID           string     `json:"id"`            // e.g. "pull-shark"
    Name         string     `json:"name"`          // e.g. "Pull Shark"
    Description  string     `json:"description"`
    Status       Status     `json:"status"`        // earnable, disabled, etc.
    CurrentTier  int        `json:"current_tier"`  // 0 if locked
    CurrentCount int        `json:"current_count"` // Provenance-tagged count
    NextTier     *Tier      `json:"next_tier,omitempty"`
    Delta        int        `json:"delta"`         // Required to reach next tier
    Provenance   Provenance `json:"provenance"`    // official, calibrated, counted
    Tiers        []Tier     `json:"tiers"`
}

// ProfileReport represents the comprehensive output for a user.
type ProfileReport struct {
    Username     string        `json:"username"`
    CheckedAt    time.Time     `json:"checked_at"`
    IsPrivate    bool          `json:"is_private"`
    TotalBadges  int           `json:"total_badges"`
    Achievements []Achievement `json:"achievements"`
}

πŸ“„ JSON Schema (gitverse --json)

Executing gitverse --json <username> or requesting Accept: application/json produces this structured response:

{
  "username": "TheVicky1",
  "checked_at": "2026-11-18T12:00:00Z",
  "is_private": false,
  "total_badges": 8,
  "achievements": [
    {
      "id": "pull-shark",
      "name": "Pull Shark",
      "description": "Opened pull requests that have been merged",
      "status": "earnable",
      "current_tier": 2,
      "current_count": 28,
      "provenance": "counted",
      "delta": 100,
      "next_tier": {
        "level": 3,
        "name": "Gold",
        "multiplier": "x3",
        "threshold": 128,
        "asset_url": "https://github.githubassets.com/assets/pull-shark-gold-90985540b385.png"
      },
      "tiers": [
        { "level": 1, "multiplier": "x1", "threshold": 2 },
        { "level": 2, "multiplier": "x2", "threshold": 16 },
        { "level": 3, "multiplier": "x3", "threshold": 128 },
        { "level": 4, "multiplier": "x4", "threshold": 1024 }
      ]
    }
  ]
}

🌐 HTTP Endpoint Specifications

1. GET /api/stars

Returns real-time stargazers count for the GitVerse repository.

  • Headers:
    Cache-Control: public, s-maxage=60, stale-while-revalidate=120
    Content-Type: application/json
  • Response:
    {
      "stargazers_count": 15
    }

2. GET /check?user={username}

Performs public profile achievement telemetry extraction and renders the interactive HTML report (or JSON if requested via Accept: application/json).

3. GET /badge/:user/:badge

Generates an SVG badge for embedding in README files.

  • Parameters:
    • :user β€” GitHub username.
    • :badge β€” Badge identifier (e.g. pull-shark, starstruck).
  • Response: Content-Type: image/svg+xml.

Clone this wiki locally