Architecture
This document provides an overview of CVWonder’s internal architecture and code organization.
Project Structure
Section titled “Project Structure”CVWonder is organized into several internal packages, each with a specific responsibility:
internal/├── cvparser/ # CV YAML file parsing├── cvrender/ # Rendering CV to different formats│ ├── html/ # HTML rendering│ └── pdf/ # PDF rendering├── cvserve/ # Local development server├── model/ # CV data models├── themes/ # Theme management│ └── config/ # Theme configuration├── utils/ # Shared utilities├── validator/ # CV YAML validation├── version/ # Version management└── watcher/ # File watching for live reloadKey Components
Section titled “Key Components”Utils Package (internal/utils)
Section titled “Utils Package (internal/utils)”The utils package provides cross-cutting utilities used throughout the application:
- Authentication (
auth.go): Centralized GitHub authentication for both API and Git operationsGetGitHubToken(): Retrieves GitHub tokens from multiple sources (gh CLI, environment variables)GetGitHubClient(): Returns authenticated GitHub API clientGetGitAuth(): Returns Git authentication for clone operations
- Configuration (
config.go): Configuration management - Logger (
logger.go): Logging utilities - Common utilities (
utils.go): File operations, directory handling, etc.
Theme Management (internal/themes)
Section titled “Theme Management (internal/themes)”Handles theme installation, creation, and listing:
- Theme installation: Downloads themes from GitHub repositories (public or private)
- Theme creation: Scaffolds new theme projects
- Theme configuration: Validates and manages theme metadata
Authentication for Private Repositories
Section titled “Authentication for Private Repositories”CVWonder uses a centralized authentication mechanism (in internal/utils/auth.go) that supports:
- GitHub CLI (
gh): Automatic authentication ifgh auth loginwas used - Environment variables:
GITHUB_TOKENorGH_TOKEN - Fallback: Unauthenticated access for public repositories
This authentication is used for:
- Fetching theme metadata (
theme.yaml) via GitHub API - Cloning theme repositories via Git
CV Parser (internal/cvparser)
Section titled “CV Parser (internal/cvparser)”Parses CV YAML files into Go data structures using the models defined in internal/model.
CV Renderer (internal/cvrender)
Section titled “CV Renderer (internal/cvrender)”Transforms CV data into different output formats:
- HTML: Uses Go’s
html/templatepackage with theme templates - PDF: Uses the
rodpackage to render HTML in a headless browser and export to PDF
Validator (internal/validator)
Section titled “Validator (internal/validator)”Validates CV YAML files against the JSON schema to ensure data integrity.
Watcher (internal/watcher)
Section titled “Watcher (internal/watcher)”Monitors CV and theme files for changes to enable live reload during development.
Dependencies
Section titled “Dependencies”Key external dependencies:
-
GitHub Integration:
github.com/google/go-github: GitHub API clientgithub.com/cli/go-gh/v2: GitHub CLI integration for authenticationgolang.org/x/oauth2: OAuth2 authenticationgithub.com/go-git/go-git/v5: Git operations (cloning themes)
-
Rendering:
html/template: HTML templating (Go standard library)github.com/go-rod/rod: Headless browser for PDF generation
-
Utilities:
github.com/goccy/go-yaml: YAML parsinglog/slog(Go standard library): Diagnostic loggingcharm.land/lipgloss/v2andgithub.com/charmbracelet/colorprofile: Terminal styling and color detectiongithub.com/spf13/cobra: CLI framework
Output: UI and logger
Section titled “Output: UI and logger”Two packages own everything that reaches the terminal. Keep them apart:
cmd/*talks to the UI (internal/ui): headers, step lines, results, tables and errors. Commands return errors (RunE); the root command renders them on stderr, with a hint when you wrap the error withui.WithHint.internal/*talks to the logger (log/slog, installed byinternal/logger):slog.Debug(...)for internal chatter,slog.Warn(...)for recoverable problems.internal/*packages never print and never callos.Exit.
The root command’s PersistentPreRunE builds both from --log-level/--quiet and routes the streams. A command whose output is data (not progress) is marked with Annotations: ui.DataAnnotations() and writes its payload with ui.Payload(); everything else it prints goes to stderr so stdout stays pipe-safe.
Adding New Features
Section titled “Adding New Features”When adding new features:
- Shared utilities: Add to
internal/utilsif the feature is cross-cutting - Domain-specific: Add to the appropriate package (e.g., new export format in
cvrender) - Tests: Add unit tests in
*_test.gofiles alongside your code - Documentation: Update relevant documentation in
docs/github-pages/docs/
Testing
Section titled “Testing”- Unit tests: Each package has
*_test.gofiles - Mocks: Generated mocks are in
mocks/subdirectories (using mockery) - Fixtures: Test data is in
internal/fixtures/
Run tests:
go test ./...Run tests for a specific package:
go test ./internal/utils/...