# ai-fn/logpretty architecture

> Architecture diagram of the GitHub repository ai-fn/logpretty, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ai-fn/logpretty
- Repository: https://github.com/ai-fn/logpretty

## Overview

logpretty is an early-stage Go CLI for streaming log lines from stdin to stdout. Its working path handles arguments and signals, reads bounded lines, and flushes output in bursts; long lines are marked when truncated. A separate, implemented parsing subsystem recognizes JSON and logfmt and assigns time, level, and message roles, but the README explicitly says parsing and formatting are not yet wired into the CLI. Filtering, colors, and pretty rendering remain planned capabilities. Edges reflect shown calls; parser-to-CLI wiring is therefore omitted.

Main entry points: [`internal/app/app.go`](https://github.com/ai-fn/logpretty/blob/main/internal/app/app.go) (CLI pipeline), [`internal/parse/detect.go`](https://github.com/ai-fn/logpretty/blob/main/internal/parse/detect.go) (Format detection), [`internal/parse/json.go`](https://github.com/ai-fn/logpretty/blob/main/internal/parse/json.go) (JSON fields), [`internal/parse/roles.go`](https://github.com/ai-fn/logpretty/blob/main/internal/parse/roles.go) (Role assignment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI control"]
  node_command["Command entry<br/>[main.go]"]
end

subgraph group_stream["Stream handling"]
  node_app["CLI pipeline<br/>[app.go]"]
  node_line_reader["Bounded line reader<br/>[linereader.go]"]
end

subgraph group_parsing["Parsing model"]
  node_entry_model["Parsed entry<br/>[entry.go]"]
  node_value_text["Value decoding<br/>[value.go]"]
  node_level_model["Level vocabulary<br/>[level.go]"]
  node_parser["Format detection<br/>[detect.go]"]
  node_json_parser["JSON fields<br/>[json.go]"]
  node_logfmt_parser["Logfmt fields<br/>[logfmt.go]"]
  node_role_assignment["Role assignment<br/>[roles.go]"]
end

node_operator(("Log producer"))
node_stdout_reader(("Output reader"))
node_signal_source(("OS signals"))

node_signal_source -->|"cancels on"| node_command
node_command -->|"runs"| node_app
node_operator -->|"supplies stdin"| node_app
node_app -->|"reads lines"| node_line_reader
node_app -->|"writes output"| node_stdout_reader
node_parser -->|"tries JSON"| node_json_parser
node_parser -->|"tries logfmt"| node_logfmt_parser
node_parser -->|"assigns roles"| node_role_assignment
node_json_parser -->|"builds fields"| node_entry_model
node_logfmt_parser -->|"builds fields"| node_entry_model
node_role_assignment -->|"marks roles"| node_entry_model
node_role_assignment -->|"parses levels"| node_level_model
node_json_parser -->|"decodes keys"| node_value_text

click node_command "https://github.com/ai-fn/logpretty/blob/main/cmd/logpretty/main.go"
click node_app "https://github.com/ai-fn/logpretty/blob/main/internal/app/app.go"
click node_line_reader "https://github.com/ai-fn/logpretty/blob/main/internal/linereader/linereader.go"
click node_entry_model "https://github.com/ai-fn/logpretty/blob/main/internal/entry/entry.go"
click node_value_text "https://github.com/ai-fn/logpretty/blob/main/internal/entry/value.go"
click node_level_model "https://github.com/ai-fn/logpretty/blob/main/internal/entry/level.go"
click node_parser "https://github.com/ai-fn/logpretty/blob/main/internal/parse/detect.go"
click node_json_parser "https://github.com/ai-fn/logpretty/blob/main/internal/parse/json.go"
click node_logfmt_parser "https://github.com/ai-fn/logpretty/blob/main/internal/parse/logfmt.go"
click node_role_assignment "https://github.com/ai-fn/logpretty/blob/main/internal/parse/roles.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_command toneBlue
class node_app,node_line_reader toneAmber
class node_entry_model,node_value_text,node_level_model,node_parser,node_json_parser,node_logfmt_parser,node_role_assignment toneMint
class node_operator,node_stdout_reader,node_signal_source toneIndigo
```

## Components

### CLI control

- [Command entry](https://github.com/ai-fn/logpretty/blob/main/cmd/logpretty/main.go): `cmd/logpretty/main.go`

### Stream handling

- [CLI pipeline](https://github.com/ai-fn/logpretty/blob/main/internal/app/app.go): `internal/app/app.go`
- [Bounded line reader](https://github.com/ai-fn/logpretty/blob/main/internal/linereader/linereader.go): `internal/linereader/linereader.go`

### Parsing model

- [Parsed entry](https://github.com/ai-fn/logpretty/blob/main/internal/entry/entry.go): `internal/entry/entry.go`
- [Value decoding](https://github.com/ai-fn/logpretty/blob/main/internal/entry/value.go): `internal/entry/value.go`
- [Level vocabulary](https://github.com/ai-fn/logpretty/blob/main/internal/entry/level.go): `internal/entry/level.go`
- [Format detection](https://github.com/ai-fn/logpretty/blob/main/internal/parse/detect.go): `internal/parse/detect.go`
- [JSON fields](https://github.com/ai-fn/logpretty/blob/main/internal/parse/json.go): `internal/parse/json.go`
- [Logfmt fields](https://github.com/ai-fn/logpretty/blob/main/internal/parse/logfmt.go): `internal/parse/logfmt.go`
- [Role assignment](https://github.com/ai-fn/logpretty/blob/main/internal/parse/roles.go): `internal/parse/roles.go`

### Other components

- **Log producer**
- **Output reader**
- **OS signals**

## Connections

- OS signals → Command entry: cancels on (evidence: `cmd/logpretty/main.go`)
- Command entry → CLI pipeline: runs (evidence: `cmd/logpretty/main.go`)
- Log producer → CLI pipeline: supplies stdin (evidence: `internal/app/app.go`)
- CLI pipeline → Bounded line reader: reads lines (evidence: `internal/app/app.go`)
- CLI pipeline → Output reader: writes output (evidence: `internal/app/app.go`)
- Format detection → JSON fields: tries JSON (evidence: `internal/parse/detect.go`)
- Format detection → Logfmt fields: tries logfmt (evidence: `internal/parse/detect.go`)
- Format detection → Role assignment: assigns roles (evidence: `internal/parse/detect.go`)
- JSON fields → Parsed entry: builds fields (evidence: `internal/parse/json.go`)
- Logfmt fields → Parsed entry: builds fields (evidence: `internal/parse/logfmt.go`)
- Role assignment → Parsed entry: marks roles (evidence: `internal/parse/roles.go`)
- Role assignment → Level vocabulary: parses levels (evidence: `internal/parse/roles.go`)
- JSON fields → Value decoding: decodes keys (evidence: `internal/parse/json.go`)
