# cocoanetics/dtcoretext architecture

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

- Interactive diagram: https://gitdiagram.com/cocoanetics/dtcoretext
- Repository: https://github.com/cocoanetics/dtcoretext

## Overview

##### Main Components
- Core Library: This is the heart of the framework and includes the layout engine and the classes for converting HTML into NSAttributedString objects. The “Core” folder encapsulates the source code for numerous utilities (e.g., DTHTMLAttributedStringBuilder, DTCoreTextLayoutFrame, DTCoreTextLayouter, etc.) as well as a wide variety of helper modules for working with CSS, HTML elements, and CoreText constructs.
- UI Rendering Components: These include UI-specific classes such as DTAttributedTextView, DTAttributedLabel, and DTAttributedTextCell, which leverage the outputs from the core layout functions to present rich text to the user.
- Demo Application: The “Demo” directory houses an example app that demonstrates how to integrate and use the DTCoreText framework in an iOS project. It shows how the UI components are instantiated and how HTML content is fed into the system.
- Testing Suite: The “Test” and “Tests” folders contain unit tests to validate the behavior of the parsing, layout, and rendering processes.
- Documentation and Configuration: Directories like “Documentation” and files like the Podspec, Xcode project files, and build scripts (e.g., build.gradle, Travis CI configuration) indicate how the project is structured, built, and documented.

##### Relationships and Interactions
- Data Flow: Start with an “HTML Input” that is first processed by the core layout engine. The DTHTMLAttributedStringBuilder (or similar classes) parses HTML and builds an attributed string.
- CoreText Integration: The generated attributed string flows into several CoreText-specific classes (e.g., DTCoreTextLayoutFrame, DTCoreTextLayouter) that determine how the text is laid out and rendered.
- UI Layer: Once layout and styling information is available, the UI components (DTAttributedTextView, DTAttributedLabel, DTAttributedTextCell) take over to display the rich text.
- Testing & Demo: The test suite verifies these interactions, and the demo app serves as a live example of how components are wired together.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project separates parsing and layout (handled within the core library) from user interface rendering (handled by dedicated UI classes) and demonstration/testing.
- Modularity: The project is organized into distinct directories (Core, Demo, Test), which helps in isolating functionality and making future maintenance or extension easier.
- Reusability and Extensibility: Through clearly defined interfaces (such as the settings exposed by the various CoreText classes), it is easy to extend or modify how HTML is parsed or rendered.

##### Relevant Technologies and Frameworks
- CoreText: The underlying Apple framework for text layout on iOS/macOS.
- Objective-C: The language used across the project.
- Xcode: As evidenced by the Xcode project files and schemes.
- Testing Frameworks: Integration of unit tests (XCTest for Swift tests and Objective-C unit tests).
- External Library Management: With podspec and Git submodules, it shows the use of dependency managers.

- How the parsing module interacts with CSS and HTML helper classes.
- Depicting the interplay between layout calculators and CoreText for accurate text positioning.
- How the UI components encapsulate the rendering logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    htmlInput["HTML Input"]:::external

    subgraph "Core Library"
        builder["DTHTMLAttributedStringBuilder"]:::core
        layout["CoreText Layout Engine"]:::core
    end

    subgraph "UI Components"
        view["DTAttributedTextView"]:::ui
        label["DTAttributedLabel"]:::ui
        cell["DTAttributedTextCell"]:::ui
    end

    demo["Demo Application"]:::external
    test["Testing Suite"]:::external

    subgraph "Documentation & Configuration"
        doc["Documentation"]:::external
        podspec["Podspec"]:::external
        xcode["Xcode Project"]:::external
    end

    htmlInput -->|"processes"| builder
    builder -->|"buildsLayout"| layout
    layout -->|"renders"| view
    layout -->|"renders"| label
    layout -->|"renders"| cell

    demo -->|"uses"| builder
    demo -->|"uses"| view

    test -->|"tests"| builder
    test -->|"tests"| layout

    doc -->|"documents"| builder
    doc -->|"includes"| podspec
    doc -->|"includes"| xcode

    click builder "https://github.com/cocoanetics/dtcoretext/tree/develop/Core/Source"
    click layout "https://github.com/cocoanetics/dtcoretext/tree/develop/Core/Source"
    click view "https://github.com/cocoanetics/dtcoretext/blob/develop/Core/Source/DTAttributedTextView.h"
    click label "https://github.com/cocoanetics/dtcoretext/blob/develop/Core/Source/DTAttributedLabel.h"
    click cell "https://github.com/cocoanetics/dtcoretext/blob/develop/Core/Source/DTAttributedTextCell.h"
    click demo "https://github.com/cocoanetics/dtcoretext/tree/develop/Demo"
    click test "https://github.com/cocoanetics/dtcoretext/tree/develop/Tests/DTCoreTextTests"
    click doc "https://github.com/cocoanetics/dtcoretext/tree/develop/Documentation"
    click podspec "https://github.com/cocoanetics/dtcoretext/blob/develop/DTCoreText.podspec"
    click xcode "https://github.com/cocoanetics/dtcoretext/blob/develop/DTCoreText.xcodeproj"

    classDef core fill:#aaffaa,stroke:#333,stroke-width:2px;
    classDef ui fill:#aaaaff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffddaa,stroke:#333,stroke-width:2px;
```
