# d1gitale/spaced architecture

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

- Interactive diagram: https://gitdiagram.com/d1gitale/spaced
- Repository: https://github.com/d1gitale/spaced

## Overview

#### Purpose and Entry Point
`spaced` is a Go terminal application for managing spaced-repetition cards. Users add named concepts, list cards due for review, score reviews, rename cards, and delete cards. Process startup is `cmd/app/main.go`, which delegates CLI command construction and execution to `internal/cli/root.go`.

#### CLI Command Layer
The CLI is organized as command handlers beneath a shared root command:
- `internal/cli/root.go`
- `internal/cli/add.go`
- `internal/cli/check.go`
- `internal/cli/list.go`
- `internal/cli/rename.go`
- `internal/cli/delete.go`

Commands translate flags and arguments into domain operations. `list` is the presentation boundary, supporting due-card filtering and JSON/plain output; review scoring enters through `check`.

#### Domain Model and Ports
The core model and persistence abstraction are separated from concrete storage:
- `internal/domain/models.go`
- `internal/domain/adapter.go`

Domain models represent cards and their review/scheduling state. The adapter interface defines the storage contract consumed by CLI/domain-facing code, allowing persistence to be replaced without changing command behavior.

#### Scheduling and Review Flow
Card creation persists an initial review state. During review, `check --id --score` loads a card, applies the SM-2 spaced-repetition calculation, and saves updated interval/scheduling metadata. The algorithm is isolated in:
- `pkg/sm2/sm2.go`
- `internal/domain/models.go`
- `internal/cli/check.go`

The resulting next-review date drives `list --due`, which filters cards eligible for review.

#### Persistence Boundary
SQLite is the concrete local persistence implementation:
- `internal/adapter/sqlite/sqlite.go`
- `internal/domain/adapter.go`

The application is local-first: CLI commands use the adapter contract, while SQLite owns database connection, schema/storage operations, and card records. No network service or web runtime is indicated.

#### Shared Runtime Services
Cross-cutting packages supply application settings, constants, formatting, and logging:
- `pkg/config/config.go`
- `pkg/format/format.go`
- `pkg/logger/logger.go`
- `pkg/constants/constants.go`

Formatting is particularly relevant to the `list` output boundary; configuration likely centralizes paths or runtime settings used by the SQLite-backed application.

#### Installation and Notifications
The Linux installer provisions the binary together with a systemd-based service mechanism:
- `scripts/install_update_linux.sh`

That infrastructure is responsible for the README-described desktop notification cadence, while the Go CLI remains the interaction and review-update interface. The required runtime is Go 1.26 or newer for builds; deployed usage targets Linux/systemd when installed via the script.

