--- url: https://docs.tinytank.dev/1.x.md --- # What is TinyTank? ::: warning Status: beta (0.x) TinyTank runs real sites, but it's young: few sites run on it so far, and its API may still change between minor versions (each release's notes in the [changelog](https://github.com/tinytankphp/framework/blob/main/CHANGELOG.md) say what to update, see [Updating TinyTank](./extending/updating)). Review it as you would any dependency before relying on it, and keep it updated: security fixes go into the latest release only ([reporting a vulnerability](./security#reporting-a-vulnerability)). Provided as is, without warranty, under the MIT license. ::: TinyTank is a small PHP framework for sites that are **mostly static but need a little server-side life**: a marketing site with a blog, a documentation hub, a tool with a single interactive page. It gives you routing, Twig templates, reactive UI through [Datastar](https://data-star.dev), a Markdown blog, translations and SEO, without a database or an admin panel. TinyTank is freely inspired by [Craft CMS](https://craftcms.com), for its Twig-first templates, content that templates query rather than receive, and image transforms, and by [Datastar](https://data-star.dev), for its hypermedia approach: the server renders HTML, and the browser stays light. Everything a request needs (compiled routes, Twig templates, parsed blog posts, translations, the Vite manifest) is built ahead of time into plain PHP files in `var/cache`. Opcache keeps those in shared memory, so a production request does no parsing, no database queries and no file scanning. ```twig {# A live search box: Datastar calls the server, which renders a Twig partial back. #}
.php`
for each ([below](#languages)).
* \[ ] **Logo and favicon**: the skeleton's placeholders are `resources/icons/tinytank.svg` (shown in
the header as `icon-[app--tinytank]`) and `public/favicon.svg`. Replace them with your own;
renaming the icon file changes its class name, so update `templates/_layout.twig` too.
* \[ ] **Colours and fonts**: the `@theme` block in `resources/css/app.css`, where each colour is a
light and dark pair, and the font import above it ([Fonts & icons](../features/fonts-icons),
[Dark & light theme](../features/theme)).
* \[ ] **Check the colours** in both themes once they're yours: `npm run build && npm run test:a11y`
([Checking](../accessibility/checking)). A new palette often fails contrast in one theme; see
[Colour and contrast](../accessibility/contrast). Optionally, check before every push:
`git config core.hooksPath .githooks`.
## 3. The starter content
The skeleton comes with **examples**, so you can see how things fit together: Datastar demos on the
home page (a live search, a like button, a sound you can play, a server clock), an FAQ as a data
collection, two blog posts and a draft, and an Italian translation of everything. `create-project`
asks whether to keep them; when you're done learning from them, one command removes them all,
with their tests:
```sh
php bin/console site:clean # lists what goes, then asks
php bin/console site:clean --dry-run # only lists
```
It deletes the files listed in `.examples` and the blocks marked `example:start` … `example:end` in
the site's config, templates and tests, then `.examples` itself. What's left is a working site whose
tests pass: an English home page with your site's name and latest posts, the blog, About, Contact,
Privacy and the style guide. Until you run it, the home page says how, and `deploy` reminds you.
* \[ ] **Remove the examples** (`site:clean`), or keep the ones you want: delete the marked block
around something to keep it, then clean.
The pages that stay are starting points to adapt:
| What | Where | Tests that check it |
|---|---|---|
| The home page | `templates/index.twig`, `src/Controller/HomeController.php` | `tests/PagesTest.php` |
| Pages: About (with a child page), Contact (with its form) and Privacy | `content/pages/`; Contact and Privacy are worth adapting rather than deleting | `tests/PagesTest.php`, `tests/ContactTest.php`, `tests/CdnTest.php`, `tests/e2e/contact.spec.js` |
| The style guide (below) | `content/pages/style-guide/` | `tests/PagesTest.php`, `tests/e2e/style-guide.spec.js`, and the browser tests that use its image and video (`accessibility`, `images`, `no-javascript`, `video`) |
When you change or delete one, update the tests listed next to it, then run `ddev composer test`
and the [browser tests](../testing#browser-tests).
### Languages
`site:clean` leaves an English-only site; the language switcher disappears by itself with one
language. For another language, or several: list them in `languages` in `config/app.php` (and set
`language` to the main one), add `translations/.php`, and give pages and posts their
`index..md` versions ([Languages](../features/languages)). An Italian-only site: change
`language` and `languages` to `it`, and copy `translations/it.php` from the skeleton.
### The style guide
`/style-guide` shows every element a post or page can contain (text, headings, lists, quotes, code
in several languages, tables, images, video) in your site's design, in light and dark mode. It's an
[unlisted](../content/pages#unlisted-pages) page: reachable by its address, but not in search
engines, the sitemap or the menus.
* \[ ] While designing: keep it, and give the address to your designer.
* \[ ] Before going live: keep it (it's harmless) or delete `content/pages/style-guide/` and the test
that checks it (`testTheStyleGuideShowsEveryElementButStaysUnlisted` in `tests/PagesTest.php`,
`tests/e2e/style-guide.spec.js`); the image and video browser tests open it too, point them at
a page of yours.
## 4. Contact and privacy
* \[ ] **Where the contact form goes**: `CONTACT_TO` and the mailer (`MAILER_DSN`, `MAILER_FROM`) in
`.env` ([Forms](../features/forms)). In DDEV, Mailpit catches every message.
* \[ ] **The privacy page** (`content/pages/privacy/`) describes the skeleton's defaults. Make it
describe your site: what the contact form does with messages, the log
([Logging](../features/logging)), and anything you add, such as videos, a CDN or analytics.
## 5. Licenses
* \[ ] **Changed a font, the icons or added a script?** Update `public/third-party-licenses.txt` and
the `/*! … */` notices ([Fonts & icons](../features/fonts-icons#licenses));
`tests/LicensesTest.php` checks them.
* \[ ] **Your site's own license**: `composer.json` says `proprietary`. Change it if your site's code
is open source, and add a `LICENSE` file.
## 6. Commit
* \[ ] The first commit, with `composer.lock`, then push to your site's repository.
## Before going live
The [production checklist](../deployment/#production-checklist): `.env` on the server, `APP_DEBUG`
off, the web server, Opcache, HTTPS, email, logs and, if you use one, the CDN.
---
---
url: https://docs.tinytank.dev/1.x/getting-started/structure.md
---
# Project structure
```
my-site/
├── bin/console Console entry point: deploy, cache:clear, your commands
├── config/
│ ├── app.php Settings: secret, URL, languages, blog, site defaults
│ ├── bootstrap.php The app's extension point: services, Twig additions, deploy steps
│ ├── collections.php Data collections and their fields
│ ├── forms.php Forms: fields, recipients, spam checks
│ ├── globals.php Values every template can read (social links, contacts)
│ ├── redirects.php Pages that moved: old path → new path
│ └── routes.php Routes → controllers
├── content/blog/ Blog posts, one folder each (see "The blog")
├── content/pages/ Content pages: About, Privacy… one folder each (see "Content pages")
├── content// Data collection items, e.g. content/faq/ (see "Data collections")
├── packages/ Empty (.gitkeep); used by TinyTank maintainers, see Contributing
├── public/ Web root: index.php, build/ (Vite), media/ (published post files)
├── resources/ Frontend sources: js/app.js, js/pages/*.js, css/app.css, icons/*.svg
├── src/ Your PHP code (namespace App\): Controller/, Command/, …
├── templates/ Twig templates; _partials/ are rendered by Datastar requests
├── tests/ Your app's tests
├── translations/ UI texts per language: en.php, it.php, …
├── var/cache/ Compiled caches (safe to delete)
├── var/deploy/ deploy's next build, and the previous one (for deploy --rollback)
├── var/log/ The log, one file per day (see Logging)
├── var/state/ Kept across deploys: the forms' rate limits
├── vendor/tinytank/framework/ ★ The framework, installed by Composer: never edit it
├── .env Local environment (never committed)
├── AGENTS.md Instructions for AI coding agents (CLAUDE.md points to it)
├── composer.json Your app's dependencies; requires tinytank/framework
└── vite.config.js Your entry points and Vite plugins
```
## The framework is a package
The framework is the `tinytank/framework` package from
[tinytankphp/framework](https://github.com/tinytankphp/framework). Composer installs it
into `vendor/tinytank/framework`, together with its own dependencies (Symfony components, Twig,
CommonMark…); your `composer.json` only requires `tinytank/framework`. Framework code never
depends on `App\` classes.
::: warning Never edit vendor/
Everything a site needs to change has an extension point in your own files. Framework updates
arrive with `composer update tinytank/framework` (see [Updating TinyTank](../extending/updating)),
which would overwrite any edit in `vendor/`.
:::
## What's yours, what's TinyTank's
| Yours (edit freely) | TinyTank's (don't edit in a site) |
|---|---|
| `config/`, `src/`, `templates/`, `content/`, `translations/`, `resources/`, `tests/` | `vendor/tinytank/framework/` |
| `public/index.php`, `bin/console` (three-line entry points) | its Vite plugin, `resources/vite/tinytank.js` |
| `vite.config.js` (entry points, extra plugins) | its test base class, `TinyTank\Testing\KernelTestCase` |
## Namespaces
| Namespace | Directory |
|---|---|
| `TinyTank\` | `vendor/tinytank/framework/src/` |
| `App\` | `src/` |
| `App\Tests\` | `tests/` |
---
---
url: https://docs.tinytank.dev/1.x/getting-started/first-page.md
---
# Your first page
TinyTank has two kinds of pages, and most sites need far more of the first:
* **A content page**: a Markdown file in `content/pages/`. Its folder is its URL. No route, no
controller. Use it for anything that is text and images: About, Team, Services, Privacy.
* **A page with a controller**: a route, a PHP class and a Twig template, for pages that compute
something on each request.
This guide makes one of each, then adds a little interactivity.
## 1. A content page
Create `content/pages/team/index.md`:
```md
---
title: Our team
summary: The people behind the studio.
---
We are three designers and a developer, working from a small studio by the sea.
## What we do
Brand identities, websites and the occasional illustration.
```
Open `/team`. That's all: the page has its title, meta description and canonical URL, it's in the
sitemap, and the skeleton's menu lists it (menus are [queries](../basics/querying) over pages). An
Italian version is `index.it.md` in the same folder. Images go in the folder next to `index.md`.
The skeleton already has About, Contact and Privacy built this way. See
[Content pages](../content/pages) for templates per page, child pages, translated URLs and
[unlisted pages](../content/pages#unlisted-pages); repeating items with the same fields (services,
team members, products) are a [data collection](../content/collections).
::: warning One URL, one owner
A route and a content page can't share a URL: `deploy` stops when a route hides a page. Don't
create an `/about` route while `content/pages/about/` exists.
:::
## 2. A page with a controller
A page that changes on every request, say a studio's opening hours with "open now" or "closed
now", needs a controller. Add a route to `config/routes.php`:
```php
use App\Controller\HoursController;
return static function (Kernel $app): void {
// …existing routes
$app->get('/hours', HoursController::class, 'hours');
};
```
The third argument is the route's **name**: templates link to it with `path('hours')`, and
TinyTank adds the language prefix (`/it/hours`) on Italian pages.
Create `src/Controller/HoursController.php`:
```php
format('G');
$this->app->seo
->title($this->t('Opening hours'))
->description($this->t('When you can visit the studio.'));
return $this->render('hours.twig', ['open' => $hour >= 9 && $hour < 18]);
}
}
```
And `templates/hours.twig`:
```twig
{% extends '_layout.twig' %}
{% block content %}
{{ 'Opening hours'|t }}
{{ 'Monday to Friday, 9:00 to 18:00.'|t }}
{{ open ? 'Open now'|t : 'Closed now'|t }}
{% endblock %}
```
The layout prints the ``, meta description, canonical URL, Open Graph tags and the language
switcher from what the controller set on `seo`. Italian texts go in `translations/it.php`, keyed
by the English text:
```php
'Opening hours' => 'Orari di apertura',
'Open now' => 'Aperto ora',
```
::: tip Pages are cached by browsers and CDNs
TinyTank pages are public and revalidated with an ETag: a page whose content depends on the time
is fine (the ETag changes with it), but anything personal to a visitor isn't: call
`$this->app->noStore()` for such a response (see [CDN caching](../deployment/cdn#not-at-the-cdn-or-nowhere)).
:::
## 3. A little interactivity
Interactivity uses [Datastar](../basics/datastar): HTML attributes, no JavaScript to write, and no
inline `` in any value can't break out of the tag.
---
---
url: https://docs.tinytank.dev/1.x/features/frontend.md
---
# Frontend & Vite
Assets are built by [Vite](https://vite.dev) with [Tailwind CSS](https://tailwindcss.com).
Sources live in `resources/`:
```
resources/
css/app.css Tailwind, plus the typography plugin for blog posts
js/app.js loaded on every page: the CSS and the Datastar client
js/pages/*.js one bundle per page or feature (see JavaScript & Datastar)
icons/*.svg your own icons, used as icon-[app--] (see Fonts & icons)
```
The Datastar client itself ships with the framework, matched to its PHP SDK, and is imported as
`'datastar'`. It's MIT-licensed: its license notice is kept in your built JavaScript, and the full
text is in the skeleton's `public/third-party-licenses.txt`.
## Development
```sh
ddev npm run dev
```
The dev server runs on port 5173 (exposed by DDEV at `https://.ddev.site:5173`). While it
runs, pages load assets from it, and:
| You change | What happens |
|---|---|
| CSS | styles update in place, no reload |
| JavaScript | the page reloads (unless the module handles hot updates itself) |
| a Twig template, a Markdown post, a translation file | the page reloads |
This only happens with `APP_DEBUG=1`. Vite writes its URL to `var/vite.hot` while it runs, and PHP
reads it in debug mode only. If Vite was killed and pages still point at port 5173, delete
`var/vite.hot`.
## Production build
```sh
npm run build
```
This writes hashed files and source maps to `public/build/`, plus a manifest that
`{{ vite('resources/js/app.js') }}` reads to print the right `` and `` in any value can't break out of the tag.
* Only whitelisted file types in a post folder are ever served or published.
* SVGs are served with a script-blocking policy in development; in production, treat SVGs from
others as code.
## Responses
* Every response sends `X-Content-Type-Options: nosniff`, `Referrer-Policy:
strict-origin-when-cross-origin` and `X-Frame-Options: SAMEORIGIN`.
* Pages send a strict Content Security Policy (below).
* Absolute URLs come from `APP_URL` only, so a forged `Host` header can't poison cached pages.
* Production errors are logged, never shown: visitors get a generic error page. The log holds no IP
addresses, query strings or function arguments, and is deleted after 14 days ([Logging](./features/logging)).
## Deployment
* There's no HTTP endpoint for deployment tasks: cachetool reaches PHP-FPM through its local socket.
* The reload command comes from the server's own configuration; keep `.env` writable only by the
deploy user.
* The cachetool phar is pinned to a version and checked against its SHA-256 hash.
## Content Security Policy
Every page tells the browser where it may load things from. By default that's **only your own
site**, so even if someone managed to inject markup into a page, the browser would refuse to load
their script, send data to their server or frame their page.
The default policy:
| Directive | Sources | Why |
|---|---|---|
| `default-src` | `'self'` | anything not listed below: your site only |
| `script-src` | `'self' 'unsafe-eval'` + the theme script's hash | your bundles; Datastar evaluates its `data-*` expressions as functions |
| `style-src` | `'self'` | your CSS |
| `style-src-attr` | `'unsafe-inline'` | `style="…"` attributes (e.g. `display: none` before `data-show` runs); they can't load anything |
| `img-src` | `'self' data:` | the icons are SVGs inlined in the CSS |
| `font-src`, `connect-src`, `media-src` | `'self'` | |
| `object-src` | `'none'` | no plugins |
| `base-uri`, `form-action`, `frame-ancestors` | `'self'` | no ` ` hijacking, forms only post to you, only you may frame your pages |
There are no per-request nonces: a nonce makes every response different, which would break ETags and
public caching. The one inline script, the theme script, is allowed by its hash, which never changes.
The JSON blocks (`public_config()`, JSON-LD) are data, not scripts, so the policy doesn't apply to
them.
While the Vite dev server runs (debug mode), its origin and WebSocket are allowed too. With
`MEDIA_URL` set, its host is allowed in `img-src` and `media-src`.
### Allowing other hosts
When a feature needs another host (a video player, analytics, a CDN), add it to the directive it
needs in `config/app.php`:
```php
'csp' => [
'enabled' => true,
'report_only' => false,
'sources' => [
'frame-src' => ['https://www.youtube-nocookie.com'],
'media-src' => ['https://cdn.example.com'],
],
],
```
or from `config/bootstrap.php`:
```php
$app->csp->allow('script-src', 'https://plausible.io')->allow('connect-src', 'https://plausible.io');
```
A directive the policy doesn't list yet (like `frame-src`) starts from `'self'`. Unknown directives
and sources containing spaces, `;` or `,` are refused, so a typo can't silently break the policy.
To try a change without breaking anything, set `report_only` to `true`: browsers then only report
what they would block, in the developer console. A controller can send its own
`Content-Security-Policy` header for one page; TinyTank then leaves it alone.
### Sources for one page
Components can allow a source on the page they appear on with `{% do csp_allow('frame-src', '…') %}`
(see [Content components](./content/components#allowing-sources-for-a-component)). The built-in video
components do this for their player, so `frame-src` lists YouTube or Vimeo only on pages that show a
video. Everything else keeps the site's policy.
### Inline scripts from Datastar
`execute_script()` runs its code as an inline `