How d1gitale/spaced works
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: root.go Root command · adapter.go Storage contract · check.go Check review · list.go List cards
Components 17
CLI commands
User-facing command handlers.
- Root command
internal/cli/root.go - Add card
internal/cli/add.go - Check review · Scores a review and persists the next schedule.
internal/cli/check.go - List cards · Filters due cards and renders JSON or plain output.
internal/cli/list.go - Rename card
internal/cli/rename.go - Delete card
internal/cli/delete.go
Domain and scheduling
Card state and review logic.
- Cards and review state
internal/domain/models.go - Storage contract · Persistence port consumed by command flows.
internal/domain/adapter.go - SM-2 scheduler · Calculates updated review interval and next date.
pkg/sm2/sm2.go
Local persistence
Replaceable storage boundary backed by SQLite.
- SQLite adapter · Owns database connection, schema, and card records.
internal/adapter/sqlite/sqlite.go
Runtime services
Shared configuration, output, and logging.
- Configuration
pkg/config/config.go - Output formatting
pkg/format/format.go - Logging
pkg/logger/logger.go - Constants
pkg/constants/constants.go
Other components
- Application entry
cmd/app/main.go - Linux installer · Installs the binary and provisions systemd notification support.
scripts/install_update_linux.sh - systemd notifications · Provides installed desktop notification cadence.
Connections 21
- 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