usecases

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 usecases contains the application use cases (orchestration logic).

This layer defines the business workflows that coordinate domain entities with external concerns (file I/O, rendering, etc.). Use cases do NOT contain business logic—that belongs in the domain layer.

Each use case:

  • Defines one complete workflow (e.g., "Generate a diagram")
  • Uses ports (interfaces) to depend on external concerns
  • Never depends directly on specific implementations
  • Maps to Gherkin scenarios: "Given → When → Then"

Ports (interfaces) defined here:

  • ConfigParser: Read and parse configuration files
  • LayoutEngine: Arrange nodes using layout algorithms
  • Pathfinder: Calculate paths between nodes
  • Renderer: Generate output (SVG, PNG, etc.)
  • FileReader/FileWriter: Abstract file system access

Adapters (in internal/adapters/) implement ports

Use cases map to Gherkin "When" steps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigParser

type ConfigParser interface {
	// Parse reads a config file and returns a validated Diagram.
	// Maps to: "Given I have a diagram config 'file.layli'"
	Parse(path string) (*domain.Diagram, error)
}

ConfigParser reads configuration files and returns domain diagrams. Implementations: YAML parser, JSON parser, etc.

type FileReader

type FileReader interface {
	Read(path string) ([]byte, error)
}

FileReader abstracts file system reads (for testing).

type FileWriter

type FileWriter interface {
	Write(path string, data []byte) error
}

FileWriter abstracts file system writes (for testing).

type GenerateDiagram

type GenerateDiagram struct {
	// contains filtered or unexported fields
}

GenerateDiagram orchestrates the complete diagram generation workflow. Maps to a complete Gherkin scenario: Given → When → Then

func NewGenerateDiagram

func NewGenerateDiagram(
	parser ConfigParser,
	layout LayoutEngine,
	pathfinder Pathfinder,
	renderer Renderer,
) *GenerateDiagram

NewGenerateDiagram creates a new GenerateDiagram use case.

func (*GenerateDiagram) Execute

func (uc *GenerateDiagram) Execute(configPath, outputPath string) error

Execute runs the complete diagram generation pipeline.

Steps:

  1. Parse configuration (Given)
  2. Validate diagram (Given)
  3. Arrange layout (When)
  4. Calculate paths (When)
  5. Render output (Then)

type LayoutEngine

type LayoutEngine interface {
	// Arrange positions all nodes in the diagram.
	// Maps to: "When I arrange using 'flow-square' layout"
	Arrange(diagram *domain.Diagram) error
}

LayoutEngine arranges nodes within a diagram. Implementations: FlowSquare, TopoSort, Tarjan, Absolute

type Pathfinder

type Pathfinder interface {
	// FindPaths calculates paths for all edges in the diagram.
	// Maps to: "And calculate paths for all edges"
	FindPaths(diagram *domain.Diagram) error
}

Pathfinder calculates edge paths between nodes. Implementations: Dijkstra, A*, etc.

type Renderer

type Renderer interface {
	// Render writes the diagram to the output path.
	// Maps to: "Then the diagram should be generated"
	Render(diagram *domain.Diagram, outputPath string) error
}

Renderer generates output from a positioned diagram. Implementations: SVG, PNG, PDF

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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