Main entry points: [`internal/cli/root.go`](https://github.com/d1gitale/spaced/blob/main/internal/cli/root.go) (Root command), [`internal/domain/adapter.go`](https://github.com/d1gitale/spaced/blob/main/internal/domain/adapter.go) (Storage contract), [`internal/cli/check.go`](https://github.com/d1gitale/spaced/blob/main/internal/cli/check.go) (Check review), [`internal/cli/list.go`](https://github.com/d1gitale/spaced/blob/main/internal/cli/list.go) (List cards)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI commands"]
  node_root["Root command<br/>CLI composition<br/>[root.go]"]
  node_add["Add card<br/>CLI command<br/>[add.go]"]
  node_check["Check review<br/>CLI command<br/>[check.go]"]
  node_list["List cards<br/>CLI command<br/>[list.go]"]
  node_rename["Rename card<br/>CLI command<br/>[rename.go]"]
  node_delete["Delete card<br/>CLI command<br/>[delete.go]"]
end

subgraph group_core["Domain and scheduling"]
  node_models["Cards and review state<br/>domain model<br/>[models.go]"]
  node_adapter{{"Storage contract<br/>adapter interface<br/>[adapter.go]"}}
  node_sm2["SM-2 scheduler<br/>scheduling algorithm<br/>[sm2.go]"]
end

subgraph group_storage["Local persistence"]
  node_sqlite[("SQLite adapter<br/>local persistence<br/>[sqlite.go]")]
end

subgraph group_shared["Runtime services"]
  node_config["Configuration<br/>runtime settings<br/>[config.go]"]
  node_format["Output formatting<br/>presentation service<br/>[format.go]"]
  node_logger["Logging<br/>runtime service<br/>[logger.go]"]
  node_constants["Constants<br/>shared definitions<br/>[constants.go]"]
end

node_main(("Application entry<br/>Go entrypoint<br/>[main.go]"))
node_installer["Linux installer<br/>deployment script"]
node_systemd["systemd notifications<br/>Linux runtime"]

node_main -->|"starts"| node_root
node_root -->|"registers"| node_add
node_root -->|"registers"| node_check
node_root -->|"registers"| node_list
node_root -->|"registers"| node_rename
node_root -->|"registers"| node_delete
node_add -->|"creates card"| node_adapter
node_check -->|"loads and saves"| node_adapter
node_check -->|"scores review"| node_sm2
node_sm2 -->|"updates schedule"| node_models
node_list -->|"queries cards"| node_adapter
node_list -->|"renders output"| node_format
node_rename -->|"renames"| node_adapter
node_delete -->|"deletes"| node_adapter
node_adapter -->|"implemented by"| node_sqlite
node_sqlite -->|"uses settings"| node_config
node_sqlite -->|"stores"| node_models
node_root -.->|"logs through"| node_logger
node_root -.->|"uses"| node_constants
node_installer -->|"installs binary"| node_main
node_installer -->|"provisions"| node_systemd

click node_main "https://github.com/d1gitale/spaced/blob/main/cmd/app/main.go"
click node_root "https://github.com/d1gitale/spaced/blob/main/internal/cli/root.go"
click node_add "https://github.com/d1gitale/spaced/blob/main/internal/cli/add.go"
click node_check "https://github.com/d1gitale/spaced/blob/main/internal/cli/check.go"
click node_list "https://github.com/d1gitale/spaced/blob/main/internal/cli/list.go"
click node_rename "https://github.com/d1gitale/spaced/blob/main/internal/cli/rename.go"
click node_delete "https://github.com/d1gitale/spaced/blob/main/internal/cli/delete.go"
click node_models "https://github.com/d1gitale/spaced/blob/main/internal/domain/models.go"
click node_adapter "https://github.com/d1gitale/spaced/blob/main/internal/domain/adapter.go"
click node_sm2 "https://github.com/d1gitale/spaced/blob/main/pkg/sm2/sm2.go"
click node_sqlite "https://github.com/d1gitale/spaced/blob/main/internal/adapter/sqlite/sqlite.go"
click node_config "https://github.com/d1gitale/spaced/blob/main/pkg/config/config.go"
click node_format "https://github.com/d1gitale/spaced/blob/main/pkg/format/format.go"
click node_logger "https://github.com/d1gitale/spaced/blob/main/pkg/logger/logger.go"
click node_constants "https://github.com/d1gitale/spaced/blob/main/pkg/constants/constants.go"
click node_installer "https://github.com/d1gitale/spaced/blob/main/scripts/install_update_linux.sh"

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_root,node_add,node_check,node_list,node_rename,node_delete toneBlue
class node_models,node_adapter,node_sm2 toneAmber
class node_sqlite toneMint
class node_config,node_format,node_logger,node_constants toneRose
class node_main,node_installer,node_systemd toneNeutral
```

## Components

### CLI commands

User-facing command handlers.

- [Root command](https://github.com/d1gitale/spaced/blob/main/internal/cli/root.go): CLI composition · `internal/cli/root.go`
- [Add card](https://github.com/d1gitale/spaced/blob/main/internal/cli/add.go): CLI command · `internal/cli/add.go`
- [Check review](https://github.com/d1gitale/spaced/blob/main/internal/cli/check.go): CLI command · Scores a review and persists the next schedule. · `internal/cli/check.go`
- [List cards](https://github.com/d1gitale/spaced/blob/main/internal/cli/list.go): CLI command · Filters due cards and renders JSON or plain output. · `internal/cli/list.go`
- [Rename card](https://github.com/d1gitale/spaced/blob/main/internal/cli/rename.go): CLI command · `internal/cli/rename.go`
- [Delete card](https://github.com/d1gitale/spaced/blob/main/internal/cli/delete.go): CLI command · `internal/cli/delete.go`

### Domain and scheduling

Card state and review logic.

- [Cards and review state](https://github.com/d1gitale/spaced/blob/main/internal/domain/models.go): domain model · `internal/domain/models.go`
- [Storage contract](https://github.com/d1gitale/spaced/blob/main/internal/domain/adapter.go): adapter interface · Persistence port consumed by command flows. · `internal/domain/adapter.go`
- [SM-2 scheduler](https://github.com/d1gitale/spaced/blob/main/pkg/sm2/sm2.go): scheduling algorithm · Calculates updated review interval and next date. · `pkg/sm2/sm2.go`

### Local persistence

Replaceable storage boundary backed by SQLite.

- [SQLite adapter](https://github.com/d1gitale/spaced/blob/main/internal/adapter/sqlite/sqlite.go): local persistence · Owns database connection, schema, and card records. · `internal/adapter/sqlite/sqlite.go`

### Runtime services

Shared configuration, output, and logging.

- [Configuration](https://github.com/d1gitale/spaced/blob/main/pkg/config/config.go): runtime settings · `pkg/config/config.go`
- [Output formatting](https://github.com/d1gitale/spaced/blob/main/pkg/format/format.go): presentation service · `pkg/format/format.go`
- [Logging](https://github.com/d1gitale/spaced/blob/main/pkg/logger/logger.go): runtime service · `pkg/logger/logger.go`
- [Constants](https://github.com/d1gitale/spaced/blob/main/pkg/constants/constants.go): shared definitions · `pkg/constants/constants.go`

### Other components

- [Application entry](https://github.com/d1gitale/spaced/blob/main/cmd/app/main.go): Go entrypoint · `cmd/app/main.go`
- [Linux installer](https://github.com/d1gitale/spaced/blob/main/scripts/install_update_linux.sh): deployment script · Installs the binary and provisions systemd notification support. · `scripts/install_update_linux.sh`
- **systemd notifications**: Linux runtime · Provides installed desktop notification cadence.

## Connections

- Application entry → Root command: starts
- Root command → Add card: registers
- Root command → Check review: registers
- Root command → List cards: registers
- Root command → Rename card: registers
- Root command → Delete card: registers
- Add card → Storage contract: creates card
- Check review → Storage contract: loads and saves
- Check review → SM-2 scheduler: scores review
- SM-2 scheduler → Cards and review state: updates schedule
- List cards → Storage contract: queries cards
- List cards → Output formatting: renders output
- Rename card → Storage contract: renames
- Delete card → Storage contract: deletes
- Storage contract → SQLite adapter: implemented by
- SQLite adapter → Configuration: uses settings
- SQLite adapter → Cards and review state: stores
- Root command → Logging: logs through
- Root command → Constants: uses
- Linux installer → Application entry: installs binary
- Linux installer → systemd notifications: provisions
