This document explains the internal workings of GoShed, how it manages projects, and its core architecture.
$HOME/
└── .goshed/
├── project-1/
│ ├── .goshed.json # Project metadata
│ ├── main.go # Project files
│ ├── go.mod
│ └── .git/ # Git repository
└── project-2/
├── .goshed.json
└── ...
Each project is tracked through a .goshed.json
file containing:
{
"created": "2024-12-03T10:00:00Z",
"lastAccessed": "2024-12-03T11:00:00Z",
"name": "project-name",
"template": "web",
"tags": ["api", "experiment"],
"notes": "Testing JWT implementation"
}
This metadata is used for:
- Project tracking
- Cleanup decisions
- Template identification
- Organization
- Search and filtering
Templates are defined in-memory as Go structs:
type Template struct {
Name string
Description string
Files map[string]string
Dependencies []string
}
When creating a new project:
- Template is selected
- Files are created from the template map
- Dependencies are installed (if any)
- Git repository is initialized
- Metadata file is created
Uses urfave/cli
for command parsing:
- Commands are defined in the main app structure
- Each command maps to a specific action function
- Flags provide additional configuration
Built with Bubble Tea framework:
- State Management
type model struct {
screen screen
mainList list.Model
templateList list.Model
projectList list.Model
nameInput textinput.Model
spinner spinner.Model
help help.Model
// ...
}
- Screen Flow
Main Menu ─────┬─── New Project ─── Template Selection
│
├─── List Projects ─── Project Details
│
└─── Clean Projects
- Update Loop
- Handles user input
- Updates model state
- Manages screen transitions
- Executes commands
- Generate project directory
- Apply template
- Initialize Git repository
- Create Go module
- Install dependencies
- Create metadata file
- Update last accessed timestamp
- Load project in editor
- Update metadata
- Verify target location
- Move project files
- Update Go module path
- Remove from GoShed tracking
- Scan all projects
- Check last accessed time
- Remove projects older than threshold
- Update project list
All file operations are handled through Go's standard library:
os.MkdirAll() // Create directories
os.WriteFile() // Write files
os.Rename() // Move files
os.RemoveAll() // Delete directories
Safety measures:
- Operations confined to GoShed directory
- Metadata validation before operations
- Error handling for all file operations
- Try VS Code first:
cmd := exec.Command("code", projectDir)
- Fall back to system editor:
defaultEditor := os.Getenv("EDITOR")
cmd = exec.Command(defaultEditor, projectDir)
Basic Git operations:
exec.Command("git", "init").Run()
-
File System Operations
- Metadata operations are lightweight
- Template application is sequential
- Cleanup runs as a single pass
-
Memory Usage
- Templates stored in memory
- Project list loaded on demand
- TUI components use minimal state
-
Concurrency
- File operations are synchronous
- UI updates are non-blocking
- Background cleanup possible
-
Graceful Degradation
- Editor fallback
- Template validation
- File system checks
-
User Feedback
- Clear error messages
- Status updates
- Operation confirmation
The architecture supports future additions:
-
Template System
- Custom template loading
- Template sharing
- Version control
-
Project Management
- Remote backups
- Project sharing
- Dependency tracking
-
UI Enhancements
- Custom themes
- Additional views
- Keyboard shortcuts
-
File System
- Operations confined to GoShed directory
- No execution of external code
- Safe file paths handling
-
External Commands
- Limited to Git and editor
- No arbitrary command execution
- Environment validation
-
Project Data
- Local storage only
- No sensitive data collection
- Metadata validation
To enable debug logging:
export GOSHED_DEBUG=1
Debug information includes:
- File operations
- Command execution
- State transitions
- Error details
This internal documentation should help contributors understand the codebase and make informed decisions when adding features or fixing bugs.