# connamara/quickfixn architecture

> Architecture diagram of the GitHub repository connamara/quickfixn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/connamara/quickfixn
- Repository: https://github.com/connamara/quickfixn

## Overview

##### Main Components and Their Roles

- Core FIX Engine (QuickFIXn)
- This is the heart of the system. It includes session management (Session, SessionFactory, SessionSettings, SessionID, SessionState), message parsing/encoding (Parser.cs, Message/MessageBuilder.cs, MessageCracker.cs), and transport/communication layers (SocketInitiator, ThreadedSocketAcceptor, SslStreamFactory, etc.).
- Helper modules such as Logger (FileLog, ScreenLog, etc.) and Store (FileStore, MemoryStore) that ensure persistence and logging support.
- Data Dictionary features are found in QuickFIXn/DataDictionary and related classes which help in parsing FIX specifications, validating messages, and mapping tags.

- Code Generation Tool (DDTool)
- This C#-based tool analyzes the FIX DataDictionary XML files and regenerates source code for field and message classes.
- How DDTool feeds into the “Messages” folder content (pre-generated FIX message classes for FIX40, FIX41, etc.).

- Message Definitions (Messages Directory)
- These directories (e.g., Messages/FIX40, FIX41, … up to FIX50, FIX50SP1, etc.) contain the auto-generated message code definitions for different FIX specification versions.
- They serve as the “vocabulary” used by the QuickFIX/n engine for encoding/decoding and handling communication.

- Testing Suites
- Acceptance Tests (AcceptanceTest directory) and UnitTests provide automated testing coverage.
- The AcceptanceTest folder includes various configuration files, acceptance test case source files, and scenario definitions (using NUnit and custom test runners).
- UnitTests show the modular test coverage of components such as parsers, message creation, session management, logging, and so forth.

- Examples and Scripts
- Examples folder demonstrates various usage scenarios (e.g., SimpleAcceptor, TradeClient, FixToJson conversion).
- Scripts (PowerShell) provide build, code-generation, deployment packaging, and version bumping capabilities.

##### Relationships and Interactions

- Data Flow Across Layers
- A client (initiator or acceptor) connects through the transport layer (networking components like SocketInitiator / ThreadedSocketAcceptor) to the core session layer.
- The Session component interacts with the Message Parser (which decodes raw FIX messages using DataDictionary definitions) and then routes messages via the Message Cracker to application callbacks implementing IApplication or IApplicationExt.
- The messages and fields then flow to higher-level business processing or logging modules.

- Code Generation Cycle
- DDTool takes DataDictionary XML files as input (see spec/fix directory) and generates standardized message classes in the Messages folder.
- This illustrates a design-time dependency that ensures the FIX engine is up-to-date with the protocol definitions.

- Testing and Validation
- The acceptance and unit tests validate that every module—from field processing and session state to logon and logout behavior—is working as expected.
- Tests are executed using the dotnet CLI (or within the IDE).

##### Architectural Patterns and Design Principles

- Layered Architecture
- Separate layers include: Transport → Message Encoding/Decoding → Session Management → Application Logic.
- Each layer communicates via clearly defined interfaces (e.g., IApplication, IMessageFactory, IField) which help in unit testing and decoupling.

