domain

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package domain contains pure business entities for layli.

This package defines the core domain model with NO external dependencies (only Go stdlib). These types represent the "ubiquitous language" from our Gherkin feature files.

Key principles:

  • No dependencies on external packages (except Go stdlib)
  • Value objects are immutable where possible
  • Business logic lives here, not in adapters
  • Types map directly to concepts in feature files

Domain entities:

  • Diagram: Complete diagram specification
  • Node: A box/component in the diagram
  • Edge: A connection between nodes
  • Position: X/Y coordinates on the grid
  • Path: A series of positions forming an edge route

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	Min Position // Top-left corner
	Max Position // Bottom-right corner
}

Bounds represents a rectangular boundary.

func (Bounds) Contains

func (b Bounds) Contains(p Position) bool

Contains checks if a position is within the bounds.

func (Bounds) Height

func (b Bounds) Height() int

Height returns the height of the bounds.

func (Bounds) String

func (b Bounds) String() string

String returns a string representation of the bounds.

func (Bounds) Width

func (b Bounds) Width() int

Width returns the width of the bounds.

type Diagram

type Diagram struct {
	Nodes  []Node
	Edges  []Edge
	Config DiagramConfig
}

Diagram represents the complete diagram specification. Maps to: "Given a diagram with..." in feature files.

func (*Diagram) Validate

func (d *Diagram) Validate() error

Validate ensures diagram invariants are met.

type DiagramConfig

type DiagramConfig struct {
	LayoutType     LayoutType
	LayoutAttempts int
	NodeWidth      int
	NodeHeight     int
	Border         int
	Margin         int
	Spacing        int
	PathAttempts   int
	PathStrategy   string
	Pathfinding    PathfindingConfig
	Styles         map[string]string
}

DiagramConfig holds diagram-level settings.

type Edge

type Edge struct {
	ID    string
	From  string // Node ID
	To    string // Node ID
	Path  *Path  // Calculated path (may be nil before pathfinding)
	Class string
	Style string
}

Edge represents a connection between two nodes. Maps to: "And an edge from 'A' to 'B'" in feature files.

func (*Edge) String

func (e *Edge) String() string

String returns a string representation of the edge.

func (*Edge) Validate

func (e *Edge) Validate() error

Validate ensures edge invariants.

type LayoutType

type LayoutType string

LayoutType enumerates available layout algorithms. When adding a new layout algorithm, add the constant here, then: 1. Implement LayoutXxx function in layout/arrangements.go 2. Register in selectArrangement() in layout/arrangements.go 3. Register in selectArranger() in internal/adapters/layout/engine.go 4. Add tests to layout/arrangements_test.go See CONTRIBUTING_LAYOUTS.md for detailed instructions.

const (
	LayoutFlowSquare     LayoutType = "flow-square"
	LayoutTopoSort       LayoutType = "topo-sort"
	LayoutTarjan         LayoutType = "tarjan"
	LayoutAbsolute       LayoutType = "absolute"
	LayoutRandomShortest LayoutType = "random-shortest-square"
)

type Node

type Node struct {
	ID       string
	Contents string
	Position Position
	Width    int
	Height   int
	Class    string
	Style    string
}

Node represents a box/component in the diagram. Maps to: "And a node 'A'" in feature files.

func (*Node) Bounds

func (n *Node) Bounds() Bounds

Bounds returns the rectangular bounds of the node.

func (*Node) Center

func (n *Node) Center() Position

Center returns the center point of the node.

func (*Node) String

func (n *Node) String() string

String returns a string representation of the node.

func (*Node) Validate

func (n *Node) Validate() error

Validate ensures node invariants.

type Path

type Path struct {
	Points []Position
}

Path represents a series of positions forming an edge route.

func (*Path) Corners

func (p *Path) Corners() int

Corners returns the number of direction changes in the path.

func (*Path) Length

func (p *Path) Length() float64

Length returns the total length of the path.

func (*Path) String

func (p *Path) String() string

String returns a string representation of the path.

type PathfindingAlgorithm added in v0.0.16

type PathfindingAlgorithm string

PathfindingAlgorithm enumerates available pathfinding algorithms. When adding a new pathfinding algorithm, add the constant here.

const (
	PathfindingDijkstra      PathfindingAlgorithm = "dijkstra"
	PathfindingAStar         PathfindingAlgorithm = "astar"
	PathfindingBidirectional PathfindingAlgorithm = "bidirectional"
)

type PathfindingConfig added in v0.0.16

type PathfindingConfig struct {
	Algorithm PathfindingAlgorithm
	Heuristic PathfindingHeuristic
}

PathfindingConfig holds pathfinding algorithm settings.

type PathfindingHeuristic added in v0.0.16

type PathfindingHeuristic string

PathfindingHeuristic enumerates available heuristic functions for A*.

const (
	HeuristicEuclidean PathfindingHeuristic = "euclidean"
	HeuristicManhattan PathfindingHeuristic = "manhattan"
)

type Position

type Position struct {
	X int
	Y int
}

Position represents an X, Y coordinate on the grid.

func (Position) Distance

func (p Position) Distance(other Position) float64

Distance returns the Euclidean distance between two positions.

func (Position) String

func (p Position) String() string

String returns a string representation of the position.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL