Skip to content

(WIP) Revised tutorial structure/template #3230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

mDuo13
Copy link
Collaborator

@mDuo13 mDuo13 commented Aug 12, 2025

  • Update "Tutorial Guidelines" with more specific, actionable guidelines for making tutorials. ⇒ Preview
    • Known issue: I haven't deleted the old screenshots yet, but that should happen before merging this (if we're going to go through with it)
  • Rewrite the Tutorial Structure page into a Tutorial Template, representing the best practices for how tutorials should work. ⇒ Preview
  • Refactor the verify_credential.js code sample into a linear script that is much less powerful but much simpler, as a demonstration of the guidelines for code samples. This is somewhat experimental and should be used as a point of comparison to confirm if this is really the direction we want to go with code samples & tutorials in general.
    • Compare: Current verify_credential.js vs Revised verify_credential.js
    • Known issue: The existing tutorial still needs to be updated to reflect the new code sample. Probably, some of the examples from the usage section should be moved to the README. (You have to edit the hard-coded values instead of passing them on the commandline now.)

1. Sample code snippets they can copy and paste into their own applications.
2. Complete API reference documentation.
- Developers can copy and paste the sample code into their own applications.
- Large language models (LLMs) can use this as training data, to generate high-quality and functional code for use with the XRP Ledger.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Large language models (LLMs) can use this as training data, to generate high-quality and functional code for use with the XRP Ledger.
- Large language models (LLMs) can use this as training data to generate high-quality code for use with the XRP Ledger.


Modular tutorials follow Malcolm Knowles’ six assumptions for designing adult learning:
LLMs are increasingly being used in software development, for example in tools that can generate code based on natural-language descriptions. To assist users of these tools, we would like to provide many working code samples that demonstrate best practices and follow consistent structure and style. Tutorials that have descriptions of what the code does alongside matching code snippets help LLMs develop the correct associations between terms used in natural language and programming language, hopefully leading to more accurate results from code generation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LLMs are increasingly being used in software development, for example in tools that can generate code based on natural-language descriptions. To assist users of these tools, we would like to provide many working code samples that demonstrate best practices and follow consistent structure and style. Tutorials that have descriptions of what the code does alongside matching code snippets help LLMs develop the correct associations between terms used in natural language and programming language, hopefully leading to more accurate results from code generation.
LLMs are increasingly being used in software development. To assist users of these tools, we would like to provide many working code samples that demonstrate best practices and follow consistent structure and style. Tutorials that have descriptions of what the code does alongside matching code snippets help LLMs develop the correct associations between terms used in natural language and programming language, hopefully leading to more accurate results from code generation.


Sample code is well commented snippets or applications that illustrate best practices for implementing a feature of the API. Sample code is modular and reusable with little customization required.
Sample code should be provided in the `_code-samples/` folder at the top of this website's source repository, with separate subfolders by programming language. There should be a `README.md` file for each code sample _above_ the language folders describing what the code sample does in general, _and_ a `README.md` in each programming language folder describing how to install and run that code sample specifically.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Sample code should be provided in the `_code-samples/` folder at the top of this website's source repository, with separate subfolders by programming language. There should be a `README.md` file for each code sample _above_ the language folders describing what the code sample does in general, _and_ a `README.md` in each programming language folder describing how to install and run that code sample specifically.
Sample code should be organized by functionality in the [_code-samples/](TBD) repository, with subfolders for each programming language. Include a `README.md` in the code sample folder describing what the code samples do in general, _and_ a `README.md` in each programming language folder describing how to install and run that code sample specifically.

Place holder until code samples moved to submodule repo.


## Concepts
Use comments to separate out logical sections of the sample code. You can these comments as markers so that the `{% code-snippet ... %}` Markdoc component shows only the relevant section at a time in a tutorial.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth having a small section documenting all our tags. Maybe not in this page, but a separate reference page we can link to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on documenting all our tags, definitely needed.


