Skip to content
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

refactor: improve global architecture #54

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Turn0xx
Copy link
Contributor

@Turn0xx Turn0xx commented Nov 8, 2024

#52

@Turn0xx
Copy link
Contributor Author

Turn0xx commented Nov 8, 2024

This PR introduces a modular architecture, organized by functional domains.
Each modules encapsulate its own declarations / definitions.

This is the actual structure that i'm going to follow:

modules
├── accounts
│   ├── index.route.ts
├── auth
│   ├── auth.service.ts
│   ├── controllers
│   │   ├── index.ts
│   │   └── login.controller.ts
│   ├── index.route.ts
└── tasks
       ├── index.route.ts

Each module is going to have

  • A bunch of controllers (generally one controller per route), who consumes services through the fastify instance.
  • One or more services, implemented as plugins.
  • Route file that serve as the api entry points

Wdyt on this approach ?

… the module (index.route)

- This allows autoload to work correctly (i guess), as it depends on the
parent directory name. Also, we'll only have one route file, so the
directory isn't needed.
Copy link

sonarcloud bot commented Nov 8, 2024

@jean-michelet
Copy link
Contributor

jean-michelet commented Nov 8, 2024

I think having a controllers directory is a bit too much for now.
We can start by creating services to reduce controllers logic and we'll see if we need a controllers dir later.
But you can create a services dir.

@Turn0xx
Copy link
Contributor Author

Turn0xx commented Nov 8, 2024

@jean-michelet You mean to much for the auth module or for all modules ? yeah for auth module just an index file would do the work. However i think for other modules like tasks, we can create multiple controller files per action area.

@jean-michelet
Copy link
Contributor

Are you sure it will not break ts inference? One file by controller function is too much I think.

@Turn0xx
Copy link
Contributor Author

Turn0xx commented Nov 8, 2024

Are you sure it will not break ts inference?

What do you mean by ts inference ?

One file by controller function is too much I think.

It's not really one file by controller function but one file by action area.
But for this demo you are right there is not really a lot of actions area per module so i'm going to make just 1 file.

And the same thing for services i think.

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.

2 participants