Module inbound

Source
Expand description

§Inbound Ports — Driving the Application

Inbound ports define how external systems can drive the fernctl application. They are the entry points through which configuration is loaded, validated, and queried.

§Overview

┌─────────────────────────────────────────────────────────────┐
│                   DRIVING ADAPTERS                          │
│                                                             │
│   ┌──────────────┐  ┌──────────────┐  ┌──────────────┐     │
│   │ TomlAdapter  │  │  CliAdapter  │  │ JsonAdapter  │     │
│   │              │  │              │  │              │     │
│   │ Reads .toml  │  │ Parses args  │  │ Reads .json  │     │
│   └──────┬───────┘  └──────┬───────┘  └──────┬───────┘     │
│          │                 │                 │              │
└──────────┼─────────────────┼─────────────────┼──────────────┘
           │                 │                 │
     ╔═════╧═════════════════╧═════════════════╧═════════════╗
     ║                  INBOUND PORTS                        ║
     ║                                                       ║
     ║   ConfigPort ──────► Load raw configuration           ║
     ║   ValidatePort ────► Validate and transform           ║
     ║   QueryPort ───────► Query theme values               ║
     ║                                                       ║
     ╚═══════════════════════════╤═══════════════════════════╝
                                 │
                                 ▼
                         ┌──────────────┐
                         │    DOMAIN    │
                         │    Theme     │
                         │    Tokens    │
                         └──────────────┘

§Port Responsibilities

PortResponsibilityInputOutput
ConfigPortLoad raw configurationSource (file content, path)Raw config data
ValidatePortValidate and transformRaw configValidated theme
QueryPortQuery theme valuesTheme + queryToken values

§Usage Pattern

Inbound ports are typically used in this sequence:

ⓘ
use fernctl::ports::inbound::*;
use fernctl::adapters::TomlConfigAdapter;

// 1. Load raw configuration
let config_adapter = TomlConfigAdapter::new();
let raw_config = config_adapter.load_from_file("config.toml")?;

// 2. Validate and transform
let theme = raw_config.validate()?.into_theme();

// 3. Query values (optional)
let bg_color = query_adapter.get_color(&theme, "background")?;

§Implementing Custom Adapters

To add support for a new configuration format (e.g., YAML):

ⓘ
use fernctl::ports::inbound::ConfigPort;
use fernctl::domain::config::RawConfig;
use fernctl::error::Result;

struct YamlConfigAdapter;

impl ConfigPort for YamlConfigAdapter {
    fn load(&self, source: &str) -> Result<RawConfig> {
        // Parse YAML and convert to RawConfig
        let yaml: serde_yaml::Value = serde_yaml::from_str(source)?;
        RawConfig::from_yaml(yaml)
    }

    fn format_name(&self) -> &'static str {
        "YAML"
    }
}

Structs§

ConfigWarning
A non-fatal warning from configuration validation.
RawConfig
Raw configuration data before validation.
ValidatedConfig
Configuration that has passed validation.

Enums§

SourceFormat
The format a configuration was parsed from.

Traits§

ConfigPort
Port for loading configuration from external sources.
QueryPort
Port for querying theme values.
ValidatePort
Port for validating configuration data.