Developer Information
This chapter provides technical details for developers and integrators.
Architecture
The extension uses three PSR-15 middlewares:
- UrlSuffixMiddleware - Detects
.mdsuffix and rewrites URLs - LlmsTxtMiddleware - Serves the
/llms.txtendpoint - ContentFormatMiddleware - Transforms HTML to Markdown
Middleware Chain
Request: /about.md
│
▼
UrlSuffixMiddleware (before site resolver)
│ Strips .md suffix
│ Sets request attribute 'llms_txt_format' = 'md'
│ Rewrites URI to /about
▼
TYPO3 Site Resolver
│
▼
LlmsTxtMiddleware (after site, before page resolver)
│ Handles /llms.txt requests
▼
TYPO3 Page Resolver & Frontend
│
▼
ContentFormatMiddleware (after content-length-headers)
│ Checks for 'llms_txt_format' attribute
│ Converts HTML response to Markdown
▼
Response: Markdown with YAML frontmatter
Services
PageTreeService
RTfirst\LlmsTxt\Service\PageTreeService
Traverses the TYPO3 page tree and collects page data for llms.txt generation.
- Supports multi-language sites
- Respects page exclusion settings
- Handles translated pages with fallback
MarkdownConverterService
RTfirst\LlmsTxt\Service\MarkdownConverterService
Orchestrates content element to Markdown conversion using registered converters.
LlmsTxtGeneratorService
RTfirst\LlmsTxt\Service\LlmsTxtGeneratorService
Generates the llms.txt content for a site.
Content Converters
The extension uses a converter pattern for content element to Markdown conversion.
Each converter implements ContentConverterInterface:
interface ContentConverterInterface
{
public function supports(string $cType): bool;
public function convert(array $record, string $baseUrl): string;
}
Built-in Converters
| Converter | Supported CTypes | Description |
|---|---|---|
| HeaderConverter | header | Converts header elements |
| TextConverter | text, textpic, textmedia | Converts text and text+media |
| ImageConverter | image | Converts image galleries |
| BulletsConverter | bullets | Converts bullet lists |
| TableConverter | table | Converts tables |
| MenuConverter | menu_* | Converts menu elements |
| HtmlConverter | html | Converts raw HTML |
| DefaultConverter | (fallback) | HTML-to-Markdown fallback |
Creating Custom Converters
- Create a class implementing
ContentConverterInterface:
<?php
declare(strict_types=1);
namespace Vendor\MyExtension\Converter;
use RTfirst\LlmsTxt\Converter\ContentConverterInterface;
class MyCustomConverter implements ContentConverterInterface
{
public function supports(string $cType): bool
{
return $cType === 'my_custom_element';
}
public function convert(array $record, string $baseUrl): string
{
$header = $record['header'] ?? '';
$bodytext = $record['bodytext'] ?? '';
return "## {$header}\n\n{$bodytext}";
}
}
- Register the converter in
Services.yaml:
services:
Vendor\MyExtension\Converter\MyCustomConverter:
tags:
- name: 'llms_txt.content_converter'
priority: 100
Higher priority converters are checked first.
Event Listeners
CacheFlushEventListener
Invalidates llms.txt cache when TYPO3 caches are flushed.
HeaderLinkEventListener
Injects the <link rel="alternate"> tag into HTML responses.
BackendNotificationEventListener
Shows a notification in the Backend if robots.txt lacks llms.txt reference.
Caching
The extension uses two cache layers:
-
llms.txt Index Cache (
cache_pages)- Stores generated llms.txt content per site
- Invalidated on cache flush
-
Format Output Cache (
llms_txt_format)- Stores Markdown output per page/language
- 24-hour default lifetime
- Part of the
pagescache group
Database Schema
The extension adds fields to the pages table:
| Field | Type | Description |
|---|---|---|
| tx_llmstxt_description | text | LLM-specific page description |
| tx_llmstxt_summary | text | Extended page summary |
| tx_llmstxt_keywords | varchar(255) | Comma-separated keywords |
| tx_llmstxt_exclude | tinyint(1) | Exclude from llms.txt |
| tx_llmstxt_priority | int(11) | Priority (0-100) for sorting |
Code Quality
The extension maintains high code quality standards:
- PHPStan Level 8 compliant
- PSR-12 code style (php-cs-fixer)
- Unit tests for converters and services
Run quality checks:
# Static analysis
vendor/bin/phpstan analyse packages/llms_txt --level=8
# Code style check
vendor/bin/php-cs-fixer fix packages/llms_txt --dry-run
# Fix code style
vendor/bin/php-cs-fixer fix packages/llms_txt
# Run tests
vendor/bin/phpunit -c packages/llms_txt/phpunit.xml
Dependencies
- league/html-to-markdown (^5.1) - HTML to Markdown conversion
- typo3/cms-core (^13.0 || ^14.0)
- typo3/cms-frontend (^13.0 || ^14.0)