Comments (1)
Hi together, just a short update. I currently try to use the following concept:
my-system
|─ services (components, modules)
| |-- config-service
| | |-- entry-points
| | | |-- validators # here I validate for example the request body (using zod) and convert to JS objects
| | | |-- config-code-server.ts # provides a simple object with methods from "the inner world" of the service
| | | |-- config-http-routes.ts # my http routes that are registered with my fastify HTTP server
| | |-- data-access
| | | |-- validators # some of the columns in my Postgres are json type, I use validators (zod) to convert to JS objects
| | | |-- config-db.ts # my DB calls using Prisma
| | |-- business-logic (domain)
| | | |-- get-config-use-case.ts # here I do something with the config from DB and return it to the entry point
| |-- another-service
| | |-- entry-points
| | | |-- validators
| | | |-- another-code-server.ts
| | | |-- another-http-routes.ts
| | |-- data-access
| | | |-- another-db.ts
| | |-- business-logic (domain)
| | | |-- clients
| | | | |-- validators
| | | | |-- config-client.ts # imports config-code-server and provides functions to the "inner world" of another service
| | | | |-- google-maps-client.ts
| | | |-- another-use-case.ts
| |
Here an example for my config-code-server.ts
:
import {
getActiveConfig,
getAllConfigs
} from '../business-logic/get-config-use-case';
export {
getActiveConfig,
getAllConfigs
};
And here my config-client.ts
:
import { Config } from '@prisma/client';
import * as configCodeServer from '../../../config-service/entry-points/config-code-server';
export async function getActiveConfig(): Promise<Config> {
const config = await configCodeServer.getActiveConfig();
return config;
}
export async function getAllConfigs(): Promise<Config[]> {
const configs = await configCodeServer.getAllConfigs();
return configs;
}
I can also write my code server a little more abstract like this:
import { Config } from '@prisma/client';
import {
getActiveConfig,
getAllConfigs
} from '../business-logic/get-config-use-case';
export async function getActiveConfig(): Promise<Config> {
const config = await getActiveConfig();
return config;
}
export async function getAllConfigs(): Promise<Config[]> {
const configs = await getAllConfigs();
return configs;
}
config-code-server.ts and config-client.ts look quite similar leading to redundancy (don't repeat yourself?!). But all in all it would be the same or perhaps even worse with microservices.
I can use the client within another-service like this
import * as ConfigClient from '../config-client'
async function anotherFunc(){
//...
const config = await ConfigClient.getActiveConfig();
//...
}
How do you find this approach? I saw other approaches with messages being published to an (in memory or external) event bus. You can find information to this here: kamilgrzybek.com/blog/posts/modular-monolith-integration-styles I tried to implement the "direct call" approach.
Here is also a great video on that topic. Modular Monolith - How to build one & lessons learned, from Milan Jovanovic
from nodebestpractices.
Related Issues (20)
- Easy to translate advice HOT 1
- Translations status HOT 1
- Bonnes pratiques nodejs
- Arabic Translation
- Node practice 1
- Should include Corepack in our recommendation? HOT 5
- Bootstraping nodejs container may be misleading
- Node
- Node js fullstack HOT 4
- Wrong example HOT 2
- Broken link to env-var
- Nextjs as main framework? HOT 2
- Italian Translation
- The backend-testing-checklist.png file is missing. HOT 3
- Hinglish Translation HOT 1
- Кнас
- Dead link for safe-regex
- Mi006
- Is using cache for npm install in docker safe?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodebestpractices.