-
Notifications
You must be signed in to change notification settings - Fork 4
Developer Guide
This guide is intended for developers who want to contribute to LLMDog or understand its internals. We'll cover the project structure, key components, and how to extend or modify the application.
LLMDog follows a clean architecture with clear separation of concerns. Here's an overview of the main components:
llmdog/
├── cmd/ # Command-line entry points
│ └── llmdog/ # Main application command
├── internal/ # Internal packages
│ ├── bookmarks/ # Bookmark management
│ ├── git/ # Git integration
│ ├── model/ # Core application model and logic
│ └── ui/ # User interface components
The entry point for the application, responsible for:
- Parsing command-line arguments
- Displaying version and help information
- Initializing the application model
- Starting the TUI
The core of the application, handling:
- Application state and business logic
- File and directory management
- Selection tracking
- Output generation
- Configuration management
- Bookmark operations
Split into two main files:
-
ui.go: Core UI components and styling -
bookmark_ui.go: UI components for bookmark management
The UI uses the [Bubble Tea](https://github.com/charmbracelet/bubbletea) framework for the terminal interface and [Lip Gloss](https://github.com/charmbracelet/lipgloss) for styling.
Handles all Git-related functionality:
- Detecting Git repositories
- Parsing
.gitignorefiles - Getting modified and staged files
- Repository information
Manages saved selections:
- Loading and saving bookmarks
- Creating, updating, and deleting bookmarks
- Bookmark data structure
- The application starts in
main.go, which initializes the model - The model loads files from the current directory and sets up the UI
- User interactions are handled through the Bubble Tea event loop:
- Key presses are captured and processed
- State is updated accordingly
- UI is re-rendered based on the new state
- When the user confirms selection, the model generates Markdown output
- Output is copied to the clipboard and the application exits
Represents a file or directory in the UI:
type FileItem struct {
Path string
Name string
IsDir bool
Selected bool
Depth int
Expanded bool
GitIgnored bool
ChildrenLoaded bool
MatchesContent bool
}Represents a saved selection:
type Bookmark struct {
Name string
Description string
FilePaths []string
RootPath string
Created time.Time
Modified time.Time
}The main application state:
type Model struct {
list list.Model
preview string
items []ui.FileItem
cwd string
gitignoreRegexp *regexp.Regexp
// ... (many more fields)
}- Open
cmd/llmdog/main.go - Add a new case to the command-line argument switch statement
- Implement the functionality for the new option
case "--my-new-option":
// Handle the new option
fmt.Println("Processing new option...")
// Do something
os.Exit(0)- Update the
Configstruct ininternal/model/model.go:
type Config struct {
// Existing fields
ShowHiddenFiles bool
FuzzyThreshold float64
// New field
MyNewOption string
}- Update the
LoadConfigfunction to include a default value - Apply the configuration option where needed in the codebase
- Define any new UI styles in
internal/ui/ui.go - Update the
Modelstruct if new state is needed - Add handler logic in the
Updatemethod ininternal/model/model.go - Update the
Viewmethod to render the new feature
- Open
internal/model/model.go - Find the
Updatemethod and thetea.KeyMsgcase - Add a new case for your keyboard shortcut:
case "ctrl+x": // New shortcut
// Implement the functionality
return m, nilgo build -o llmdog ./cmd/llmdog# Linux/macOS
BUBBLES_DEBUG=1 ./llmdog
# Windows PowerShell
$env:BUBBLES_DEBUG=1; ./llmdog# For Windows
GOOS=windows GOARCH=amd64 go build -o llmdog.exe ./cmd/llmdog
# For macOS
GOOS=darwin GOARCH=amd64 go build -o llmdog-macos ./cmd/llmdog
# For Linux
GOOS=linux GOARCH=amd64 go build -o llmdog-linux ./cmd/llmdogLLMDog follows standard Go conventions:
- Use
gofmtorgo fmtto format code - Follow [Effective Go](https://golang.org/doc/effective_go) guidelines
- Use meaningful variable and function names
- Write comments for exported functions and types
- UI-related code belongs in the
internal/uipackage - Model and business logic goes in
internal/model - Keep the main package minimal, delegating to internal packages
- Use the Bubble Tea update/view pattern consistently
- File Loading: For large directories, files are loaded lazily when directories are expanded
- Preview Generation: Limited to a configurable maximum size to prevent slowdowns
- Content Search: Can be slow on large projects, only enabled when explicitly toggled
- Gitignore Processing: Converted to efficient regular expressions for faster matching
Update the getFileIcon function in internal/ui/ui.go to add new file type icons:
func getFileIcon(name string, isDir bool) string {
// ...
switch ext {
// ...
case ".newext":
return "🆕" // Icon for new extension
// ...
}
}Modify the BuildOutput function in internal/model/model.go to change how the Markdown output is formatted.
To add new filtering capabilities, update the performSearch method in internal/model/model.go.