Some legacy tutorials show example requests and responses using WebSocket or JSON-RPC APIs, sometimes using the `rippled` commandline. These are not recommended, for the following reasons:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Some legacy tutorials show example requests and responses using WebSocket or JSON-RPC APIs, sometimes using the `rippled` commandline. These are not recommended, for the following reasons:
Some legacy tutorials show example requests and responses using WebSocket, JSON-RPC APIs, or the `rippled` commandline. These are not recommended, for the following reasons:

Comment on lines +44 to +49

You can find the complete source code for this tutorial's examples in the {% repo-link path="resources/contribute-documentation/tutorial-structure.md" %}resources section of this website's repository{% /repo-link %}.

{% admonition type="success" name="Tip" %}
Use the `{% repo-link ... %}` component to link to the source files; this component is designed to adjust based on the environment, so for example previews link to the code on the preview branch... although it doesn't fully work as of this writing (2025-08-11).
{% /admonition %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can find the complete source code for this tutorial's examples in the {% repo-link path="resources/contribute-documentation/tutorial-structure.md" %}resources section of this website's repository{% /repo-link %}.
{% admonition type="success" name="Tip" %}
Use the `{% repo-link ... %}` component to link to the source files; this component is designed to adjust based on the environment, so for example previews link to the code on the preview branch... although it doesn't fully work as of this writing (2025-08-11).
{% /admonition %}
Use the `{% repo-link ... %}` component to link to the source files; this component is designed to adjust based on the environment, so for example previews link to the code on the preview branch... although it doesn't fully work as of this writing (2025-08-11).

Doesn't feel great to tell someone to use a tag and in the same breath say it doesn't work. How big of a lift is it to fix that component?

Comment on lines +53 to +70
To test that the code runs properly, you can navigate to the repository top and start the local Redocly server as follows:

```sh
npm run start
```

Then, navigate to <http://localhost:4000/resources/contribute-documentation/tutorial-structure> to view the parsed version of this page.

{% admonition type="info" name="Usage is optional" %}
You should include a Usage section in **sample app tutorials**. Provide a "Usage" section if this tutorial's sample code:
- Has a GUI with multiple buttons/inputs
- Is a commandline utility with multiple options/parameters
- Consists of multiple scripts that need to be run in a specific order

If there's a user interface, you can also embed a video demonstrating usage of the sample app.

For single-file scripts that perform a linear set of steps without user input, omit the Usage section.
{% /admonition %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the previous sections, the admonition info feels like the actual instructional part we want to be the focus. Maybe we move the "example" text into the admonition block instead?

{% /tab %}
{% /tabs %}

### 2. Connect and get account(s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 2. Connect and get account(s)
### 2. Connect and get account(s)

I get we're trying to show a real example header here, but it feels a little confusing to have the header not match the content of the step. I think it'd be better to match the header to the content, in this case: 2. Label step headings

Comment on lines +103 to +115
Most code samples need at least one account. The first step should generally cover from the start of the file (including imports) through instantiating a client, connecting to a network, and deriving wallets and/or funding accounts via the faucet.

{% tabs %}

{% tab label="JavaScript" %}
{% code-snippet file="/_code-samples/verify-credential/js/verify_credential.js" language="js" before="// Look up Credential" /%}
{% /tab %}

{% /tabs %}

{% admonition type="info" name="Code snippets and steps" %}
Each "step" of the tutorial should correspond to one code snippet (with tabs by programming language). There can be exceptions, for example if one programming language needs additional code in a separate place to make the same functionality work.
{% /admonition %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a separate step (3. Code guidelines), assuming we follow the previous suggestion of breaking steps out as the "instructions" of this tutorial.

Comment on lines +161 to +169
Use `{% code-snippet ... %}` tags instead of copy-paste to display the code samples, so that you don't have to manually keep the code in the doc synchronized with changes to the code sample. To facilitate this, use `from=` and `before=` strings based on unique comments in the code. The first code snippet should omit `from=` and the last should omit `before=`.

{% tabs %}

{% tab label="JavaScript" %}
{% code-snippet file="/_code-samples/verify-credential/js/verify_credential.js" language="js" from="// Credential has passed all checks" /%}
{% /tab %}

{% /tabs %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into the proposed step 3 above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants