Skip to content

Refactorisation #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 14, 2025
Merged

Refactorisation #93

merged 19 commits into from
Apr 14, 2025

Conversation

jean-michelet
Copy link
Member

Goals of this PR

Encapsulate more logic into utility plugins

Our controllers are currently handling too many responsibilities: database queries, file uploads, and more. IMO, they should focus only on handling HTTP concerns. I made some improvements in this direction, but there's still work to be done. I believe introducing a service layer or a set of use-cases would help to achieve this separation.

Better logging

I think relying on the reply.internalServerError() utility from @fastify/sensible is not very useful, and we were essentially blind to the actual reasons why transactions were failing (credits to @fraxken). If we don't implement fine-grained logging, it's better to let errors propagate naturally. The default error handler already does a good job of adding context to thrown errors.

Hotfixes

I also took the opportunity to address #38 by implementing the temporary file approach recommended by @climba03003 here.

Future improvements

  • Encapsulate business logic into dedicated plugins (service objects or use-case decorators). Controllers would no longer handle file management or direct repository calls.
  • Improve the folder structure to better reflect which plugins belong to infrastructure, application, shared utilities, or business logic.
  • Reduce the use of module augmentation by using getDecorator<T> api on next minor, see feat: allow to access decorators fastify#5768

@jean-michelet jean-michelet requested review from delvedor, climba03003, Fdawgs and gurgunday and removed request for delvedor March 30, 2025 10:35
@jean-michelet jean-michelet mentioned this pull request Mar 30, 2025
2 tasks
@jean-michelet
Copy link
Member Author

@fastify/collaborators
Can an additional contributor take a look plz?

Copy link

sonarqubecloud bot commented Apr 8, 2025

@jean-michelet jean-michelet merged commit 1d430da into fastify:main Apr 14, 2025
5 checks passed
@jean-michelet jean-michelet deleted the refactorisation branch April 14, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants