How it works
Core has no router and no framework. Each address is one PHP file. If you can read public/login.php, you can read everything.
The folders
vanillasaas-core/
├── public/ the only folder a browser can reach
│ ├── *.php one file per page
│ └── assets/ one stylesheet, one optional script
├── app/
│ ├── bootstrap.php loaded first by every page
│ ├── config.php all settings
│ ├── custom.php your own functions
│ ├── lib/ Core's functions, one file per concern
│ └── views/ templates and layouts
├── database/ the schema and run-once migrations
├── storage/ SQLite file, logs, sessions
└── bin/ the installer
Only /public is served. The code, the database and the logs sit beside it, where a browser can't ask for them. That one decision removes the most common way small apps leak: a database file or config file that downloads when someone guesses its address.
The four steps of every page
Every file in /public has the same shape. This is public/dashboard.php, shortened:
require __DIR__ . '/../app/bootstrap.php'; // 1. bootstrap
allow_methods('GET');
$user = require_auth(); // 2. guard
// 3. handle POST (this page has none)
view('pages/dashboard', [ // 4. render
'title' => 'Dashboard',
'user' => $user,
]);
- Bootstrap loads the config, error handling, security headers, the session and Core's functions.
- Guard decides who may see the page.
require_auth()is for signed-in users,require_guest()for signed-out ones. It runs on the server before any HTML exists, so a guest receives a redirect and none of the page. - Handle POST when a form was submitted: check the form token, read the fields, validate, write to the database, redirect.
- Render hands data to a template in
app/views/.
A page that fails validation skips the redirect and renders the form again with the error messages.
Your files and Core's files
Once you build on Core, nothing updates your copy automatically. A fix reaches your app when you apply it. That is only painless if your code and Core's code live in different files.
| Yours: edit freely | Core's: leave alone |
|---|---|
public/ (pages, CSS, JavaScript) | app/lib/ |
app/views/ (templates, layouts) | app/bootstrap.php |
app/config.php, app/config.local.php | bin/install.php |
app/custom.php, your own scripts in bin/ | database/schema.*.sql |
database/migrations/*/app-*.sql | database/migrations/*/core-*.sql |
Almost every bug and security fix lands in app/lib/. If you never edit that folder, applying a fix means replacing a file. If you do, every update becomes a manual merge, and the usual outcome is that the fix never gets applied.
When you need Core to behave differently, change a setting in app/config.php, or write your own function in app/custom.php and call that instead.
The helpers you'll use most
| Function | What it does |
|---|---|
e($value) | Escapes text for HTML. Every echoed value goes through it. |
input('field') | Reads a submitted form field as a trimmed string. |
db_one(), db_all(), db_run() | Run a query with ? placeholders. |
auth_user(), auth_id() | The signed-in user, or their id. |
csrf_field(), csrf_verify() | The form token: one in the form, one in the handler. |
flash('success', '...') | A message shown once on the next page. |
redirect('page.php') | Send the browser elsewhere and stop. |
view('pages/name', [...]) | Render a template inside the layout. |
abort(404) | Stop with an error page. |
Three rules that keep it secure
- Every value echoed into HTML goes through
e(). - Every SQL value goes through a
?placeholder. Never build SQL by joining strings. - Every
<form method="post">contains<?= csrf_field() ?>, and every POST handler callscsrf_verify().
And one that keeps the Content-Security-Policy working: no inline <script>, no onclick=, no style="". JavaScript goes in public/assets/js/ and styles in app.css. The browser refuses inline code by design.