Everything Is A Module
In Trongate v2, everything is a module. Every piece of built-in functionality - database handling, form rendering, file uploads, image manipulation, template rendering, validation, even helper functions - lives inside a dedicated module.
This isn't just philosophy. It's the architecture of the framework.
What Is a Module?
A module is a folder. That's it.
Each module lives inside modules/ and contains a controller file with the same name as the folder. Some modules add a model file (Some_module_model.php) and a views/ directory. But the bare minimum is a folder and a controller.
Here's the db module - the one that powers all database interactions:
That's it. One folder. One file. Yet it handles every query, every transaction, every table operation you'll ever need.
What "Everything" Actually Means
Open the modules/ directory in any Trongate v2 installation and you'll see:
| Module | What It Does |
|---|---|
db | Database connections, queries, CRUD operations |
file | File upload, move, copy, delete, directory management |
flashdata | One-time session messages |
form | All form helper functions |
image | Image resize, crop, rotate, upload configuration |
language | Multilingual support, language file loading |
pagination | Page navigation for result sets |
string_service | String manipulation helpers (truncate, split, filter) |
templates | Admin and public page rendering with layout support |
login | Universal login for any user table |
trongate_administrators | Admin panel (create, edit, delete users) |
trongate_email | Send emails via SMTP |
trongate_control | Module management and SQL import |
trongate_security | Permission checking, method-level access control |
trongate_tokens | API token generation, validation, lifecycle |
url | URL generation, redirects, anchor tags |
utilities | Block URL access, CORS handling, segment helper |
validation | Form validation, error display, CSRF protection |
welcome | Default landing page |
Every one of these is a module. Every one follows the same pattern: folder → controller → done.
How Helpers Became Modules
In earlier versions of Trongate, helper functions lived inside engine/tg_helpers/ as full function definitions that were loaded on every request. That worked, but it meant PHP had to parse hundreds of lines of helper code even when you only needed truncate_str() once.
Today, those helper files are thin routing wrappers. Each function simply forwards the call to its corresponding module via Modules::run():
The real logic lives in the string_service module. The helper file is just a map. The result?
- Engine size: ~ approximately 1,200 lines of core PHP across the entire framework
- Bootstrap overhead: Near zero - helpers parse as lightweight function stubs
- Module logic: Loaded only when called, not on every request
What This Means for You
As a developer, nothing changes. You still call truncate_str(), current_url(), $this->db->get() - exactly as before.
But under the hood, the framework is leaner than ever. The engine/ directory - the beating heart of Trongate - now contains only four PHP files totalling roughly 1,200 lines. Everything else is a module, loaded lazily, invoked only when needed.
Your application code doesn't feel any of this. It just runs faster.
Takeaway: A module is a folder. A folder is a module. Database? Module. Templates? Module. Helper functions? Modules. The entire framework is just folders and controllers, glued together with Native PHP. That's the whole trick.
We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.
Share your thoughts in the Documentation Feedback.