Developer API documentation for the Open Source Project Generator.
Main interface for project generation orchestration.
Location: pkg/interfaces/coordinator.go
type ProjectCoordinatorInterface interface {
Generate(ctx context.Context, config interface{}) (interface{}, error)
DryRun(ctx context.Context, config interface{}) (interface{}, error)
Validate(config interface{}) error
}Methods:
Generate- Generate a complete project from configurationDryRun- Preview what would be generated without creating filesValidate- Validate configuration before generation
Usage:
coordinator := orchestrator.NewProjectCoordinator(logger)
result, err := coordinator.Generate(ctx, config)
if err != nil {
log.Fatal(err)
}
generationResult := result.(*models.GenerationResult)Interface for bootstrap tool executors.
Location: pkg/interfaces/executor.go
type BootstrapExecutorInterface interface {
Execute(ctx context.Context, spec *BootstrapSpec) (*ExecutionResult, error)
SupportsComponent(componentType string) bool
GetDefaultFlags(componentType string) []string
}Methods:
Execute- Execute the bootstrap tool with given specificationSupportsComponent- Check if executor supports a component typeGetDefaultFlags- Get default flags for a component type
Interface for mapping generated structures.
Location: pkg/interfaces/mapper.go
type StructureMapperInterface interface {
Map(ctx context.Context, source, target, componentType string) error
UpdateImportPaths(targetPath, componentType string) error
}Methods:
Map- Map generated files to target structureUpdateImportPaths- Update import paths in generated files
Project configuration structure.
Location: pkg/models/project.go
type ProjectConfig struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
OutputDir string `yaml:"output_dir" json:"output_dir"`
Author string `yaml:"author,omitempty" json:"author,omitempty"`
Email string `yaml:"email,omitempty" json:"email,omitempty"`
License string `yaml:"license,omitempty" json:"license,omitempty"`
Repository string `yaml:"repository,omitempty" json:"repository,omitempty"`
Components []ComponentConfig `yaml:"components" json:"components"`
Integration IntegrationConfig `yaml:"integration" json:"integration"`
Options ProjectOptions `yaml:"options" json:"options"`
}Fields:
Name- Project name (required)Description- Project descriptionOutputDir- Output directory path (required)Author- Project authorEmail- Author emailLicense- License type (e.g., "MIT", "Apache-2.0")Repository- Repository URLComponents- List of components to generateIntegration- Integration settingsOptions- Generation options
Component configuration structure.
type ComponentConfig struct {
Type string `yaml:"type" json:"type"`
Name string `yaml:"name" json:"name"`
Enabled bool `yaml:"enabled" json:"enabled"`
Config map[string]interface{} `yaml:"config" json:"config"`
}Fields:
Type- Component type (e.g., "nextjs", "go-backend")Name- Component nameEnabled- Whether component is enabledConfig- Component-specific configuration
Integration configuration structure.
type IntegrationConfig struct {
GenerateDockerCompose bool `yaml:"generate_docker_compose" json:"generate_docker_compose"`
GenerateScripts bool `yaml:"generate_scripts" json:"generate_scripts"`
APIEndpoints map[string]string `yaml:"api_endpoints" json:"api_endpoints"`
SharedEnvironment map[string]string `yaml:"shared_environment" json:"shared_environment"`
}Fields:
GenerateDockerCompose- Generate Docker Compose fileGenerateScripts- Generate build/run scriptsAPIEndpoints- API endpoint configurationSharedEnvironment- Shared environment variables
Generation options structure.
type ProjectOptions struct {
UseExternalTools bool `yaml:"use_external_tools" json:"use_external_tools"`
DryRun bool `yaml:"dry_run" json:"dry_run"`
Verbose bool `yaml:"verbose" json:"verbose"`
CreateBackup bool `yaml:"create_backup" json:"create_backup"`
ForceOverwrite bool `yaml:"force_overwrite" json:"force_overwrite"`
}Fields:
UseExternalTools- Use bootstrap tools or force fallbackDryRun- Preview mode (don't create files)Verbose- Enable verbose loggingCreateBackup- Create backup before overwritingForceOverwrite- Force overwrite existing directory
Result of project generation.
type GenerationResult struct {
Success bool `json:"success"`
ProjectRoot string `json:"project_root"`
Components []*ComponentResult `json:"components"`
Duration time.Duration `json:"duration"`
Errors []error `json:"errors,omitempty"`
Warnings []string `json:"warnings,omitempty"`
DryRun bool `json:"dry_run"`
LogFile string `json:"log_file,omitempty"`
}Fields:
Success- Whether generation succeededProjectRoot- Root directory of generated projectComponents- Results for each componentDuration- Total generation timeErrors- List of errors encounteredWarnings- List of warningsDryRun- Whether this was a dry runLogFile- Path to log file
Result of component generation.
type ComponentResult struct {
Name string `json:"name"`
Type string `json:"type"`
Success bool `json:"success"`
Method string `json:"method"`
ToolUsed string `json:"tool_used"`
OutputPath string `json:"output_path"`
Duration time.Duration `json:"duration"`
Error error `json:"error,omitempty"`
Warnings []string `json:"warnings,omitempty"`
ManualSteps []string `json:"manual_steps,omitempty"`
}Fields:
Name- Component nameType- Component typeSuccess- Whether generation succeededMethod- Generation method ("bootstrap" or "fallback")ToolUsed- Tool that was usedOutputPath- Path to generated componentDuration- Generation timeError- Error if generation failedWarnings- List of warningsManualSteps- Manual steps required (for fallback)
Result of tool availability check.
type ToolCheckResult struct {
AllAvailable bool `json:"all_available"`
Tools map[string]*ToolInfo `json:"tools"`
Missing []string `json:"missing"`
Outdated []string `json:"outdated"`
CheckedAt time.Time `json:"checked_at"`
}Fields:
AllAvailable- Whether all required tools are availableTools- Information about each toolMissing- List of missing toolsOutdated- List of outdated toolsCheckedAt- When check was performed
Information about a tool.
type ToolInfo struct {
Available bool `json:"available"`
InstalledVersion string `json:"installed_version,omitempty"`
MinVersion string `json:"min_version,omitempty"`
Path string `json:"path,omitempty"`
}Fields:
Available- Whether tool is availableInstalledVersion- Installed versionMinVersion- Minimum required versionPath- Path to tool executable
package main
import (
"context"
"log"
"github.com/cuesoftinc/open-source-project-generator/internal/orchestrator"
"github.com/cuesoftinc/open-source-project-generator/pkg/logger"
"github.com/cuesoftinc/open-source-project-generator/pkg/models"
)
func main() {
// Create logger
log := logger.NewLogger()
// Create configuration
config := &models.ProjectConfig{
Name: "my-project",
OutputDir: "./my-project",
Components: []models.ComponentConfig{
{
Type: "nextjs",
Name: "web-app",
Enabled: true,
Config: map[string]interface{}{
"typescript": true,
"tailwind": true,
},
},
},
Integration: models.IntegrationConfig{
GenerateDockerCompose: true,
GenerateScripts: true,
},
Options: models.ProjectOptions{
UseExternalTools: true,
CreateBackup: true,
},
}
// Create coordinator
coordinator := orchestrator.NewProjectCoordinator(log)
// Generate project
result, err := coordinator.Generate(context.Background(), config)
if err != nil {
log.Fatal("Generation failed:", err)
}
// Check result
genResult := result.(*models.GenerationResult)
if genResult.Success {
log.Info("Project generated successfully!")
log.Info("Location:", genResult.ProjectRoot)
} else {
log.Error("Generation failed with errors:", genResult.Errors)
}
}// Preview what would be generated
result, err := coordinator.DryRun(context.Background(), config)
if err != nil {
log.Fatal(err)
}
previewResult := result.(*models.PreviewResult)
log.Info("Would generate", len(previewResult.Components), "components")
for _, comp := range previewResult.Components {
log.Info("Component:", comp.Name, "Type:", comp.Type)
}// Create tool discovery
toolDiscovery := orchestrator.NewToolDiscovery(log)
// Check specific tools
tools := []string{"npx", "go", "gradle"}
result, err := toolDiscovery.CheckRequirements(tools)
if err != nil {
log.Fatal(err)
}
toolResult := result.(*models.ToolCheckResult)
if toolResult.AllAvailable {
log.Info("All tools available!")
} else {
log.Warn("Missing tools:", toolResult.Missing)
}package bootstrap
import (
"context"
"github.com/cuesoftinc/open-source-project-generator/pkg/logger"
)
type CustomExecutor struct {
*BaseExecutor
}
func NewCustomExecutor(log *logger.Logger) *CustomExecutor {
return &CustomExecutor{
BaseExecutor: &BaseExecutor{logger: log},
}
}
func (ce *CustomExecutor) Execute(ctx context.Context, spec *BootstrapSpec) (*ExecutionResult, error) {
// Custom implementation
ce.logger.Info("Executing custom tool")
// Build command
spec.Tool = "custom-tool"
spec.Flags = []string{"create", spec.Config["name"].(string)}
// Execute
return ce.BaseExecutor.Execute(ctx, spec)
}
func (ce *CustomExecutor) SupportsComponent(componentType string) bool {
return componentType == "custom"
}
func (ce *CustomExecutor) GetDefaultFlags(componentType string) []string {
return []string{"--default"}
}The generator uses typed errors for better error handling:
import "github.com/cuesoftinc/open-source-project-generator/pkg/errors"
// Configuration errors
errors.NewConfigError("invalid configuration", err)
// Tool errors
errors.NewToolError("tool not found", err)
// File system errors
errors.NewFileSystemError("permission denied", err)
// Validation errors
errors.NewValidationError("invalid input", err)
// Security errors
errors.NewSecurityError("path traversal detected", err)result, err := coordinator.Generate(ctx, config)
if err != nil {
switch e := err.(type) {
case *errors.ConfigError:
log.Error("Configuration error:", e)
// Handle configuration error
case *errors.ToolError:
log.Error("Tool error:", e)
// Handle tool error
case *errors.FileSystemError:
log.Error("File system error:", e)
// Handle file system error
default:
log.Error("Unknown error:", e)
}
return
}import "errors"
if errors.Is(err, ErrToolNotFound) {
log.Warn("Tool not found, using fallback")
// Use fallback generator
}
if errors.Is(err, ErrConfigInvalid) {
log.Error("Invalid configuration")
// Show validation errors
}type Logger interface {
Debug(msg string, args ...interface{})
Info(msg string, args ...interface{})
Warn(msg string, args ...interface{})
Error(msg string, args ...interface{})
Fatal(msg string, args ...interface{})
SetLevel(level LogLevel)
}log := logger.NewLogger()
// Set log level
log.SetLevel(logger.DebugLevel)
// Log messages
log.Debug("Debug message", "key", "value")
log.Info("Info message")
log.Warn("Warning message")
log.Error("Error message", "error", err)type Validator interface {
Validate(config *models.ProjectConfig) error
ApplyDefaults(config *models.ProjectConfig) error
}validator := config.NewValidator()
// Validate configuration
if err := validator.Validate(config); err != nil {
log.Fatal("Validation failed:", err)
}
// Apply defaults
if err := validator.ApplyDefaults(config); err != nil {
log.Fatal("Failed to apply defaults:", err)
}import "github.com/cuesoftinc/open-source-project-generator/pkg/security"
sanitizer := security.NewSanitizer()
// Sanitize path
cleanPath, err := sanitizer.SanitizePath(userPath)
if err != nil {
log.Fatal("Invalid path:", err)
}
// Sanitize project name
cleanName, err := sanitizer.SanitizeName(userName)
if err != nil {
log.Fatal("Invalid name:", err)
}// Validate path is safe
if err := security.ValidatePath(path); err != nil {
log.Fatal("Unsafe path:", err)
}
// Check for path traversal
if security.HasPathTraversal(path) {
log.Fatal("Path traversal detected")
}- Architecture - System architecture
- Adding Tools - Adding new bootstrap tools
- Getting Started - Installation and usage
- Configuration Guide - Configuration options