# Relationship between swift-docc, swift-docc-render, and swift-docc-plugin

**URL:** <https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980>\
**Category:** Swift-DocC\
**Tags:** docc-render\
**Created:** [August 16, 2024, 3:39am UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980 "2024-08-16T03:39:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucca-mito](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucca-mito/32/24744_2.png) [@Lucca-mito](https://forums.swift.org/u/Lucca-mito)\
**Post date:** [August 16, 2024, 3:39am UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980/1 "2024-08-16T03:39:35Z")

</div>

Although I’ve been using DocC (through its Swift compiler plugin) for a while, I’m new to contributing to DocC. So I have some beginner’s questions.

My understanding so far is that:

1. [swift-docc](https://github.com/swiftlang/swift-docc) transforms in-source documentation into a [symbol graph](https://github.com/swiftlang/swift-docc-symbolkit).
2. [swift-docc-render](https://github.com/swiftlang/swift-docc-render) transforms that symbol graph into a Vue.js SPA.
3. The [swift-docc-plugin](https://github.com/swiftlang/swift-docc-plugin) (namely, its `generate-documentation` command) does #1 then #2.

Assuming the three descriptions above are all reasonably accurate, which they may very well not be,

- Why does [the swift-docc-plugin README](https://github.com/swiftlang/swift-docc-render?tab=readme-ov-file#swift-docc-render) state that swift-docc outputs a documentation archive, not a symbol graph?
  - As far as I know, the documentation archive and the symbol graph are both JSON representations of the symbols in the source code: the former is packaged as a `.doccarchive` file, and the latter is technically a conceptual graph implemented as [a Swift struct](https://github.com/swiftlang/swift-docc-symbolkit/blob/main/Sources/SymbolKit/SymbolGraph/SymbolGraph.swift) that’s _then_ encoded into JSON. But what is the relationship between the two?

- Why does swift-docc depend on swift-docc-plugin? Shouldn’t it be the other way around? (The dependency is declared [here](https://github.com/swiftlang/swift-docc/blob/main/Package.swift#L142). Even more curiously, the dependency on swift-docc-plugin doesn’t seem to actually be used by any compilation targets.)
- Similarly, why _doesn’t_ swift-docc-plugin depend on swift-docc-render? If assumption #3 is correct, then swift-docc-plugin’s `generate-documentation` command is essentially just swift-docc followed by swift-docc-render.
- Why does swift-docc-render include [a script for generating a symbol graph](https://github.com/swiftlang/swift-docc-render/blob/main/bin/generate-symbol-graph)? Isn’t that the purview of swift-docc?

Thanks!

---

<div class="post-metadata">

**Author:** ![krilnon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/krilnon/32/276_2.png) [@krilnon](https://forums.swift.org/u/krilnon)\
**Post date:** [August 16, 2024, 11:38am UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980/2 "2024-08-16T11:38:52Z")

</div>

Hey, here's my understanding of how these parts relate:

> [@Lucca-mito](#):
>
> [swift-docc](https://github.com/swiftlang/swift-docc) transforms in-source documentation into a [symbol graph](https://github.com/swiftlang/swift-docc-symbolkit).

DocC turns documentation markup (and DocC catalogs) into DocC archives (which hold the render JSON used by DocC render to show docs websites).

A tool like `swiftc -emit-symbol-graph` is what gives DocC its knowledge of the in-source docs and the associated declarations / symbol relationships. DocC further transforms the symbol graph info when it has it.

> [@Lucca-mito](#):
>
> The [swift-docc-plugin](https://github.com/swiftlang/swift-docc-plugin) (namely, its `generate-documentation` command) does #1 then #2.

Yeah, the plugin bundles up bunch of the steps. However, I think its intended use case is for SwiftPM packages or similar where you have source code (and potentially dependencies). The plain DocC tool can operate on a bare DocC bundle and on symbol graphs that it might have received without the associated source code.

> [@Lucca-mito](#):
>
> Why does [the swift-docc-plugin README](https://github.com/swiftlang/swift-docc-render?tab=readme-ov-file#swift-docc-render) state that swift-docc outputs a documentation archive, not a symbol graph?

The symbol graph is an input to DocC; the output is render JSON (often inside a DocC archive), which DocC render uses as input.

> [@Lucca-mito](#):
>
> Why does swift-docc depend on swift-docc-plugin? Shouldn’t it be the other way around? (The dependency is declared [here](https://github.com/swiftlang/swift-docc/blob/main/Package.swift#L142). Even more curiously, the dependency on swift-docc-plugin doesn’t seem to actually be used by any compilation targets.)

I don't know, but it hasn't always. From [the PR where Ethan added the dependency](https://github.com/swiftlang/swift-docc/pull/106), it seems like it might be a way to get a fresh copy of DocC render when building everything locally.

> [@Lucca-mito](#):
>
> Similarly, why _doesn’t_ swift-docc-plugin depend on swift-docc-render?

I think both DocC and DocC render come bundled in every environment where you get Swift (like the [swift.org](http://swift.org) toolchains), so they're dependencies but not in the SwiftPM sense.

> [@Lucca-mito](#):
>
> Why does swift-docc-render include [a script for generating a symbol graph](https://github.com/swiftlang/swift-docc-render/blob/main/bin/generate-symbol-graph)? Isn’t that the purview of swift-docc?

That's code specific to generating a symbol graph for Vue components, which is something DocC doesn't normally support but that it uses for its own self-documentation. For example [the TabNavigator directive docs](https://www.swift.org/documentation/docc/tabnavigator) come from that script.

* * *

Hope this helps! There might be a couple inaccuracies or over simplifications, but if nothing else that'll give someone who works on DocC on a more daily basis a springboard to add more info.

---

<div class="post-metadata">

**Author:** ![QuietMisdreavus](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/quietmisdreavus/32/18057_2.png) [@QuietMisdreavus](https://forums.swift.org/u/QuietMisdreavus)\
**Post date:** [August 16, 2024, 3:40pm UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980/3 "2024-08-16T15:40:35Z")

</div>

> [@Lucca-mito](#):
>
> - [swift-docc](https://github.com/swiftlang/swift-docc) transforms in-source documentation into a [symbol graph](https://github.com/swiftlang/swift-docc-symbolkit).

This is probably the major misunderstanding. A "symbol graph" is a representation of source code that Swift-DocC loads to create documentation. It's generated by Clang and Swift (and anything else that wants to get loaded by Swift-DocC, like the Vue components in Swift-DocC-Render) and provided as an input to Swift-DocC.

> [@Lucca-mito](#):
>
> Why does [the swift-docc-plugin README](https://github.com/swiftlang/swift-docc-render?tab=readme-ov-file#swift-docc-render) state that swift-docc outputs a documentation archive, not a symbol graph?

See above, but the README is correct. The JSON files ending in `.symbol.json` and loaded by Swift-DocC are "symbol graphs", loaded into data structure definitions defined in SymbolKit, and reflect the source code being documented. The JSON files in the "documentation archive" are called "Render JSON", and reflect a rendered documentation page, including any visual styling that may occur. This is represented in code by [Swift-DocC's `RenderNode` type](https://github.com/swiftlang/swift-docc/blob/main/Sources/SwiftDocC/Model/Rendering/RenderNode.swift) and its constituent types, and is provided as an input to Swift-DocC-Render.

> [@Lucca-mito](#):
>
> Why does swift-docc depend on swift-docc-plugin?

This is a quirk of SwiftPM command plugins. swift-docc-plugin provides the `swift package generate-documentation` command, for quickly building the documentation for a Swift package. However, it can only ever be added to a package's dependencies; due to limitations in SwiftPM, it can't be installed globally. So here, adding swift-docc-plugin to Swift-DocC's dependencies is just a way for Swift-DocC contributors to easily generate documentation for Swift-DocC outside of Xcode.

> [@Lucca-mito](#):
>
> Similarly, why _doesn’t_ swift-docc-plugin depend on swift-docc-render?

swift-docc-plugin uses Swift-DocC from an installed toolchain. In toolchains that ship from [swift.org](http://swift.org) or in Xcode, Swift-DocC-Render is packaged alongside Swift-DocC in a well-known path, [that Swift-DocC will determine on its own](https://github.com/swiftlang/swift-docc/blob/979ea2d8b3cd6ca8f71627ce62250fb109286b0a/Sources/SwiftDocCUtilities/ArgumentParsing/Options/TemplateOption.swift#L41-L51). This way, you don't need to build Swift-DocC-Render yourself, or download [the pre-built artifact](https://github.com/swiftlang/swift-docc-render-artifact) either. If you want to use a specific build of Swift-DocC-Render for testing, you'll need to set [the `DOCC_HTML_DIR` environment variable](https://github.com/swiftlang/swift-docc/blob/main/CONTRIBUTING.md#2-set-the-path-to-your-renderer) yourself.

> [@Lucca-mito](#):
>
> Why does swift-docc-render include [a script for generating a symbol graph](https://github.com/swiftlang/swift-docc-render/blob/main/bin/generate-symbol-graph)?

Swift-DocC was originally written to document Swift and Objective-C projects, but it doesn't integrate directly into either compiler. As mentioned earlier, it uses symbol graphs to load the source code representation. Swift-DocC-Render uses this script to create a symbol graph of its own so that it can use Swift-DocC for documentation, despite not being written in Swift. (Similarly, this approach could be taken for any source language or data format, so long as you can map it into a symbol graph...)

* * *

Hope this helps! I know @krilnon added some information, but i wanted to come in here and flesh it out more (and provide a bunch of links 😅) so that it could be a bit more authoritative.

---

<div class="post-metadata">

**Author:** ![Lucca-mito](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucca-mito/32/24744_2.png) [@Lucca-mito](https://forums.swift.org/u/Lucca-mito)\
**Post date:** [September 21, 2024, 3:00am UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980/4 "2024-09-21T03:00:00Z")

</div>

Thanks, @QuietMisdreavus!

I didn't mention this in my original post, but my mentor and I are contributing to DocC as part of the Swift Mentorship Program. So, as a follow-up, were were also hoping to better understand the distinction between a documentation bundle and a documentation catalog, especially since both are directories with the `.docc` extension and with approximately the same contents.

Our understanding so far is:

1. A documentation _bundle_ is the (sole) input to the standalone, language-agnostic `docc` command. A documentation _catalog_ is an optional input to the swift-docc-plugin, the other input being Swift source code.

2. The catalog and bundle both contain assets and free-form Markdown; a documentation bundle may also contain a symbol graph generated by the appropriate compiler.

3. If you use DocC via the standalone, language-agnostic `docc` command, you must manually create the documentation bundle.

4. If you use DocC via the swift-docc-plugin, the plugin combines symbol graph(s) with the documentation catalog (if any) into a documentation bundle. Then the plugin passes the documentation bundle it generated to the language-agnostic `docc`, which then generates a documentation **archive** from this documentation **bundle** that was generated (in part) from the documentation **catalog.**

I've combined the observations above with your answers to my previous question into the diagram below. Is our understanding correct? (I've omitted the intermediate `.docc-build`.)

 ![Partial DocC pipeline](https://global.discourse-cdn.com/swift/original/3X/6/1/61824c27b039776487fbe25369e26227ee65f96e.png)

---

<div class="post-metadata">

**Author:** ![ronnqvist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ronnqvist/32/20110_2.png) [@ronnqvist](https://forums.swift.org/u/ronnqvist)\
**Post date:** [September 21, 2024, 8:36am UTC](https://forums.swift.org/t/relationship-between-swift-docc-swift-docc-render-and-swift-docc-plugin/73980/5 "2024-09-21T08:36:26Z")

</div>

> [@Lucca-mito](#):
>
> [We] were also hoping to better understand the distinction between a documentation bundle and a documentation catalog, especially since both are directories with the `.docc` extension and with approximately the same contents.

A directory with a `.docc` extension is a documentation _catalog_, nothing else.

A documentation _bundle_ isn’t a user-facing term. It’s a in-memory object that represent the list of “discovered” input files—categorized by their kind—to build documentation from.

When you pass a catalog to `docc convert` (either by invoking it directly or by going through another tool like the plugin), the first step of that command is to search through that catalog directory to find all the markup files, resources (images, etc.), and symbol graph files.

If you _don’t_ pass a catalog to `docc convert` but you pass a symbol graph directory using the `--additional-symbol-graph-dir` option (either by invoking it directly or by going through another tool like the plugin), then the first step of the command will create a _bundle_ (in-memory object listing the “discovered” input files) using only those symbol graph files.

This first step, in both cases, normalizes the inputs so that the rest of the command doesn’t need to known if the developer passed a catalog on the command line or not. It only needs to know the list of files (of each kind) that it should process.