- Factory and Builder Patterns
- Factories are used for message creation (DefaultMessageFactory, MessageFactory in Messages/* directories).
- The Builder pattern appears in MessageBuilder and message creation utilities.

- Pluggable Components
- Logging, message storage, and transport mechanisms are abstracted (ILog, IMessageStore, IFieldMapSpec) making them replaceable by custom implementations if required.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entity
    External["External FIX Client"]:::external

    %% Core FIX Engine Subgraph
    subgraph "Core FIX Engine"
        T["Transport/Networking\n(SocketInitiator, ThreadedSocketAcceptor, SslStreamFactory)"]:::transport
        P["Message Parser/Encoder\n(Parser, MessageBuilder, MessageCracker)"]:::parser
        S["Session Management\n(Session, SessionFactory, SessionSettings, SessionID, SessionState)"]:::session
        D["Data Dictionary\n(DataDictionary)"]:::dd
        L["Logging\n(ScreenLog, FileLog)"]:::logging
        F["Persistence\n(FileStore, MemoryStore)"]:::store
        A["Application Callbacks\n(IApplication, IApplicationExt)"]:::application
    end

    %% Code Generation (DDTool) Subgraph
    subgraph "Code Generation (DDTool)"
        DDP["Parsers\n(DDParser, FieldParser, MessageParser)"]:::ddtool
        DDG["Generators\n(GenFields, GenMessages)"]:::ddtool
        DDS["Structures\n(DDMessage)"]:::ddtool
    end

    %% Message Definitions Subgraph
    MD["Message Definitions\n(FIX Versions: FIX40, FIX41, FIX50, FIX50SP1, FIX50SP2, FIXT11)"]:::msgdef

    %% Testing Suites Subgraph
    subgraph "Testing Suites"
        AT["Acceptance Tests"]:::testing
        UT["Unit Tests"]:::testing
    end

    %% Examples and Scripts Subgraph
    subgraph "Examples & Scripts"
        EX["Examples\n(SimpleAcceptor, TradeClient, FixToJson)"]:::examples
        SCR["Scripts\n(Build-NuGets.ps1, Generate-Message-Sources.ps1)"]:::scripts
    end

    %% Data Flow Connections
    External -->|"connects"| T
    T -->|"sends_RAW_Message"| P
    P -->|"delivers_Parsed_Message"| S
    S -->|"updates_Session"| L
    S -->|"updates_Session"| F
    S -->|"routes_Message"| A
    %% Feedback connection (optional)
    S -->|"feedbacks_To"| P

    %% Code Generation Flow
    DDP -->|"generates_output"| MD
    DDG -->|"generates_output"| MD
    DDS -->|"provides_structure"| MD

    %% Testing Connections
    UT -->|"tests_Core"| S

    %% Examples Usage Connection
    EX -->|"demonstrates_usage"| A

    %% Click Events for Core FIX Engine Components
    click T "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/Transport/SocketInitiator.cs"
    click P "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/Parser.cs"
    click S "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/Session.cs"
    click D "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/DataDictionary/DataDictionary.cs"
    click L "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/Logger/ScreenLog.cs"
    click F "https://github.com/connamara/quickfixn/blob/master/QuickFIXn/Store/FileStore.cs"

    %% Click Events for Code Generation (DDTool)
    click DDP "https://github.com/connamara/quickfixn/blob/master/DDTool/DDTool/Parsers/DDParser.cs"
    click DDG "https://github.com/connamara/quickfixn/blob/master/DDTool/DDTool/Generators/GenFields.cs"
    click DDS "https://github.com/connamara/quickfixn/blob/master/DDTool/DDTool/Structures/DDMessage.cs"

    %% Click Event for Message Definitions
    click MD "https://github.com/connamara/quickfixn/tree/master/Messages"

    %% Click Events for Testing Suites
    click AT "https://github.com/connamara/quickfixn/tree/master/AcceptanceTest"
    click UT "https://github.com/connamara/quickfixn/tree/master/UnitTests"

    %% Click Events for Examples and Scripts
    click EX "https://github.com/connamara/quickfixn/tree/master/Examples"
    click SCR "https://github.com/connamara/quickfixn/blob/master/scripts/Build-NuGets.ps1"

    %% Style Classes
    classDef external fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef transport fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef parser fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef session fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef dd fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef logging fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef store fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef application fill:#f0e68c,stroke:#a67c00,stroke-width:2px;
    classDef ddtool fill:#e6ccff,stroke:#6f42c1,stroke-width:2px;
    classDef msgdef fill:#c3e6cb,stroke:#28a745,stroke-width:2px;
    classDef testing fill:#f5c6cb,stroke:#dc3545,stroke-width:2px;
    classDef examples fill:#ffeeba,stroke:#fd7e14,stroke-width:2px;
    classDef scripts fill:#d6d8db,stroke:#343a40,stroke-width:2px;
```
