# skufu/chirpy architecture

> Architecture diagram of the GitHub repository skufu/chirpy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/skufu/chirpy
- Repository: https://github.com/skufu/chirpy

## Overview

##### Project type and purpose
- This is a lightweight Go‑based HTTP server (a small “microservice” or open‑source tool) whose sole purpose is to serve static files and expose simple health, metrics, and reset endpoints.

##### File structure
- Top‑level Go files:
- main.go – application entrypoint that sets up the HTTP server and routes
- metrics.go – implements metricsHandler and middlewareMetricsInc
- reset.go – implements resetHandler
- readiness.go – implements readinessHandler
- Chirpy (binary output?) and out directory (build artifacts)
- assets/ and index.html – static assets root and default landing page
- go.mod – module definition for dependency management
- .gitignore – ignore rules

##### README for additional insights
- HTTP endpoints: /healthz, /metrics, /reset, /app/*
- Middleware pattern used to wrap the static file handler for counting
- Atomic counter in apiConfig holds server state (hit counter)

##### Detail without over‑splitting
- That middleware wraps only the /app/* handler
- A callout for Go’s net/http ServeMux as the central routing component

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client"]:::external

    subgraph "Chirpy HTTP Service"
        Router["ServeMux Router\n(port 8080)"]:::server
        Middleware["Middleware\n(request counter)"]:::middleware
        StaticHandler["Static File Handler\n(/app/*)"]:::handler
        HealthHandler["Health Handler\n(/healthz)"]:::handler
        MetricsHandler["Metrics Handler\n(/metrics)"]:::handler
        ResetHandler["Reset Handler\n(/reset)"]:::handler
        Counter[(Atomic Counter)]:::datastore
        FileSystem["Static Assets\n(assets/, index.html)"]:::filesystem
    end

    Client --> Router
    Router -->|"/app/*"| Middleware
    Middleware --> StaticHandler
    StaticHandler --> FileSystem
    Router -->|"/healthz"| HealthHandler
    Router -->|"/metrics"| MetricsHandler
    MetricsHandler --> Counter
    Router -->|"/reset"| ResetHandler
    ResetHandler --> Counter

    subgraph "Project Files"
        Mod["go.mod"]:::projectFile
        Binary["Chirpy (binary)"]:::projectFile
        Out["out/"]:::projectFile
    end

    click Router "https://github.com/skufu/chirpy/blob/main/main.go"
    click Middleware "https://github.com/skufu/chirpy/blob/main/metrics.go"
    click StaticHandler "https://github.com/skufu/chirpy/blob/main/main.go"
    click FileSystem "https://github.com/skufu/chirpy/tree/main/assets/"
    click HealthHandler "https://github.com/skufu/chirpy/blob/main/readiness.go"
    click MetricsHandler "https://github.com/skufu/chirpy/blob/main/metrics.go"
    click ResetHandler "https://github.com/skufu/chirpy/blob/main/reset.go"
    click Counter "https://github.com/skufu/chirpy/blob/main/main.go"
    click Mod "https://github.com/skufu/chirpy/blob/main/go.mod"
    click Binary "https://github.com/skufu/chirpy/tree/main/Chirpy"
    click Out "https://github.com/skufu/chirpy/tree/main/out/"

    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef server fill:#bbf,stroke:#333,stroke-width:1px
    classDef middleware fill:#bfb,stroke:#333,stroke-width:1px
    classDef handler fill:#ffb,stroke:#333,stroke-width:1px
    classDef datastore fill:#fbf,stroke:#333,stroke-width:1px
    classDef filesystem fill:#fbb,stroke:#333,stroke-width:1px
    classDef projectFile fill:#ddd,stroke:#333,stroke-width:1px
```
