r/typescript • u/acefolio_dev • 18h ago
How do you keep feature modules from reaching into each other's internals in a backend?
In most backends I've worked on, "modules" are just folders. Nothing stops billing from importing a repository straight out of users, and after a while every feature quietly depends on every other feature's internals.
I'm trying a different approach in Elpod, a small framework I'm building on top of Elysia. It runs on Bun rather than Node, but the problem is the same. Each feature is a plain value that says what it owns and what it exposes:
```ts
export const users = pod({
name: "users",
prefix: "/users",
controller: UsersController,
providers: [UsersService, UsersRepository],
exports: [UsersService],
});
export const billing = pod({
name: "billing",
prefix: "/billing",
controller: BillingController,
imports: [users],
providers: [BillingService],
});
```
And a class lists what it needs as a static tuple, no decorators:
```ts
export class BillingService {
static readonly needs = [UsersService] as const;
constructor(private readonly users: UsersService) {}
}
```
Only what users exports is visible to billing, so UsersRepository stays private. Import cycles between features and duplicate exports fail when the app composes, not later. These are in-process boundaries though, not security boundaries, so authorization still lives in the services.
For those of you with bigger Node services: do you enforce this kind of thing at all? dependency-cruiser, eslint-plugin-boundaries, Nx module boundaries, or just code review? I'm curious whether doing it at the DI level feels useful or like extra ceremony.
It's alpha (0.1.x), so the API can still change. Docs if you want to look: https://elpod.vercel.app/docs/features-and-pods/