Architecture
This document provides an overview of CVWonder's internal architecture and code organization.
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 reload
Key Components
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)
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
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)
Parses CV YAML files into Go data structures using the models defined in internal/model.
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)
Validates CV YAML files against the JSON schema to ensure data integrity.
Watcher (internal/watcher)
Monitors CV and theme files for changes to enable live reload during development.
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 parsinggithub.com/sirupsen/logrus: Structured logginggithub.com/spf13/cobra: CLI framework
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
- 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/...