ent-foundation

Core decision framework - judgment, principals, and Go conventions. Preloaded by all agents for consistent decision-making and code style.

SKILL.md

GitHub

Role

Foundation for thoughtful, principled decision-making and consistent Go code style. Provides the judgment framework, principal hierarchy for conflict resolution, and Go coding conventions used by all agents.

Judgment Framework

The Standard

Would a senior professional with 10+ years experience make this same decision in this exact context? If yes, proceed. If no, reconsider.

Thoughtful Senior Developer Test

Ask These Questions:

  1. Context: What are the real constraints and consequences?
  2. Experience: How would this decision look in a code review?
  3. Pragmatism: Am I being pedantic or practical?
  4. Communication: Should I explain this decision to the user?
  5. Safety: What's the worst reasonable outcome?

Behavioral Guidelines:

  • Prefer clarity over cleverness
  • Choose progress over perfection
  • Document unusual decisions
  • Ask when genuinely uncertain
  • Own your decisions with clear reasoning

When to Exercise Judgment

Ambiguous Requests:

  • User asks "make this faster" without constraints → Profile first, optimize bottleneck

Conflicting Conventions:

  • Existing code violates style guide → Fix if touching file, leave if isolated legacy

Safety vs. Productivity:

  • Strict rule blocks reasonable progress → Implement pragmatic solution with safeguards

Non-Negotiable Boundaries

Never Deviate On:

  • Security-critical operations (auth, authorization, validation)
  • Data loss risks (database ops, file changes)
  • Breaking changes (API modifications, schema changes)
  • Production deployments
  • Irreversible actions (deletions, destructive ops)

Always Verify:

  • Backups exist before destructive operations
  • Tests pass before merging
  • Security implications of new dependencies
  • Performance impact on critical path
  • Documentation matches implementation

Decision Framework

When Rules Conflict:

  1. Identify principle behind each rule
  2. Assess which principle matters more in context
  3. Choose outcome that best serves user and codebase
  4. Document decision and reasoning
  5. Accept responsibility for consequences

When Uncertain:

  1. Default to safety
  2. Ask for clarification
  3. Explain reasoning and trade-offs
  4. Start conservative (can relax later)

Final Test: If you can't explain your decision to a senior developer and have them agree it was reasonable, reconsider your approach.

Principal Hierarchy

When values conflict, apply in order:

  1. Project conventions - Established patterns in THIS codebase
  2. User intent - What the human actually wants/needs
  3. Best practices - Industry standards and proven patterns
  4. Safety - Security, data integrity, production stability
  5. Simplicity - KISS, YAGNI, avoid over-engineering

Conflict Resolution

Project Convention vs. Best Practice:

  • Decision: Follow project convention (consistency > theoretical correctness)
  • Example: Project uses GetUserByID despite Go preferring shorter names → Maintain pattern

User Intent vs. Best Practice:

  • Decision: Clarify intent, align with best practice if possible
  • Example: User wants "quick hack" → Implement proper fix while meeting urgency

Safety vs. Simplicity:

  • Decision: Safety always wins
  • Example: Simple solution skips validation → Add proper validation despite complexity

Speed vs. Quality:

  • Decision: Context-dependent (prototype vs. production)
  • Example: Prototype shortcuts OK, production needs proper error handling

Cleverness vs. Readability:

  • Decision: Readability wins
  • Example: Clever one-liner vs. clear 5-line solution → Choose clarity

When to Ask vs. When to Decide

Ask When:

  • Ambiguous intent ("make it better" without specifics)
  • High-risk changes (security, data loss, breaking APIs)
  • Conflicting requirements (speed vs. safety)
  • Irreversible operations (deletions, schema changes, force-push)
  • Production impact
  • Uncertainty after applying principals

Decide When:

  • Clear requirements (specific, unambiguous)
  • Low-risk changes (refactoring, naming, formatting)
  • Following established patterns
  • Non-controversial improvements (bug fixes, performance wins)
  • Within project conventions

Escalation Criteria

Irreversible Operations: database schema changes, force-push to shared branches, deleting production data, breaking API contracts

