Giter VIP home page Giter VIP logo

Comments (1)

mindactuate avatar mindactuate commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.