# swoopezz/typer architecture

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

- Interactive diagram: https://gitdiagram.com/swoopezz/typer
- Repository: https://github.com/swoopezz/typer

## Overview

Typer is a single native C++ terminal application: there is one executable, built from `main.cpp` plus two small support modules under `tui/` and `escape/`.

1. **Entry point and orchestration**
   - `main.cpp` is the application entry point and likely owns the full runtime loop.
   - It coordinates input handling, progress tracking, completion detection, and final stats such as WPM and accuracy.

2. **Core application flow**
   - The program presents one target line of text.
   - The user types into the terminal until the line is completed or `q` is pressed.
   - As input arrives, the app compares typed characters against the target text and updates correctness state.

3. **Terminal UI subsystem**
   - `tui/Window.h` and `tui/Window.cpp` form the terminal rendering layer.
   - This module is responsible for drawing the centered text, showing per-character correctness/mistakes, and refreshing the terminal display.

4. **ANSI/terminal control utilities**
   - `escape/escape.h` is a small low-level helper for terminal escape sequences.
   - This is likely used by the TUI layer to control cursor movement, clearing, coloring, and other terminal formatting behavior.

5. **Responsibility split**
   - `main.cpp` handles “what should happen” in the typing session.
   - `tui/Window` handles “how it looks in the terminal.”
   - `escape` provides the raw terminal control primitives that the UI depends on.

6. **Data flow**
   - The target text is loaded or defined in the app logic.
   - User keystrokes are read in the main loop.
   - Typing state is updated character-by-character.
   - The updated state is passed to the window renderer, which redraws the view.

7. **Feedback loop**
   - The architecture is an immediate-feedback terminal loop: input changes the model, the model drives rendering, and the rendering gives the user visual correctness feedback in real time.

8. **Metrics computation**
   - WPM and accuracy are computed after the typing session completes.
   - These metrics are part of the app-level logic rather than the rendering layer, since they summarize the session rather than affect drawing.

9. **Boundary with the environment**
   - The app depends directly on the terminal for input and output.
   - There are no visible external services, databases, or network dependencies.
   - This is a self-contained CLI program.

10. **Runtime and build model**
   - The project is built as a simple C++ binary using `clang++ main.cpp -o typer` per the README.
   - That suggests a very small codebase with minimal build tooling and few layers of abstraction.

11. **Architecture shape**
   - For a diagram, the best model is: terminal user ↔ main application loop ↔ TUI renderer ↔ terminal.
   - `escape` sits under the renderer as a support library for terminal control.

12. **Project maturity**
   - The README explicitly says this is a first C++ learning project, so the architecture is intentionally simple and likely not heavily modularized beyond the basic split between app logic and terminal UI.

Main entry points: [`main.cpp`](https://github.com/swoopezz/typer/blob/main/main.cpp) (Main loop), [`tui/Window.cpp`](https://github.com/swoopezz/typer/blob/main/tui/Window.cpp) (Window), [`escape/escape.h`](https://github.com/swoopezz/typer/blob/main/escape/escape.h) (Escape)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_terminal_user(("User<br/>terminal input"))
  node_main_loop["Main loop<br/>app runtime<br/>[main.cpp]"]
  node_session_stats["Stats<br/>metrics<br/>[main.cpp]"]
end

subgraph group_ui["Terminal UI"]
  node_window_ui["Window<br/>tui renderer<br/>[Window.cpp]"]
end

subgraph group_term["Terminal control"]
  node_escape_ctl["Escape<br/>ansi helper<br/>[escape.h]"]
end

node_terminal_user -->|"keystrokes"| node_main_loop
node_main_loop -->|"render state"| node_window_ui
node_window_ui -->|"cursor/color control"| node_escape_ctl
node_window_ui -->|"feedback"| node_terminal_user
node_main_loop -->|"finish"| node_session_stats
node_session_stats -->|"results"| node_terminal_user

click node_main_loop "https://github.com/swoopezz/typer/blob/main/main.cpp"
click node_session_stats "https://github.com/swoopezz/typer/blob/main/main.cpp"
click node_window_ui "https://github.com/swoopezz/typer/blob/main/tui/Window.cpp"
click node_escape_ctl "https://github.com/swoopezz/typer/blob/main/escape/escape.h"

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_terminal_user,node_main_loop,node_session_stats toneBlue
class node_window_ui toneAmber
class node_escape_ctl toneMint
```

## Components

### Core runtime

Application control flow and session logic

- **User**: terminal input · Person typing into and reading from the terminal session
- [Main loop](https://github.com/swoopezz/typer/blob/main/main.cpp): app runtime · Entry point and orchestration for input handling, typing state, completion, and session flow · `main.cpp`
- [Stats](https://github.com/swoopezz/typer/blob/main/main.cpp): metrics · Computes final WPM and accuracy after the typing session completes · `main.cpp`

### Terminal UI

Rendering and screen refresh layer

- [Window](https://github.com/swoopezz/typer/blob/main/tui/Window.cpp): tui renderer · Renders centered text, per-character correctness, and refreshes the terminal display · `tui/Window.cpp`

### Terminal control

Low-level ANSI escape helpers

- [Escape](https://github.com/swoopezz/typer/blob/main/escape/escape.h): ansi helper · Provides raw terminal escape-sequence primitives used by the UI layer · `escape/escape.h`

## Connections

- User → Main loop: keystrokes · User input drives the typing session state
- Main loop → Window: render state · Updated typing progress is passed to the terminal renderer
- Window → Escape: cursor/color control · Renderer uses escape helpers for terminal positioning and formatting
- Window → User: feedback · Screen redraws give immediate correctness feedback to the user
- Main loop → Stats: finish · Completion logic triggers final session metrics
- Stats → User: results · Final WPM and accuracy are shown at the end of the run