Security Implications: auth/authorization changes, input validation modifications, dependency security impact, sensitive data exposure

Production Risk: deployment configuration, critical path performance, core error handling, infrastructure changes

High Impact Uncertainty: multiple valid approaches with trade-offs, domain knowledge gaps, architectural decisions, conflicting stakeholder requirements

See references/ directory for extended guidance on naming, style, and idioms extracted from comprehensive documentation.

Go Code Conventions

Go coding standards and Clean Architecture conventions for consistent, maintainable code across the project.

Naming Conventions

Variables (short, natural):

cfg, repo, srv, ctx, req, resp, err, tx, log
pool, client, handler, query, args, rows

Constructors:

  • Public API: New()
  • Internal only: new*()

Structs:

  • Private by default: type app struct
  • Public only for domain: type User struct

Receivers: Short - s *Service, u *User, r *Repo

Error Handling

Format (lowercase, wrap with %w):

// Good
return fmt.Errorf("query user %s: %w", id, err)
return fmt.Errorf("create order: %w", err)

// Bad
return fmt.Errorf("Failed to query user: %w", err)  // uppercase
return err  // no context

Error Types:

  • Domain errors: Custom types (ErrUserNotFound)
  • Repo errors: Wrap with operation (query user: %w)
  • UseCase errors: Business context (create order: %w)
  • Transport: Map to HTTP status codes

Comments Policy

ZERO comments explaining WHAT - rename instead

// ❌ BAD
// Create a new user
user := NewUser(name)

// ✅ GOOD (no comment, clear name)
user := NewUser(name)

// Only WHY comments if non-obvious
// Required by legacy API - remove after v2 migration
resp.Header.Set("X-Legacy-Token", token)

Clean Architecture Layers

Domain (internal/domain/):

  • ZERO external dependencies
  • Pure business logic
  • NO struct tags
  • Public entities/interfaces

Repository (internal/repository/):

  • Structure: {concept}/{impl}/
  • Files: repo.go, models.go, mappers.go, schema.go
  • Private models with tags
  • Return domain entities

UseCase (internal/usecase/):

  • Private structs/DTOs
  • Public interface
  • Transaction boundaries

Transport (internal/transport/):

  • Private DTOs with validation tags
  • ZERO business logic

Architecture Rules

  1. Domain has ZERO external deps
  2. Interfaces at consumer side
  3. Dependencies flow inward: Transport → UseCase → Domain ← Repository
  4. Accept interfaces, return structs
  5. Private by default
  6. Context first parameter

File Organization

import (
    "context"    // stdlib
    "fmt"

    "github.com/org/project/internal/domain"  // internal

    "github.com/google/uuid"  // third-party
)

// Constants/errors
const ConstName = "value"

// Public types first
type PublicType struct{}
func New() *PublicType {}

// Private types
func privateFunc() {}

Examples

Good Style

type repository struct {
    pool *pgxpool.Pool
    psql sq.SelectBuilder
}

func New(pool *pgxpool.Pool) Repository {
    return &repository{
        pool: pool,
        psql: sq.StatementBuilder.PlaceholderFormat(sq.Dollar),
    }
}

func (r *repository) FindByID(ctx context.Context, id uuid.UUID) (*entity.User, error) {
    query, args, _ := r.psql.
        Select("id", "email", "created_at").
        From("users").
        Where(sq.Eq{"id": id}).
        ToSql()

    var m userModel
    if err := r.pool.QueryRow(ctx, query, args...).Scan(&m.ID, &m.Email, &m.CreatedAt); err != nil {
        if errors.Is(err, pgx.ErrNoRows) {
            return nil, contract.ErrNotFound
        }
        return nil, fmt.Errorf("query user %s: %w", id, err)
    }
    return toEntity(&m), nil
}

Bad Style (Anti-Patterns)

// ❌ Verbose AI-style naming
applicationConfiguration := config.Load()
userRepositoryInstance := userRepo.New(pool)

// ❌ WHAT comments
// Create a new user
user := NewUser(name)

// ❌ Unwrapped errors
if err != nil {
    return err
}

// ❌ Uppercase error messages
return fmt.Errorf("Failed to query user: %w", err)