Search by

silarhi / llms-txt-bundle

guillaume-sainthillier

Build, dump and serve an llms.txt file from your Symfony application, the PrestaSitemapBundle way.

Package info

github.com/silarhi/llms-txt-bundle

Homepage

Documentation

Type:symfony-bundle

pkg:composer/silarhi/llms-txt-bundle

Statistics

Installs: 5 962

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

v1.6.1 2026-11-27 12:04 UTC

This package is auto-updated.

Last update: 2026-11-27 15:49:40 UTC


README

License PHP Version CI Status Coverage

LLMs.txt Bundle

Build, dump and serve an llms.txt file from your Symfony application.
The PrestaSitemapBundle way: listeners fill it, a controller serves it, a command dumps it.

📖 Documentation

Features

  • Link providers: a #[AsLlmsTxtLinkProvider(section: 'Products')] method returns the links of a section, from your repositories
  • Event driven: listeners of LlmsTxtPopulateEvent change the whole document, like SitemapPopulateEvent
  • Route options: static pages join the file with an llms_txt route option, like the sitemap one
  • On the fly or dumped: the controller serves the dumped file when there is one, and builds it otherwise
  • Flat memory: links added as generators are read one at a time, streamed to the response or the dumped file
  • llms-full.txt: the Markdown of the pages, next to llms.txt, from the content of their links
  • Markdown versions: a route accepting the md format serves its page at page.md, and to the agents asking for text/markdown
  • Checks: debug:llms-txt shows where the links come from, and finds duplicates, relative URLs, a file too large
  • Spec compliant: H1 title, blockquote summary, H2 sections of links, the Optional section always last, escaped links
  • Discovery: a <link> tag for the <head> of your pages and an opt-in Link header, through WebLink

Requirements

  • PHP 8.2+
  • Symfony 6.4, 7.x or 8.x
  • symfony/framework-bundle to register the bundle: the package does not install it, and the generator, the renderers and the dumpers work without it, see Without the bundle

Installation

composer require silarhi/llms-txt-bundle

Import the route serving /llms.txt:

# config/routes/llms_txt.yaml
llms_txt:
    resource: '@LlmsTxtBundle/config/routes.php'

Without the bundle

An application without the framework or symfony/dependency-injection builds the services by hand, from an event dispatcher and the router (the llms_txt route options):

use Silarhi\LlmsTxtBundle\Controller\LlmsTxtController;
use Silarhi\LlmsTxtBundle\Event\LlmsTxtPopulateEvent;
use Silarhi\LlmsTxtBundle\EventListener\RouteOptionsListener;
use Silarhi\LlmsTxtBundle\LlmsTxt;
use Silarhi\LlmsTxtBundle\Service\Dumper;
use Silarhi\LlmsTxtBundle\Service\FullMarkdownRenderer;
use Silarhi\LlmsTxtBundle\Service\Generator;
use Silarhi\LlmsTxtBundle\Service\MarkdownRenderer;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Filesystem\Filesystem;

$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new RouteOptionsListener($router, 'Pages')); // the routes carrying an "llms_txt" option
$dispatcher->addListener(LlmsTxtPopulateEvent::class, static function (LlmsTxtPopulateEvent $event) use ($products): void {
    $event->getDocument()->addLinks('Products', $products->links()); // a generator of Link, read while writing
});

$generator = new Generator($dispatcher, title: 'SILARHI', summary: 'Web and mobile applications.');

// public/llms.txt, and public/llms-full.txt from the same listeners
(new Dumper($generator, new MarkdownRenderer(), new Filesystem(), __DIR__ . '/public', LlmsTxt::FILENAME))->dump();
(new Dumper($generator, new FullMarkdownRenderer(), new Filesystem(), __DIR__ . '/public', LlmsTxt::FULL_FILENAME))->dump();

// or serve it: the dumped file when there is one, built on the fly otherwise
$controller = new LlmsTxtController($generator, new MarkdownRenderer(), __DIR__ . '/public', 'text/plain; charset=UTF-8', 3600, LlmsTxt::FILENAME, true);
$response = $controller($request);

DumpCommand (with symfony/console), LlmsTxtExtension (with twig/twig) and MarkdownVersionListener are built the same way. What needs a container stays with the bundle class: the configuration, the #[AsLlmsTxtLinkProvider] attribute (add a LinkProviderListener to the dispatcher instead), the routes of routes.php, the cache warmers and Twig's escaping of the *.md.twig templates.

Quick start

# config/packages/llms_txt.yaml
llms_txt:
    title: 'SILARHI'
    summary: 'Web and mobile applications, from design to maintenance.'
use Silarhi\LlmsTxtBundle\Routing\LlmsTxtEntry;

#[Route('/contact', name: 'contact', options: ['llms_txt' => new LlmsTxtEntry(title: 'Contact')])]
public function contact(): Response

GET /llms.txt now lists the contact page. Add the pages of your database from a link provider, or dump the file with php bin/console llms-txt:dump.

Documentation

Everything else is on llms-txt-bundle.silarhi.dev:

Contributing

See CONTRIBUTING.md. Release notes are in CHANGELOG.md.

License

Released under the MIT License.