twenty/packages/twenty-server
Charles Bochet eab8deb211
Rework messaging modules (#5710)
In this PR, I'm refactoring the messaging module into smaller pieces
that have **ONE** responsibility: import messages, clean messages,
handle message participant creation, instead of having ~30 modules (1
per service, jobs, cron, ...). This is mandatory to start introducing
drivers (gmails, office365, ...) IMO. It is too difficult to enforce
common interfaces as we have too many interfaces (30 modules...). All
modules should not be exposed

Right now, we have services that are almost functions:
do-that-and-this.service.ts / do-that-and-this.module.ts
I believe we should have something more organized at a high level and it
does not matter that much if we have a bit of code duplicates.

Note that the proposal is not fully implemented in the current PR that
has only focused on messaging folder (biggest part)

Here is the high level proposal:
- connected-account: token-refresher
- blocklist
- messaging: message-importer, message-cleaner, message-participants,
... (right now I'm keeping a big messaging-common but this will
disappear see below)
- calendar: calendar-importer, calendar-cleaner, ...

Consequences:
1) It's OK to re-implement several times some things. Example:
- error handling in connected-account, messaging, and calendar instead
of trying to unify. They are actually different error handling. The only
things that might be in common is the GmailError => CommonError parsing
and I'm not even sure it makes a lot of sense as these 3 apis might have
different format actually
- auto-creation. Calendar and Messaging could actually have different
rules

2) **We should not have circular dependencies:** 
- I believe this was the reason why we had so many modules, to be able
to cherry pick the one we wanted to avoid circular deps. This is not the
right approach IMO, we need architect the whole messaging by defining
high level blocks that won't have circular dependencies by design. If we
encounter one, we should rethink and break the block in a way that makes
sense.
- ex: connected-account.resolver is not in the same module as
token-refresher. ==> connected-account.resolver => message-importer (as
we trigger full sync job when we connect an account) => token-refresher
(as we refresh token on message import).

connected-account.resolver and token-refresher both in connected-account
folder but should be in different modules. Otherwise it's a circular
dependency. It does not mean that we should create 1 module per service
as it was done before

In a nutshell: The code needs to be thought in term of reponsibilities
and in a way that enforce high level interfaces (and avoid circular
dependencies)

Bonus: As you can see, this code is also removing a lot of code because
of the removal of many .module.ts (also because I'm removing the sync
scripts v2 feature flag end removing old code)
Bonus: I have prefixed services name with Messaging to improve dev xp.
GmailErrorHandler could be different between MessagingGmailErrorHandler
and CalendarGmailErrorHandler for instance
2024-06-03 11:16:05 +02:00
..
@types Compile with swc on twenty-server (#4863) 2024-04-14 09:09:51 +02:00
patches Fix yoga patch user id cache (#5285) 2024-05-03 18:47:31 +02:00
scripts Uniformize datasources (#5196) 2024-04-27 11:43:44 +02:00
src Rework messaging modules (#5710) 2024-06-03 11:16:05 +02:00
test chore: use Nx affected tasks in CI (#5110) 2024-04-30 16:28:25 +02:00
.env.example fix: user has to login every time chrome sidepanel is opened (#5544) 2024-05-30 12:58:45 +02:00
.env.test File token chores (#4664) 2024-03-26 13:42:09 +01:00
.eslintrc.cjs fix: fix storybook:build memory allocation error in CI (#5284) 2024-05-03 19:19:21 +02:00
.gitignore feat: workspace:health nullable fix (#3882) 2024-02-08 18:22:29 +01:00
.prettierignore Migrate to a monorepo structure (#2909) 2023-12-10 18:10:54 +01:00
.prettierrc Migrate to a monorepo structure (#2909) 2023-12-10 18:10:54 +01:00
.swcrc Compile with swc on twenty-server (#4863) 2024-04-14 09:09:51 +02:00
jest.config.ts 4840 multi workspace update user userworkspace inconsistent on delete set null constraint (#5373) 2024-05-13 14:50:27 +02:00
nest-cli.json chore: use Nx affected tasks in CI (#5110) 2024-04-30 16:28:25 +02:00
package.json Bump to version v0.12.1 (#5608) 2024-05-27 16:07:38 +02:00
project.json Feat/migrate password reset token to app token table (#5051) 2024-05-06 15:30:03 +02:00
tsconfig.build.json chore: set up twenty-emails config so build isn't needed in development (#3619) 2024-01-29 06:17:12 -03:00
tsconfig.json 4586 fix workspace member feature (#4680) 2024-03-28 17:59:48 +01:00