Configuration#
Lesstruct has two layers of configuration, each for a different concern:
config.toml— your site’s content schema: languages, custom post types, user profile fields, thumbnail variants. Edited by hand, version-controlled.- Environment variables (in
.envor the process env) — your deployment configuration: host, port, database, secrets, SMTP, AI integrations. Treated as deployment state, not committed.
This document covers both.
Table of Contents#
- Where the Files Live
- Environment Variables
- config.toml Reference
- Validation Rules
- Worked Examples
- What is NOT Configurable from config.toml
- Upgrading Lesstruct
- Troubleshooting
- Quick Reference
Where the Files Live#
| Concern | Default location | Override via env |
|---|---|---|
| Content schema | ./config.toml in the working directory | CONFIG_DIR (directory), CONFIG_FILE (filename) |
| Deployment config | .env in the working directory | process env wins over .env |
| Custom theme | empty (uses embedded theme) | THEME_DIR=themes/<name> |
| Plugins | plugins/ in the working directory | not configurable (hard-coded) |
| Database | data/lesstruct.db (SQLite) | DB_DRIVER, DB_PATH, DB_DSN |
config.toml is loaded once at startup from CONFIG_DIR/CONFIG_FILE. The runtime does not auto-merge or auto-generate anything; the file is read as-is. If the file is missing, the runtime falls back to defaults (one language: English, default post and page post types, default thumbnail at 370 px). Validation errors at startup are reported with a clear message; the server does not start with an invalid config.toml.
Historical note. Early Lesstruct releases shipped a
config.tomlwhose header claimed it was “generated by merging all TOML files inconfig/” — there was never such an auto-merge. The shipped header now states this correctly. If you are upgrading from an old release, you can safely delete any leftoverconfig/merge instructions from yourconfig.toml; editconfig.tomldirectly.
Environment Variables#
All env vars are loaded by internal/config/config.go:Load() and override the corresponding defaults. The runtime also loads a .env file in the working directory via godotenv (env vars in the actual process env take precedence over .env).
Server#
| Variable | Default | Description |
|---|---|---|
HOST | 0.0.0.0 | Bind address for the HTTP server. |
PORT | 8080 | Bind port. Validated to be in [1, 65535]. |
Database#
| Variable | Default | Description |
|---|---|---|
DB_DRIVER | sqlite | One of sqlite, postgres, mysql. |
DB_PATH | data/lesstruct.db | SQLite file path (used when DB_DRIVER=sqlite). |
DB_DSN | empty | Required for postgres and mysql. See per-driver requirements below. |
DB_POOL_MAX_CONNS | 20 | Max connections in the pool (used with postgres and mysql). Must be ≥ 1 when set. |
Per-driver requirements (enforced at startup):
- SQLite — no extra requirements. Just set
DB_PATH(or use the default). - Postgres —
DB_DSNis required. Format:postgres://user:password@host:port/db?sslmode=disable.DB_POOL_MAX_CONNSmust be ≥ 1 if set. - MySQL —
DB_DSNis required. The DSN must containparseTime=trueandmultiStatements=true. Without them, DATE columns scan as[]byteand migrations with multiple statements fail.clientFoundRows=trueis automatically injected if missing — it ensuresRowsAffected()returns the number of rows matched by theWHEREclause rather than rows whose values changed, which prevents spuriouscontent_not_founderrors on no-op updates. Format:user:password@tcp(host:port)/db?parseTime=true&multiStatements=true&charset=utf8mb4&collation=utf8mb4_general_ci.
Storage#
Media files and profile pictures are stored through a single Storage interface (internal/storage/) with two backends: local (default) and s3. The s3 backend works against both AWS S3 and MinIO — they speak the same S3 API, so one driver serves either; the difference is configuration (endpoint + path style), not code.
The driver also decides the shape of stored media URLs: the local backend produces root-relative URLs (/uploads/media/<file>) — they resolve against whatever origin serves the page, so reverse proxies and HTTPS need no extra config — while the s3 backend produces absolute URLs (<STORAGE_S3_PUBLIC_BASE_URL>/<key>). SEO contexts that require absolute values (Open Graph/Twitter images, JSON-LD) are absolutized with SITE_URL.
| Variable | Default | Description |
|---|---|---|
STORAGE_DRIVER | local | One of local, s3. |
STORAGE_S3_ENDPOINT | empty | S3-compatible endpoint URL. Empty = AWS S3 (uses default AWS endpoints). Set for MinIO, e.g. http://localhost:9000. |
STORAGE_S3_REGION | us-east-1 | AWS region; MinIO deployments usually keep us-east-1 (MinIO’s default). |
STORAGE_S3_BUCKET | empty (required for s3) | Bucket holding media and profile pictures. |
STORAGE_S3_ACCESS_KEY_ID | empty (required for s3) | Static access key. |
STORAGE_S3_SECRET_ACCESS_KEY | empty (required for s3) | Static secret key. |
STORAGE_S3_USE_PATH_STYLE | false | true for MinIO (path-style addressing), false for AWS (virtual-host style). |
STORAGE_S3_PUBLIC_BASE_URL | empty (required for s3) | Public base URL served to clients — the bucket’s public URL or a CDN/CloudFront distribution, e.g. https://cdn.example.com. GetURL returns this prefix + object key, so the bucket must be publicly readable (or fronted by a CDN with bucket access). |
Per-driver requirements (enforced at startup):
- Local — files live under
data/uploads/media/anddata/uploads/profile_pictures/, served by the server’s built-in fileserver at/uploads/media/*and/uploads/profile_pictures/*.GetURLreturns root-relative URLs (/uploads/media/<file>). No configuration needed. - S3 —
STORAGE_S3_REGION,STORAGE_S3_BUCKET,STORAGE_S3_ACCESS_KEY_ID,STORAGE_S3_SECRET_ACCESS_KEY, andSTORAGE_S3_PUBLIC_BASE_URLare required. Files are stored under themedia/andprofile_pictures/key prefixes;GetURLreturns absolute URLs (<STORAGE_S3_PUBLIC_BASE_URL>/<key>); the local fileserver is not mounted — clients fetch bytes directly from the public base URL.
Switching drivers after data exists: media_files.file_path/url and the profile picture column store whatever the active backend produced (root-relative URL paths for local, object keys + public URLs for s3). Rows created under one driver are not readable under the other — switching requires a one-time migration that re-uploads the existing files and rewrites the stored paths/URLs (there is no built-in migration tool yet). Rows written by older Lesstruct versions under the local driver contain absolute http://host:port URLs; they keep rendering as-is (both shapes resolve), and new uploads use the relative form.
Authentication#
| Variable | Default | Description |
|---|---|---|
JWT_SECRET | empty (required) | HMAC secret for JWTs. Required. Must be at least 32 characters. |
API_KEY_PEPPER | empty | Pepper prepended to API key secrets before hashing. Adding or changing it invalidates all existing API keys. |
SMTP#
| Variable | Default | Description |
|---|---|---|
SMTP_HOST | empty | SMTP server hostname. When unset, the email-verification and password-reset flows will not work. |
SMTP_PORT | 587 | SMTP port. |
SMTP_USER | empty | SMTP auth username. |
SMTP_PASSWORD | empty | SMTP auth password. |
SMTP_FROM | empty | From: address for outbound emails. |
For local development, Mailtrap or any sandbox SMTP service is a safe choice.
CORS#
| Variable | Default | Description |
|---|---|---|
CORS_ALLOWED_ORIGINS | http://localhost:5173 | Comma-separated list of allowed origins. Each must be a valid http:// or https:// URL with a non-empty host. The default is suitable for local admin dev. |
A typical production value:
| |
Site#
| Variable | Default | Description |
|---|---|---|
SITE_URL | http://localhost:8080 | Canonical public origin of the site. Used for email verification/reset links, SEO metadata (Open Graph/Twitter/JSON-LD image absolutization), the XML sitemap, robots.txt, static-site generation, and author profile links in the public API. Set it to the public https:// origin when running behind a reverse proxy — HOST/PORT only bind the listener and never appear in generated links. |
DEV_MODE | false | When true, the admin panel is served from the Vite dev server (ADMIN_DEV_URL) instead of the embedded build. Same env var enables plugin hot-reload — see the plugin skill. |
ADMIN_DEV_URL | http://localhost:5173 | URL of the Vite dev server (only used when DEV_MODE=true). |
THEME_DIR | empty | Path to a custom theme directory. Empty uses the embedded theme. See the theme skill. |
POSTS_PER_PAGE | 50 | Number of posts per page on public listing pages (homepage, author, tag, and post-type listings). Must be between 1 and 100; 0 falls back to the default. Pagination links (?page=N) appear automatically. |
Rate limits#
| Variable | Default | Description |
|---|---|---|
RATE_LIMIT_ENABLED | true | Master toggle. Set to false to disable all rate limiting (not recommended in production). |
RATE_LIMIT_AUTH_PER_MINUTE | 5 | Per-IP cap on auth endpoints (login, register, forgot-password, reset-password). |
RATE_LIMIT_API_PER_MINUTE | 100 | Per-token cap on authenticated API endpoints. |
RATE_LIMIT_PUBLIC_PER_MINUTE | 60 | Per-IP cap on public endpoints (search, content listing, etc.). |
Imports#
| Variable | Default | Description |
|---|---|---|
IMPORT_MAX_SIZE_MB | 100 | Max upload size (in megabytes) for any importer. Shared by all import types — the WordPress WXR importer and the Hugo archive importer. WordPress exports commonly reach tens or hundreds of MB for real sites, so the default is generous; raise it for very large sites. |
WORDPRESS_IMPORT_TIMEOUT | 2h | Max duration (Go duration string, e.g. 4h, 90m) for a single WordPress import job. Imports run asynchronously in a background goroutine after the HTTP request returns 202 Accepted. Set higher for very large exports with many images. |
HUGO_IMPORT_TIMEOUT | 10m | Max duration (Go duration string, e.g. 10m, 30m) for a single Hugo import job. Imports run asynchronously in a background goroutine after the HTTP request returns 202 Accepted. Set higher for sites with many images to migrate. |
Server timeouts#
| Variable | Default | Description |
|---|---|---|
SERVER_READ_HEADER_TIMEOUT | 15s | Max duration to read request headers (Slowloris protection). Recommended. |
SERVER_READ_TIMEOUT | 0 (off) | Max duration to read the entire request including the body. A zero value means no timeout — per-handler MaxBytesReader / maxBodySizeMiddleware caps body size on each route. Leave at 0 to allow large uploads (WordPress import, media upload). |
SERVER_WRITE_TIMEOUT | 0 (off) | Max duration to write the response after headers have been read. A zero value means no timeout — per-handler context deadlines (e.g. WORDPRESS_IMPORT_TIMEOUT) bound long-running operations. Leave at 0 to avoid interrupting large uploads or slow clients. |
Logging#
| Variable | Default | Description |
|---|---|---|
LOG_LEVEL | info | One of debug, info, warn, error. |
AI image generation (optional)#
When AI_IMAGE_GENERATION_API_KEY is set, the admin panel shows a “Generate with AI” button in the media library and content editor.
Reference images (optional uploads or media-library picks shown as thumbnails in
the generate dialog, up to 3 images of 10 MB each) are supported by the
gemini-* and gpt-image-* models only — the default Imagen models are
text-to-image, so the reference section is hidden when one of them is
configured. Picking a library image as a reference fetches its bytes in the
browser: with the S3 storage driver the bucket must allow cross-origin GET
(Access-Control-Allow-Origin) for this to work.
The “Open Graph image” checkbox generates an exact 1200x630 social preview:
the prompt gains composition guidance and the output is center-cropped and
resized server-side, so it works with every model. Set
AI_IMAGE_GENERATION_ASPECT_RATIO=16:9 to minimize the crop. Generated from
the content editor, the image is inserted at the top of the content —
og:image is always the content’s first image.
| Variable | Default | Description |
|---|---|---|
AI_IMAGE_GENERATION_API_KEY | empty | API key for the image provider. |
AI_IMAGE_GENERATION_MODEL | imagen-4.0-fast-generate-001 | Model name. Examples: imagen-4.0-fast-generate-001, imagen-4.0-ultra-generate-001, gpt-image-1, gpt-image-1-mini, gemini-2.5-flash-image. |
AI_IMAGE_GENERATION_SIZE | empty | Pixel size, e.g. 1024x1024. |
AI_IMAGE_GENERATION_ASPECT_RATIO | empty | Aspect ratio, e.g. 16:9, 1:1, 4:3. |
AI text generation (optional)#
When AI_TEXT_GENERATION_API_KEY is set, the admin panel enables AI text enhancement (TipTap), HTML/CSS generation, and translation for both formats. Works with any OpenAI-compatible API.
| Variable | Default | Description |
|---|---|---|
AI_TEXT_GENERATION_API_KEY | empty | API key for the text provider. |
AI_TEXT_GENERATION_BASE_URL | empty | Override the API base URL. Default is OpenAI’s API. For other providers: https://api.deepseek.com, https://openrouter.ai/api/v1, http://localhost:11434/v1 (Ollama), etc. |
AI_TEXT_GENERATION_MODEL | gpt-5-mini | Chat model name. Examples by provider: OpenAI gpt-5-mini, DeepSeek deepseek-chat, OpenRouter openai/gpt-5-mini, Together meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8, Ollama llama3. |
Admin frontend (Vite)#
The admin SPA (served at /admin/) loads its API base URL from a Vite env var. In production (embedded assets, same origin), the SPA uses a relative base and follows whatever host:port the user opens in the browser — no config needed. Override only for cross-origin dev setups.
| Variable | Default | Description |
|---|---|---|
VITE_API_BASE_URL | '' (same-origin) | Override the backend API URL. Set in web/admin/.env.local (gitignored). Used in dev mode when the Vite dev server and the Go backend run on different ports. Example: http://localhost:8081. |
Duplicate-key gotcha#
.env files are parsed by godotenv, which is a last-value-wins parser. If the same variable appears twice, only the second value is used:
| |
The first line is silently overridden by the empty second line — Lesstruct ends up using the embedded theme. This is a common operator mistake. Check your .env for duplicate keys if a setting appears to have no effect.
config.toml Reference#
config.toml is loaded at startup. If the file is missing, the runtime uses defaults: English only, the built-in post, page, media, and comment post types, default thumbnail at 370 px. If the file is present but invalid, the server fails to start with a validation error.
Top-level keys#
| Key | Type | Default | Description |
|---|---|---|---|
languages | []string | ["en"] | ISO 639-1 language codes. The first is the primary language. Used by the i18n catalog, the admin language switcher, and the content language switcher. Public listings (homepage, sections, tag/author pages, static export) list each translation group once, preferring languages in this order — a post missing from the primary language falls back to the next configured one. |
[site_config] | table | empty | Site-wide identity: name and logo. See below. |
[user_fields] | table | empty | Global user profile fields. Applies to all users. |
[[post_type]] | array of tables | four built-in types | Custom post types, or extensions to built-in types (see below). Add as many as needed. |
[[homepage_section]] | array of tables | empty | Per-post-type groupings rendered on the homepage in addition to the latest-posts list. See below. |
[[public_field]] | array of tables | empty | Allowlist of custom/system fields that may be filtered or sorted on the public query endpoints. See below. |
[csp] | table | empty (default CSP applied) | Content-Security-Policy configuration — per-directive source appends, extra directives, report-only mode, and a full-override escape hatch. See below. |
[[thumbnail]] | array of tables | [{max_width=370, suffix="_thumb"}] | Image processing variants. See below. |
[headless] | table | disabled | Headless-mode toggle. When enabled, the server-rendered content site is not served. See below. |
[comments] | table | enabled | Comment-system toggle. When disabled, the comment system is hard-disabled end to end. See below. |
[[role]] | array of tables | three built-in roles | Custom user roles, or overrides of the built-in roles. See below. |
[registration] | table | follows comments | Self-registration toggle, default role, and admin-approval gate. See below. |
[user_fields]#
| Key | Type | Description |
|---|---|---|
fields | []FieldSchema | User-editable fields shown in the user profile. |
system_fields | []FieldSchema | Read-only fields managed by plugins or operators. |
The schema for each field is the same as post-type fields (below).
[site_config]#
Optional site-wide identity. Two fields, both optional:
| Key | Type | Description |
|---|---|---|
name | string | The site name. Drives the browser-tab title suffix (e.g. My Post - <name>), the og:site_name meta tag, the default logo text, and the footer. When unset, defaults to Lesstruct. |
logo | string | Optional logo image URL or path (e.g. /uploads/logo.png). When set, the default theme renders <img src="…" alt="{name}">; when empty, it renders name as text. |
| |
[site_config] exists because the site name is otherwise baked into the binary’s PageTitle strings (which a THEME_DIR override cannot reach). Everything beyond identity — social links, Google Analytics, site-verification meta tags, footer copyright text, custom <head> injection, image/multi-logo layouts — is a theme concern: override layout.html in your THEME_DIR for those. See docs/theme-development.md.
[[post_type]]#
Each entry defines one custom post type, or extends a built-in one. Four post types are always present: post, page, media, and comment. To add custom fields to a built-in type, reuse its slug — the entry’s fields and system_fields are merged into the built-in type (by slug; an incoming field replaces an existing one of the same slug). When extending, only fields/system_fields are read; name, description, and supports are ignored (and may be omitted), and the built-in’s identity is preserved. To define an entirely new type, use a slug that is not one of the built-ins.
| Key | Type | Required | Description |
|---|---|---|---|
name | string | new types | Display name (e.g. "Product"). 1-200 characters. Ignored when extending a built-in type. |
slug | string | yes | URL slug (e.g. "product"). 1-200 characters. Kebab-case only: lowercase letters, digits, hyphens, underscores. No leading/trailing hyphens, no consecutive hyphens. Reusing a built-in slug (post, page, media, comment) extends that type instead of defining a new one. |
description | string | no | Human-readable description. Shown in the admin panel. Ignored when extending a built-in type. |
supports | []string | new types (non-empty) | Features the post type supports. Each entry must be one of: title, content, tags, featured_image, excerpt. At least one is required for new types. Ignored when extending a built-in type (the built-in’s supports are kept). |
fields | []FieldSchema | no | User-editable custom fields. Merged by slug when extending a built-in type. |
system_fields | []FieldSchema | no | Read-only system fields. Often set by plugins via before_save hooks. Merged by slug when extending a built-in type. |
hidden | bool | no | When true, the post type is hidden from the admin panel and the public post-type list. Allowed only on the post built-in and custom post types — page, media, and comment reject hidden = true (disable the comment system via the [comments] block instead). Hidden types remain valid for content and the registry keeps serving them (e.g. to the API); only the presentation surfaces drop them. |
Field schema (FieldSchema)#
Used in [user_fields].fields, [user_fields].system_fields, [[post_type]].fields, and [[post_type]].system_fields.
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | Display name. 1-200 characters. |
slug | string | yes | Identifier. 1-200 characters, snake_case (regex-enforced). Must be unique within the parent (user fields or a post type). |
type | string | yes | One of text, textarea, number, date, datetime, email, url, select, checkbox. |
required | bool | no | When true, the field must have a value when saving. |
options | []string | for select | The list of allowed values. Required and non-empty for select. |
min | float | for number | Minimum allowed value. |
max | float | for number | Maximum allowed value. |
max_length | int | for text/textarea | Maximum character count. |
Reserved slug
post_script: When a post type declares apost_scriptfield (recommended typetextarea), its raw HTML is emitted verbatim at the end of the post via{{.PostScripts}}— excluded from the visible custom-fields section and stripped from AMP. Declaration is the operator’s opt-in (like Ghost’s per-post code injection): only declare it on types whose editors are fully trusted, and ensure your CSP allows what you emit (externalsrcis'self'-clean; inline needs'unsafe-inline').
[[homepage_section]]#
Each entry tells the public homepage to render a per-post-type grouping (for example, a magazine-style “Latest Articles” or “Upcoming Events” block) in addition to the flat latest-posts list. Sections are opt-in: when no [[homepage_section]] blocks are configured, the homepage renders only the latest-posts list (fully backward compatible).
The latest-posts list and each section are both scoped to the configured languages (in priority order) and the post type at the database level: every translation group appears once, under its best-ranked available language, so a post without a primary-language version is not dropped from the list. Section items use the same PostItem shape as the post grid, and the homepage template exposes them via .Sections (see the theme development guide).
| Key | Type | Required | Description |
|---|---|---|---|
post_type | string | yes | The post-type slug to feature (e.g. "article"). Must match a configured post type. |
limit | int | no | Number of items to show. Defaults to 6. |
offset | int | no | Number of items to skip. Defaults to 0. Use a non-zero offset to avoid duplicating items shown in an earlier section (e.g. a “Recommendations” carousel that starts after the “Featured” section). |
title | string | no | Override the section heading. When omitted, the post type’s display name is used. |
Example:
| |
[[public_field]]#
The public query endpoints (GET /api/v1/public/content_items and GET /api/v1/public/authors) accept cf_<field>, cf_<field>_min, cf_<field>_max, and sort_by=cf:<field> parameters. These are off by default — every such parameter that references a field not declared in a [[public_field]] block is rejected with a 400 field_not_queryable error. This is the fail-closed default; the operator must explicitly opt fields in.
Admin-managed system fields ([[post_type.system_fields]], [user_fields].system_fields) are also queryable via the same cf_* / sort_by=cf:* parameters — they share the same custom_fields JSON column as regular custom fields. A [[public_field]] entry with the system-field slug is all that is needed to expose it on the public API.
The "expose" operation additionally includes the field’s value in the response body. When "expose" is not present (the default), the field’s value is never sent to the client — it can only be used for sorting/filtering queries. Currently only the "user" resource supports the "expose" operation.
Admin endpoints (e.g. GET /api/v1/content_items) are not gated by this allowlist — they remain unrestricted, matching pre-existing behaviour.
| Key | Type | Required | Description |
|---|---|---|---|
resource | string | yes | Either "user" or "content". Selects which public endpoint the entry applies to. |
field | string | yes | The custom-field or system-field slug. Must match ^[a-z][a-z0-9_]*$. |
post_type | string | no | When resource = "content", scopes the entry to one post type. Empty (the default) matches every post type. Ignored (and silently cleared) when resource = "user". |
operations | []string | yes | A non-empty subset of ["sort", "filter", "expose"]. Declares which public query operations are allowed on this field. The "expose" operation includes the field’s value in the response body (currently only "user" resource). |
resource, field, post_type, and operations are matched case-insensitively after normalisation. Duplicate operations in the list are collapsed.
| |
With the configuration above:
GET /api/v1/public/authors?sort_by=cf:points&order=desc→200GET /api/v1/public/authors?sort_by=cf:email→400 field_not_queryableGET /api/v1/public/authors→ response includes"publicFields": {"tier_point": 500}for each author (iftier_pointis not empty)GET /api/v1/public/content_items?post_type=article&cf_views_min=100&sort_by=cf:views→200GET /api/v1/public/content_items?post_type=page&sort_by=cf:views→400 field_not_queryable(theviewsentry is scoped toarticle)
[csp]#
Optional Content-Security-Policy configuration. When the section is absent, Lesstruct applies its built-in default CSP (backward compatible, exactly today’s policy plus https://www.youtube-nocookie.com in frame-src — the privacy-enhanced variant of the already-allowed youtube.com). All fields are optional.
The default CSP (structured as an ordered directive table in the binary) is:
| |
Each _src list appends to the directive’s built-in sources — the policy can only become more permissive; nothing existing is replaced. The exceptions are frame_ancestors (dedicated replace knob for that directive — appending to the default 'none' is meaningless per the CSP spec) and policy (complete override, documented as “advanced” — the operator takes ownership). Use extra_directives to add wholly new directives (e.g. worker-src, report-uri).
| Key | Type | Default | Description |
|---|---|---|---|
disable | bool | false | When true, no CSP header is emitted at all. For operators behind a CDN/WAF that manages CSP. The framing floor still applies: X-Frame-Options keeps following frame_ancestors (default DENY). |
report_only | bool | false | When true, emits Content-Security-Policy-Report-Only instead, for safe rollout testing. |
script_src | []string | [] | Appended to the directive’s default sources. |
style_src | []string | [] | Appended to the directive’s default sources. |
img_src | []string | [] | Appended to the directive’s default sources. |
font_src | []string | [] | Appended to the directive’s default sources. |
connect_src | []string | [] | Appended to the directive’s default sources. |
frame_src | []string | [] | Appended to the directive’s default sources. Also feeds the HTML sanitizer’s iframe allowlist: <iframe> embeds in HTML-format content are only kept when their host appears in frame-src (defaults + appends). A https://*.host entry allows subdomains only — the apex host must be listed separately (e.g. https://disqus.com); a port or path in an entry narrows matching to it. Root-relative src (same-origin embeds) is always allowed; scheme-relative //host srcs are host-checked like absolute URLs. With a policy override the sanitizer follows the override’s frame-src (an override without frame-src keeps iframes stripped); disable/report_only keep the default-based allowlist as a safety net. |
media_src | []string | [] | Appended to the directive’s default sources. |
object_src | []string | [] | Appended to the directive’s default sources. |
worker_src | []string | [] | Appended to the directive’s default sources. |
frame_ancestors | []string | [] | Replaces the default frame-ancestors 'none' (the only directive with replace semantics — appending to 'none' is meaningless). ["'self'"] allows same-origin framing (demo pages, interactive helpers). Also drives X-Frame-Options: no sources → DENY; "['self']" → SAMEORIGIN; a host list (e.g. ["https://embedder.example.com"]) → the header is omitted because X-Frame-Options cannot express host allowlists (the CSP directive is the control then) — except under report_only, where a host list floors to DENY so a rollout trial never silently drops all framing protection. A policy override takes precedence over the knob for this derivation (mirroring the emitted CSP, where the policy replaces everything); 'none' anywhere in the sources maps to DENY; 'self' is matched case-insensitively and duplicates are ignored. Validation rejects entries containing whitespace and lists mixing 'none' with other sources (browsers discard such directives entirely, opening framing up). |
extra_directives | map[string]string | {} | New directives not in the defaults. Key = directive name, value = sources (or empty for flag directives like upgrade-insecure-requests). Note: adding frame-ancestors here creates a duplicate directive, which browsers ignore in favor of the first occurrence (the default 'none') — use frame_ancestors instead. |
policy | string | "" | Complete override. When non-empty, replaces the safe builder. The operator takes full responsibility for the resulting policy. |
Example — allow same-origin framing (embedded demo pages), Google Analytics, data: URI fonts, and the privacy-enhanced YouTube host:
| |
The CSP is built once at startup. Restart the server to pick up changes.
[[thumbnail]]#
Each entry defines one image processing variant. When media is uploaded, Lesstruct generates one file per variant.
| Key | Type | Required | Description |
|---|---|---|---|
max_width | int | yes | Maximum width in pixels. Must be > 0. |
suffix | string | no | Filename suffix. Must be unique. The default thumbnail has suffix _thumb. |
If no [[thumbnail]] entries are defined, the runtime uses a single default variant: max_width = 370, suffix = "_thumb".
[headless]#
Optional. When enabled = true, the instance serves only the admin panel and the REST API — the server-rendered content site is not served at all. This is the configuration for using Lesstruct purely as a headless CMS with a separate frontend.
| |
Effects of headless mode:
- The content-site catch-all (
/*) and/static/*(theme assets) are not mounted; any non-API path returns 404. /admin/*,/api/*, and/uploads/*keep working.sitemap.xmlreturns 404 androbots.txtreturnsDisallow: /(no sitemap reference). The JSON sitemap (GET /api/v1/sitemap) is unaffected — a headless consumer typically reads it from the API.- The admin SPA, SSG export, WordPress/Hugo import, and the agent API all keep working unchanged.
Absent block → headless disabled (the default; fully backward compatible).
[comments]#
Optional. When enabled = false, the comment system is hard-disabled end to end. This is intended for instances that do not want comments at all — most importantly it stops self-registration (see below), which otherwise lets anyone create a Commentator account (a role that only exists for commenting).
| |
Effects of disabling comments:
- All comment routes are unmounted in all three realms: agent/Bearer (
/api/v1/content/{id}/comments), public (/api/v1/public/content_items/{slug}/comments), and browser admin (moderation,/api/v1/my-comments). Requests to them 404. - Without a
[registration]override,POST /api/auth/registerreturns403 REGISTRATION_DISABLED, the/registerpage returns 404, and the login page hides the “create account” link. A[registration]block re-enables all three for the role it names. - Admins can no longer assign the
Commentatorrole when creating users (ErrInvalidRole). - New content always stores
allowComments = false, even if a request explicitly sendsallowComments: true; the admin editor hides the “Allow comments” checkbox. - The admin UI hides the Comments nav item and redirects comment routes.
Absent block (or enabled omitted) → comments enabled (the default; fully backward compatible). The comment post type itself cannot be hidden via hidden = true — use this block instead.
[[role]]#
Optional. Roles gate what a user may do: which post types they can manage (create/edit/delete), whether they can publish content directly, and whether they can upload media and post comments. Three built-in roles always exist:
| Role | Post types | Publish | Media | Comments | Notes |
|---|---|---|---|---|---|
Admin | all | yes | yes | yes | Reserved superuser. Cannot be redefined. |
Contributor | all | yes | yes | yes | The default content author. |
Commentator | none | no | yes | yes | Exists for the comment system. |
A [[role]] entry either overrides a built-in (except Admin) or adds a custom role. Overriding a built-in narrows/widens its capabilities in place; overriding Contributor without an explicit post_types keeps its manage-all-types behavior. A new custom role with no post_types manages no content types.
Override semantics. An override replaces the built-in’s capabilities wholesale: keys you omit (
publish,media,comments,post_types) are reset tofalse/empty. To widen a built-in, spell out every capability you want to keep. (This always fails toward less privilege — it can never silently grant more.)
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | Role name stored in users.role. 1-200 characters. Admin is reserved and rejected. |
post_types | []string | no | Post-type slugs the role may manage (own-content CRUD). Each must reference a post type defined in this file — a typo fails closed at startup. |
publish | bool | no | When true, the role may publish content directly; otherwise content is saved as a draft (admins publish). |
media | bool | no | When true, the role may upload and generate media. |
comments | bool | no | When true, the role may post comments. |
Example — a journalist who manages only article content, publishes directly, and comments, but cannot touch media:
| |
Effects:
GET /api/v1/post_types(admin) returns only the role’s manageable types; the admin sidebar, content list tabs, and editor type select follow suit.- Creating/editing/deleting content of a type the role does not manage returns
403 forbidden(ErrForbiddenPostType). - Publishing without the
publishcapability is rejected (ErrForbiddenPublish); a non-publishing role’s new content is forced to draft. - The admin content editor hides the Publish button and the Published status option for roles without the
publishcapability (the button stays visible for admins). The Unpublish action remains available (see below), and editing an item that is already published keeps its current status selectable. - Media endpoints return
403for roles withoutmedia; comment endpoints return403for roles withoutcomments. - Admins can assign any registered role in the user management UI (the dropdown is populated from
GET /api/v1/roles).
Note: a non-publishing role may still set its own published content back to draft (unpublish) — the publish capability gates draft→published only. It cannot re-publish; that requires the publish capability or an admin.
Absent block → only the three built-in roles (the default; fully backward compatible).
[registration]#
Optional. Decouples self-registration from the comment system. Historically registration was enabled iff comments were enabled, because the only self-registerable role — Commentator — was meaningless without them. With custom [[role]] entries a site may want public registration for a different role (e.g. a journalist), so this block overrides the coupling.
| Key | Type | Default | Description |
|---|---|---|---|
enabled | bool | follows [comments] | When set, overrides the comment-system coupling. true = registration allowed (the /register page renders and the login page shows the “create account” link), false = POST /api/auth/register returns 403 REGISTRATION_DISABLED and /register 404s. |
default_role | string | "Commentator" | Role assigned to new registrants. Must be a registered role (built-in or [[role]]) and cannot be an admin role — a typo or an Admin default fails closed at startup. |
admin_approval | bool | false | When true, email verification is required before an admin can activate a registrant: approving a user whose email is still unverified fails with 409 EMAIL_NOT_VERIFIED. When false (default), admins may approve pending registrants regardless of email verification (legacy behavior). |
Email verification is always mandatory: every registrant must click the link in the verification email before the account can become active. The admin_approval flag only decides when verification happens relative to activation:
admin_approval | Verify-email link result | Activation path |
|---|---|---|
false (default) | Marks the email verified and activates the account (verified) | Email link alone is enough |
true | Marks the email verified; account stays pending with the message “Email verified. An administrator will activate your account.” | Admin approval in the registration queue is the only path from pending to active |
Example — public registration for a journalist role, with email verification plus admin approval, comments disabled site-wide:
| |
Absent block → registration enabled iff comments are enabled, default role Commentator, pending until approved (the default; fully backward compatible).
Validation Rules#
These are enforced at startup by the runtime. Violations cause the server to fail to start with a clear error.
Post type rules#
namemust be 1-200 characters (internal/domain/posttype/types.go:93-99).slugmust be 1-200 characters, contain only lowercase letters, digits, hyphens, and underscores; cannot start or end with a hyphen; cannot contain consecutive hyphens (types.go:102-126).supportsmust be non-empty and each entry must be one of:title,content,tags,featured_image,excerpt(types.go:26-32,129-146).- Duplicate post-type slugs are rejected for new types (
types.go:20). Reusing a built-in slug (post,page,media,comment) is not a duplicate — it extends the built-in type by mergingfields/system_fields(service.go:Register).
Field rules#
namemust be 1-200 characters (internal/domain/customfield/types.go:98-104).slugmust be 1-200 characters and match the snake-case regex (types.go:106-115).typemust be one of:text,textarea,number,date,datetime,email,url,select,checkbox(types.go:35-44,118-123).selectfields must have a non-emptyoptionslist (types.go:125-128).numberfields can haveminandmax;textandtextareafields can havemax_length. Other combinations are rejected (types.go:141-159).- Duplicate field slugs within the same parent (user fields or a single post type) are rejected (
types.go:90-93).
File rules#
CONFIG_FILEmust not contain path separators or..(internal/config/posttypes.go:19-21).- The config directory must exist and be readable; the file is optional (defaults apply if missing).
Role rules#
namemust be 1-200 characters (internal/domain/role/types.go:43-48).Adminis reserved and cannot be redefined (ErrAdminRoleReserved).- A duplicate
nameis rejected for new roles (ErrDuplicateRole); reusing a built-in name overrides it instead. - Every
post_typesentry must reference a registered post type — a typo fails closed at startup (internal/config/roles.go:62-67). - A role entry cannot declare
all_types(that flag is internal and derived).
Worked Examples#
Example A — Minimal blog#
A personal blog with one language and the default post types. config.toml only sets the language; everything else falls back to defaults.
| |
That’s it. You can omit [[thumbnail]] entirely (the runtime uses the default 370 px _thumb variant). No custom post types, no custom user fields, no custom themes, no plugins.
For a more useful starting point, add a [[thumbnail]] for medium-sized previews:
| |
Example B — Multilingual site (English + Indonesian)#
A two-language site with a custom user profile (system fields for gamification, regular fields for bio/links).
| |
The runtime falls back to the default post and page post types (in both languages) for the content schema. Users can write posts and pages; the i18n switcher in the layout lets visitors pick English or Indonesian.
Example C — Shop with custom post types#
A two-post-type content schema: product for a storefront and portfolio for a work showcase. Both have realistic field combinations.
| |
Pair this with a .env that enables the AI integrations, e.g.:
| |
Example D — Role-scoped journalism site with open registration#
A magazine where registered readers can write articles, a small editorial team publishes them, and media stays admin-only. Registration is decoupled from the comment system and auto-verified.
| |
With this config: new registrants become Journalist (articles only, drafts, comments allowed, no media); editors publish articles/pages; the built-in Admin keeps the full surface including media and user management.
What is NOT Configurable from config.toml#
config.toml and the env vars cover deployment and content schema, but several other surfaces are configured elsewhere:
| Surface | How to configure | Reference |
|---|---|---|
| Public site theme (CSS, JS, HTML templates) | THEME_DIR=themes/<name> env var → a themes/<name>/ directory | skills/lesstruct-theme-development/ |
| WASM plugins (custom hooks, external API calls) | <name>.wasm and <name>.manifest in plugins/ | skills/lesstruct-plugin-development/ |
| Admin panel branding (logo, colors, copy) | Edit web/admin/ source and rebuild | make build-admin |
| API response shapes | Edit internal/api/handlers/ | source only |
| CLI flags | lesstruct-cli --help | built-in |
Plugins and themes are loaded at startup and hot-reloaded only when DEV_MODE=true is set (and even then, only the plugin watcher is recursive; the theme is not). Admin and API changes always require a rebuild / redeploy.
Upgrading Lesstruct#
When you bump the Lesstruct version (via go install github.com/aristorinjuang/lesstruct@<version> or a new release tarball):
- Back up your
config.tomland.env. New versions may add fields that your old config doesn’t have; the runtime applies sensible defaults for any field that is missing. - Diff the new
config.toml.exampleand.env.exampleagainst your files. Lesstruct’s release notes call out new env vars; copy them into your.envonly if you need the feature. - Validate before starting. Start the server with the new binary. If
config.tomlhas a new validation rule (e.g. a new field type), the runtime reports it at startup. Fix and retry. - New field types or supported features are documented here. If you see a new entry in the Validation Rules section, your existing
config.tomlwill keep working; only new post types you add will need to use the new field types. - Theme and plugin skills ship independently of the runtime. After a runtime upgrade, re-run the theme and plugin skills to compare your
themes/<name>/andplugins/<name>.wasmagainst any new defaults.
Troubleshooting#
JWT_SECRET is required at startup#
You didn’t set JWT_SECRET in .env (or it’s empty). It must be present and at least 32 characters:
| |
unsupported DB_DRIVER "X"#
DB_DRIVER must be sqlite, postgres, or mysql. The runtime rejects other values at startup.
DB_DSN must contain parseTime=true (MySQL)#
The MySQL DSN is missing the parseTime=true query parameter. Without it, DATE columns scan as []byte. Add it to the DSN:
| |
DB_DSN must contain multiStatements=true (MySQL)#
Same fix as above — the multiStatements=true parameter is required for golang-migrate to run migrations with multiple SQL statements.
post type slug "X" is invalid#
X violates the slug rules: it must be kebab-case, lowercase letters/digits/hyphens/underscores only, no leading/trailing hyphens, no consecutive hyphens (--). Examples:
- ✓
product,team-member,case_study - ✗
Product(uppercase),-product(leading hyphen),team--member(consecutive hyphens),team.member(period not allowed)
field "x": duplicate slug#
Two fields in the same parent (user fields, or a single post type) have the same slug. Slugs must be unique within a parent.
field type must be one of: text, textarea, number, date, datetime, email, url, select, checkbox#
Typo in the type field, or a new field type that this version of Lesstruct doesn’t support. Check the Field schema table for the current list.
select field requires non-empty options#
A select field has no options = [...] list. Add at least one option.
CONFIG_FILE must not contain path separators#
You tried to set CONFIG_FILE to a path like config/shop.toml. The runtime only supports a flat filename in CONFIG_DIR; subdirectories are not allowed.
Theme changes are not taking effect#
Cross-reference the lesstruct-theme-development skill. Common causes: THEME_DIR is empty, points to a missing directory, or the server was not restarted after the last change.
Plugin hooks are not firing#
Cross-reference the lesstruct-plugin-development skill. The currently-invoked hooks are before_save (create, update, and admin system-fields updates), after_create, after_publish, before_delete, and after_unpublish. on_plugin_loaded is defined but not invoked today.
Env var appears to have no effect (.env)#
Check for duplicate keys in .env. The godotenv parser uses last-value-wins, so a later THEME_DIR= line silently overrides an earlier THEME_DIR=themes/dark-warm.
Quick Reference#
All env vars (with defaults)#
| |
All config.toml keys#
| |
All field types#
| Type | Required sub-keys | Optional sub-keys |
|---|---|---|
text | name, slug, type | required, max_length |
textarea | name, slug, type | required, max_length |
number | name, slug, type | required, min, max |
date | name, slug, type | required |
datetime | name, slug, type | required |
email | name, slug, type | required |
url | name, slug, type | required |
select | name, slug, type, options (non-empty) | required |
checkbox | name, slug, type | required |
All supported supports values#
title, content, tags, featured_image, excerpt.