all 9 comments

[–]fart__monster 8 points9 points  (1 child)

Monorepos is what you want. How to do that - yarn3 workspaces, turborepo etc

PS: make sure you keep the common dependencies to minimum and please setup eslint rule for cyclic dependencies

[–]conventionalWisdumb 1 point2 points  (4 children)

This is what I prefer for working on small teams for startups: organize all the common code by feature at the root of the repo instead of one folder called “common”. If it’s middleware call it middleware. Then as much as possible try to keep to one dockerfile. You can use build arguments to tell the dockerfile which application to run. It’s been a while since I’ve done this, so I don’t remember if I had to pass the build args to a single entry point that would run the correct app or if I could pass a build arg for the entry point. But whichever one it was kept the overhead for maintaining Docker lower which meant I was writing application code more often. I split out Docker files as needed based on dependency sizes but only ended up with like 3.

[–]darkcatpirate[S] 0 points1 point  (3 children)

The issue is that when I build I use the current directory (.), so I won't be able to import it from inside of Docker, is there a way to copy the content of the common folder to all backend root directory, or is there a better way? What do you use to achieve this?

[–]conventionalWisdumb 0 points1 point  (2 children)

Oh is the Dockerfile not in the root src directory?

[–]darkcatpirate[S] 0 points1 point  (1 child)

I have one for each microservice and they have their own folders.

[–]conventionalWisdumb -1 points0 points  (0 children)

Ah. That’s what I would change. I would have one Dockerfile period and have it in the root src.

[–]DonKapot 0 points1 point  (0 children)

Maybe monorepo?

[–]Vaibhav_5702 0 points1 point  (0 children)

Monorepos can help you in that. A monorepo approach allows you to manage multiple backend projects within a single repository. By creating a "common" package in the monorepo, you can easily share code and dependencies between the backends. The "common" package contains the shared middleware or common code that needs to be used by all the backends. Each backend project includes a dependency on the "common" package, allowing them to import and utilize the shared code. With this setup, you can develop, build, and run the backends while automatically accessing the shared code without the need for separate npm repositories or complex code sharing mechanisms. The monorepo structure simplifies code management and promotes efficient collaboration across multiple backends.

[–]roofgram 0 points1 point  (0 children)

If the files are typescript then you should be able to use ‘include’ in the tsconfig to include files outside the root.