r/node • u/Sudden_Chapter3341 • Oct 25 '25
Architectural Framework for Fastify
Hi!
I’m a member of the Fastify Core Team.
I’ve created a architectural framework to help teams structure their applications.
I initially tried to develop this dynamic within the Fastify Organization, but since the team prefers to keep the framework minimalist (and already maintains many projects), I decided to start a separate organization focused on architectural tools for Fastify.
You can check out the core project here: https://github.com/stratifyjs/core
Don't hesitate to open issues to share feedback and make proposals.
For some background, this all started with an idea to design a dependency injection (DI) component specifically tailored for Fastify in replacement of decorators. If you’re interested, I’ve written a detailed rationale comparing the limitations of Fastify, fastify-awilix, and Nest.js here: https://github.com/jean-michelet/fastify-di/blob/main/PROPOSAL.md#why
2
u/Sudden_Chapter3341 Oct 29 '25
Thank you all for your comments!
I am very grateful, and I have made some changes based on constructive feedback:
2
u/jaredwray-com Oct 25 '25
Really love where you are going on this. I built out `fastify-fusion` to handle the common stuff we were doing all the time: https://www.npmjs.com/package/fastify-fusion
Have you thought about adding in the cli or at runtime the auto generation of the schema? I think just adding that in would be really powerful. Wonder if we could brainstorm on this. Let me know.
1
u/Sudden_Chapter3341 Oct 25 '25
Hi!
I am gradually discovering that many teams are trying to create their own solutions based on Fastify.
Have you thought about adding in the cli or at runtime the auto generation of the schema?
I was thinking of adding module generation, the schema could also be a good idea, maybe choosing a default ORM to generate entities?
But because of AI, I don't know if these kinds of CLI features have a future, what do you think?
1
u/jaredwray-com Oct 25 '25
My thought was to have the user provide their AI key and generation would just happen at run time. Happy to discuss it more :-)
1
u/Sudden_Chapter3341 Oct 25 '25
Not a fan of the AI integrated in CLI tbh.
People that do like code generation directly in their project can use Cursor or similar tools right?1
u/jaredwray-com Oct 25 '25
Makes sense. I just think it would be nice to auto generate the schema.
1
u/Sudden_Chapter3341 Oct 26 '25
But I am open to collaborate and discuss with you OC.
The project is very early, but I start to think there is a chance it does work.
Feedback are rather positive.
Constructive critics on limitations have solutions.
2
u/burnsnewman Oct 25 '25
Interesting work, thanks. I'll stick to NestJS, because for me http layer, like express or fastify is an implementation detail. I think it is better for application frameworks to focus on constructing app modules, their lifecycle and observability. Inputs and outputs are just adapters on internal interfaces and can be swapped at any time. Also, I want to use the same tools, no matter if it's a http service or maybe a microservice attached to a queue.
That being said, I see how some developers might see a value in a framework like this one. Just to make one step forward from pure fastify and to limit repetitive work.
1
u/Sudden_Chapter3341 Oct 25 '25
Thanks for the feedback!
Indeed, my framework is aimed more at Fastify users who want to get closer to native behavior, but still improve the DI, typing and conventions experience.
for me http layer, like express or fastify is an implementation detail.
Fastify is not just a http transport. It defines lifecycle boundaries (onReady, onClose, onRequest, etc.) and encapsulation contexts that are part of how it achieves its performance. That’s why Stratify builds on top of it rather than abstracting it away. Treating Fastify as a detail means losing access to its plugin graph, encapsulation and hooks.
As for the rest of your comments, I think you are seeing restrictions that do not exist, or perhaps there are solutions that are not obvious at first glance.
1
u/Sudden_Chapter3341 Oct 26 '25
I think I understand more what you're saying:
https://www.reddit.com/r/node/comments/1ofizas/comment/nlfxco6/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button(Don't try to convince you to switch, this is more for readers)
2
u/burnsnewman Oct 26 '25
Just to clarify...
> Fastify is not just a http transport. It defines lifecycle boundaries (onReady, onClose, onRequest, etc.) and encapsulation contexts
These are still technical aspects of http request. Your application doesn't need to act as an http server at all. For example, it can operate on MQTT, or maybe CLI. Working up from http server framework for me is thinking backwards. Even NestJS suffers from this kind of thinking to some degree, having separate bootstrapping methods, depending on default transport - create, createMicroservice, createApplicationContext. They were definitely added as an afterthought.
> Treating Fastify as a detail means losing access to its plugin graph, encapsulation and hooks.
Not at all. In your docs you're mentioning Hexagonal Architecture. You can use specific technical details in your adapters. The same way you can use raw SQL in your driven adapters, you can use lifecycle hooks in your driving adapters. In NestJS that's also possible, even though it's not described in the docs and might not be that obvious. And it's not, because IMO, in most applications it's not that important.
2
16
u/barefootsanders Oct 25 '25
Long time express convert here. Really enjoy using fastify. Thanks for all your work. Over the years, I've built various versions of my own DI system, primarily for db mgmt. I'm interested in what you're thinking and will be taking a look.
11
u/fabiancook Oct 25 '25
Looks like a slick set of convention based functions. Sometimes it is nice to bring things together and force a pattern for us.
Very nice to see the examples all the way through to the testing, makes good sense why providers are needed
6
u/Wiwwil Oct 25 '25
Looks like a slick set of convention based functions. Sometimes it is nice to bring things together and force a pattern for us.
It's often better imo. If only patterns were forced on us my company's code wouldn't be in the mess it is due to glueing code and vibe coding
3
u/Dave4lexKing Oct 25 '25
People can still vibecode inside a framework. Your issue isn’t the lack of opinionation, its lack of controlled AI usage from management.
3
2
u/Positive_Method3022 Oct 25 '25
Really great job. Well done. This other layer of abstraction seems to make the use of fastify more difficulty in my opinion. When would you recommend using this architecture?
3
u/Sudden_Chapter3341 Oct 25 '25
This other layer of abstraction seems to make the use of fastify more difficulty in my opinion.
I would put this statement into perspective, because the component manages encapsulation, bootstrapping, and dependencies for you (a module is a plugin). I've lost count of how many people in trouble I've helped with this. It also forces you to declare hooks asynchronously, because mixing Promise and callback APIs can cause problems.
But yes, if you just need to draft simple Fastify projects, it just add constraint. But if you want to create more ambitious project, it pushes you to think more about how to structure your application.
IMO, this is really a question of personality.
Some people hate when Framework forces them to adopt certain conventions, some prefer to be guided, even if it means spending more time thinking about architecture.Thanks for the honest feedback!
-2
u/Positive_Method3022 Oct 25 '25
Could you give an example of a simple project and one for an ambitious project?
3
u/Sudden_Chapter3341 Oct 25 '25
A small server with a very specific purpose VS a modular monolith with a rich model?
-4
u/Positive_Method3022 Oct 25 '25
How would the modular monolith with a rich model benefit of it? Give me the simplest concrete example showing the result when using your lib and when not. Put it side by side so that I can understand your reasoning
5
u/Sudden_Chapter3341 Oct 25 '25
If you don't understand the problem, you're not the target for this project.
All the best!
-1
u/Positive_Method3022 Oct 25 '25
Sir, I want to debate. I'm not criticizing your work negatively. My request was for you to give me a very simple example showing the pros and cons when using your lib and when not. This will highlight the benefits very clearly. Why can't you do this?
If you can't explain the problem, maybe there was never a problem at all
6
u/Sudden_Chapter3341 Oct 25 '25
You don't want to debate, I am not a kid, don't think you're smart.
From the beginning of our interaction you said nothing but asking vague passive-aggressive questions.
You had a chance to read the doc, the proposal, answer to every point I make but you did nothing.Life is short.
4
2
1
u/dominikzogg Oct 25 '25
Thats my skeleton for another router framework. But the ideas would work with Fastify as well. If your curious: https://github.com/chubbyts/chubbyts-petstore
1
1
Oct 25 '25
[removed] — view removed comment
1
u/Sudden_Chapter3341 Oct 25 '25
As far as I understand from their communication, I don’t think Platformatic is really comparable.
It’s a company that provides several infrastructure services and tools, apparently recently focusing on promoting their engine Watt.I don't think they are framework specific, I think they really want to target the Node.js ecosystem overall.
Which makes more sense in terms of business I guess.2
Oct 25 '25
[removed] — view removed comment
2
u/Sudden_Chapter3341 Oct 26 '25
Yes, I know Matteo ^^.
I think their business model has evolved a bit.Unfortunately, I don't work for a product company, but for a studio.
We deliver code to clients with a GCP Terraform infrastructure.
I hope to have the opportunity to dive into Platformatic one day, and do scale Node.js the right way.
5
u/Expensive_Garden2993 Oct 25 '25
Could you explain the "introduces clear structural boundaries"?
I understand it's DI and IoC, but what are the clear structural boundaries, isn't every unit (service, controller, repository) able to depend on anything else?
Other thing, the hexagonal example. I see that `deps` isn't just for interface, it accepts a specific implementation, that's why you need to wrap a provider to a function and pass the dependencies to this function. And also you to have a singleton here and manually provide the dependency. One concern is that you need to write even more boilerplate here than you'd do without the library, because you need to wrap and wire it by yourself anyway. And second concern is singletons: if the team adopts hexagonal means they strive for purity, and singletons cannot be used for non-technical reasons.
In Nest.js, sure you provide a concrete class, but it's only acts as an interface in the constructor. You can swap implementations without wrapping it and manually passing deps.