Skip to content

Hexagonal Architecture

Stéphane Pilloy edited this page Nov 29, 2026 · 2 revisions
Language: English | Français 🇫🇷

Hexagonal Architecture & Zero-Allocation Engine

CassiniFlow is designed following Hexagonal Architecture (Ports and Adapters) and Domain-Driven Design (DDD) principles, targeting .NET 10 and C# 14 with high-throughput zero-allocation memory constraints.


Layered Architecture Diagram

graph TD
    subgraph Presentation["Presentation Layer (Driving Adapters)"]
        GUI["CassiniFlow.Desktop<br/>(Avalonia UI 12.1.5, MVVM)"]
        CLI["CassiniFlow.Cli<br/>(Headless Console Runner)"]
    end

    subgraph Application["Application Layer (Use Cases & Pipelines)"]
        UC["Use Cases<br/>(RunPipelineUseCase, LiveStackingSessionUseCase, PreviewFrameUseCase)"]
        Pipe["Pipeline Pattern<br/>(FrameProcessingPipeline)"]
    end

    subgraph Domain["Domain Layer (Core Pure Logic)"]
        Entities["Entities & Models<br/>(AstroFrame, Centroid, CropRegion, QualityScore, LiveHistogramData)"]
        Services["Domain Services<br/>(ImageProcessor, LiveStackingEngine, FieldDerotationEngine)"]
        Ports["Inbound & Outbound Ports<br/>(ICameraDriver, IMountController, IFocuserController, IFilterWheelController)"]
    end

    subgraph Infrastructure["Infrastructure Layer (Driven Adapters)"]
        Codecs["Codecs & Formats<br/>(SerFile, FitsFile, UniversalMediaReader)"]
        Hardware["Camera & Observatory Drivers<br/>(Alpaca REST, ZWO ASI/EFW, Player One, QHY, ToupTek, SVBony)"]
        Native["Native Libraries<br/>(OpenCV / OpenCvSharp4, FFmpeg CLI)"]
        Persistence["Storage & Serialization<br/>(ProfileSerializer, Astronomical Naming Helper)"]
    end

    GUI --> Application
    CLI --> Application
    Application --> Domain
    Infrastructure --> Ports
Loading

Strict Separation Rules

  1. CassiniFlow.Domain:
    • Zero external dependencies on UI frameworks or third-party imaging libraries.
    • Pure domain models (AstroFrame, QualityScore, Centroid, BoundingBox).
    • Pure domain calculations (CoG, limb math, crop math, sorting heuristics).
  2. CassiniFlow.Application:
    • Implements use cases and coordinates domain services via composable pipeline stages.
    • Tracks cancellation tokens, error dispatching, and progress reporting.
  3. CassiniFlow.Infrastructure:
    • Implements outbound ports (secondary adapters): reading/writing .ser binaries, FITS astronomical cubes, OpenCV video interop.
  4. CassiniFlow.Desktop / CassiniFlow.Cli:
    • Driving adapters that receive user input and render feedback.

Zero-Allocation High-Speed Frame Processing

Processing raw astronomical video streams can easily saturate .NET garbage collection (GC) if naive byte[] arrays are allocated per frame.

CassiniFlow adheres to strict zero-allocation performance rules:

  • MemoryPool<byte> & ArrayPool<byte>.Shared: Frame memory is rented and returned to pools instead of triggering heap allocations.
  • Span<T> and ReadOnlySpan<T>: In-place pixel arithmetic and convolution kernels operate without memory copies.
  • SIMD Hardware Acceleration: Vectorized CPU intrinsics (AVX2 / SSE4.1) accelerate gradient and debayering convolutions.
  • Single-Pass Bounded Top-K Min-Heap: Limits memory usage to $&lt; 900\text{ MB}$ even when ranking sequences of 50,000+ frames.

Clone this wiki locally