# Project structure

> Project structure - Organization of the DataRobot CLI codebase.

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-05-06T18:17:09.550106+00:00` (UTC).

## Primary page

- [Project structure](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html): Full documentation for this topic (HTML).

## Sections on this page

- [Directory overview](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#directory-overview): In-page section heading.
- [Key directories](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#key-directories): In-page section heading.
- [cmd/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#cmd): In-page section heading.
- [internal/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#internal): In-page section heading.
- [config/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#config): In-page section heading.
- [drapi/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#drapi): In-page section heading.
- [envbuilder/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#envbuilder): In-page section heading.
- [task/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#task): In-page section heading.
- [tui/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#tui): In-page section heading.
- [docs/](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#docs): In-page section heading.
- [Code organization patterns](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#code-organization-patterns): In-page section heading.
- [Command structure](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#command-structure): In-page section heading.
- [TUI models](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#tui-models): In-page section heading.
- [Configuration](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#configuration): In-page section heading.
- [Testing structure](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#testing-structure): In-page section heading.
- [Build artifacts](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#build-artifacts): In-page section heading.
- [Next steps](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/structure.html#next-steps): In-page section heading.

## Related documentation

- [Agentic AI](https://docs.datarobot.com/en/docs/agentic-ai/index.html): Linked from this page.
- [CLI](https://docs.datarobot.com/en/docs/agentic-ai/cli/index.html): Linked from this page.
- [Authentication flow](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/authentication.html): Linked from this page.
- [Setup guide](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/setup.html): Linked from this page.
- [Building guide](https://docs.datarobot.com/en/docs/agentic-ai/cli/development/building.html): Linked from this page.

## Documentation content

This document describes the organization of the DataRobot CLI codebase.

## Directory overview

```
cli/
├── cmd/                     # Command implementations (Cobra)
│   ├── root.go              # Root command and global flags
│   ├── auth/                # Authentication commands
│   ├── component/           # Component management commands
│   ├── dotenv/              # Environment variable management
│   ├── run/                 # Task execution
│   ├── self/                # Self-management commands
│   ├── start/               # Application startup
│   ├── task/                # Task commands
│   └── templates/           # Template management
├── internal/                # Private application code
│   ├── assets/              # Embedded assets
│   ├── config/              # Configuration management
│   ├── copier/              # Template copying utilities
│   ├── drapi/               # DataRobot API client
│   ├── envbuilder/          # Environment builder
│   ├── misc/                # Miscellaneous utilities
│   ├── repo/                # Repository detection
│   ├── shell/               # Shell utilities
│   ├── task/                # Task discovery and execution
│   ├── tools/               # Tool prerequisites
│   └── version/             # Version information
├── tui/                     # Terminal UI components
│   ├── banner.go            # Banner display
│   ├── interrupt.go         # Interrupt handling
│   └── theme.go             # Visual theme
├── docs/                    # Documentation
│   ├── commands/            # Command reference
│   ├── development/         # Development guides
│   ├── template-system/     # Template system docs
│   └── user-guide/          # User documentation
├── smoke_test_scripts/      # Smoke tests
├── main.go                  # Application entry point
├── Taskfile.yaml            # Task definitions
├── go.mod                   # Go module definition
└── goreleaser.yaml          # Release configuration
```

## Key directories

### cmd/

Contains all CLI command implementations using the Cobra framework. Each subdirectory represents a command or command group.

Structure:

- root.go —root command setup and global flags
- Each command has its own subdirectory with cmd.go as the entry point
- Commands that have subcommands organize them in the same directory

Example:

- cmd/auth/cmd.go —auth command group
- cmd/auth/login.go —login subcommand
- cmd/auth/logout.go —logout subcommand

### internal/

Private application code that cannot be imported by other projects. This follows Go's convention for internal packages.

#### config/

Configuration management including:

- Reading/writing configuration files
- Authentication state
- User preferences

#### drapi/

DataRobot API client implementation for:

- Template listing and retrieval
- API authentication
- API endpoint communication

#### envbuilder/

Environment configuration builder that:

- Discovers environment variables from templates
- Validates configuration
- Generates .env files
- Provides interactive prompts

#### task/

Task discovery and execution:

- Taskfile detection
- Task parsing
- Task running
- Output handling

### tui/

Terminal UI components built with Bubble Tea:

- Reusable UI models
- Theme definitions
- Interrupt handling for graceful exits
- Banner displays

### docs/

Documentation organized by audience:

- commands/ —detailed command reference
- development/ —development guides for contributors
- template-system/ —template configuration system
- user-guide/ —end-user documentation

## Code organization patterns

### Command structure

Each command follows this pattern:

```
// cmd/example/cmd.go
package example

import "github.com/spf13/cobra"

var Cmd = &cobra.Command{
    Use:   "example",
    Short: "Example command",
    Long:  `Detailed description`,
    PreRunE: func(cmd *cobra.Command, args []string) error {
        // Validation and setup
        return nil
    },
    RunE: func(cmd *cobra.Command, args []string) error {
        // Command implementation
        return nil
    },
}

func init() {
    // Flag definitions
    Cmd.Flags().StringP("flag", "f", "", "Flag description")
}
```

### TUI models

TUI components use the Bubble Tea framework and are wrapped with `InterruptibleModel` for consistent Ctrl-C handling:

```
// cmd/example/model.go
package example

import (
    tea "github.com/charmbracelet/bubbletea"
    "github.com/datarobot/cli/tui"
)

type model struct {
    // State fields
}

func (m model) Init() tea.Cmd {
    return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
    // Handle messages
    return m, nil
}

func (m model) View() string {
    // Render UI
    return ""
}

// Usage in command
func runInteractive() error {
    m := model{}
    wrapped := tui.NewInterruptibleModel(m)
    _, err := tea.NewProgram(wrapped).Run()
    return err
}
```

### Configuration

Configuration is managed through Viper and stored in:

- ~/.config/datarobot/config.yaml —global configuration
- ~/.config/datarobot/credentials.json —authentication tokens

Access configuration through the `internal/config` package:

```
import "github.com/datarobot/cli/internal/config"

// Get configuration values
apiKey := config.GetAPIKey()
endpoint := config.GetEndpoint()

// Set configuration values
config.SetAPIKey("new-key")
config.SaveConfig()
```

## Testing structure

Tests are colocated with the code they test:

- Unit tests: *_test.go files in the same package
- Test helpers in same directory when needed
- Smoke tests in smoke_test_scripts/ directory

## Build artifacts

Generated files and artifacts:

- dist/ —build output (created by Task/GoReleaser)
- tmp/ —temporary build files
- coverage.txt —test coverage report

## Next steps

- Setup guide —setting up your development environment
- Building guide —detailed build information and architecture
