How are the templates in the js_example module retrieved?
Inside js_example.module there's a function which declares how a render array using a certain '#theme' is to be rendered as HTML and which variables might be available. This function is hook_theme. It also can define a template that Drupal will look for inside the module's template folder.

function js_example_theme() {

  return [
    'js_example_accordion' =&gt; [
      'template' =&gt; 'accordion',
      'variables' =&gt; [
        'title' =&gt; NULL,
      ],
    ],
  ];
}


Next there is the src/Controller/JsExampleController.php which has a function to output stuff and is told to use the 'js_example_accordion'-'#theme' for that.

  public function getJsAccordionImplementation() {

    $title = $this-&gt;t('Click sections to expand or collapse:');

    $build['myelement'] = [
      '#theme' =&gt; 'js_example_accordion',
      '#title' =&gt; $title,
    ];

    $build['myelement']['#attached']['library'][] = 'js_example/js_example.accordion';

    return $build;
  }


That's the basics.



The description.html.twig is used a little bit differently but maybe just skip that for now as its some kind of advanced exception you'll understand later.