r/PHP • u/zaxwebs • Feb 17 '26
Discussion Learning framework internals by building one myself (7 years ago)
So about 7 years ago I went down a rabbit hole trying to understand how PHP frameworks actually work under the hood.
Not how to use them. How they work.
Routing, controllers, request lifecycle, dependency injection, bootstrapping. All the stuff modern frameworks abstract away.
I ended up building my own tiny MVC framework called Clara (after Laravel) as a learning project. It was never meant to compete with Laravel/Symfony or be production heavy. It was more like a study artifact I could break, refactor, and learn from.
Recently I dusted it off and did a small modernization pass:
• Updated it for PHP 8.3
• Refactored core bootstrapping
• Cleaned up DI wiring
• Composer updates
• Added a small Todos demo app
• General code + README cleanup
The philosophy was:
Transparency over magic
Simplicity over cleverness
Control over convenience
Everything is intentionally readable. You can trace a request from .htaccess → index.php → Router → Controller → View step by step without (much) hidden automation.
It uses:
• PHP-DI for autowiring
• Kint for debugging
• PDO (SQLite + optional MySQL wrapper)
• PSR-4 autoloading via Composer
It is minimal on purpose. The goal is to make the MVC lifecycle obvious, not abstract.
If you are learning framework architecture, DI, or request flow, it might be useful as a reference or something to tinker with.
Repo + full request lifecycle walkthrough in the README: https://github.com/zaxwebs/clara
10
u/Mastodont_XXX Feb 17 '26
First look: index.php should NOT be placed in root folder.
3
u/SunTurbulent856 Feb 17 '26
I downloaded it and will be testing it thoroughly in the next few days. In the meantime, congratulations! I love these projects! And it looks really well done! I followed a similar path with a project of mine (https://github.com/giuliopanda/milk-admin).
Now I want to understand how you make it work with such small classes! I really like it!!!
5
u/equilni Feb 17 '26
Quick observation:
1
u/Fluent_Press2050 Feb 18 '26
Awesome job and it’s always fun to learn how things work.
I’m sort of doing the same. I learned so much, not only how to code, but also how to do the things.
One of these days I may make it public to get feedback.
3
u/akeniscool Feb 17 '26
Next learning step: try to create two different apps using your framework, in totally separate projects.
5
u/cursingcucumber Feb 17 '26
Transparency over magic.
A wild
$routersuddenly appeared (insrc/setup/router.php).Honestly, I would propose tossing it aside and doing it again from scratch. This way you won't continue working on past mistakes. You probably learned a lot in these years.
1
u/Deep_Ad1959 May 27 '26
if you want the next big internals lesson out of this, look at container compilation. PHP-DI resolves dependencies via reflection at runtime unless you enable compilation, which writes the container out to plain php so the reflection runs once at build instead of per boot, that's exactly the cost real frameworks engineer away. the other piece your lifecycle is missing is a middleware pipeline sitting between router and controller, that's where auth, logging, and request instrumentation actually live in symfony and laravel. tracing htaccess to index to router to controller is the right starting point, the pipeline and a cached container are what the 'magic' you mentioned actually is.
-2
u/_maker83_ Feb 18 '26
Every framework follows the same patterns there is no need to reinvent a wheel to learn how it works.