One of my projects started as PHP but recently some of the new functionality has been written in JavaScript on Node.js platform.

How do big polyglot projects that use multiple languages to write their server components organize their code?

One of the need arises when doing that is to have models and services written in multiple languages. This leads us to:

/models
  /php
  /js
  /ruby
/lib
  /php
  /js
  /ruby

Alternatively we could put implementations written in different languages into the same folder and only differentiate them by the file extension.

/models
  user.php
  user.js
  role.rb
/lib
  auth.php
  service.js
  anotherService.rb

What are some common patterns to deal with this?

有帮助吗?

解决方案

It may be the right time to introduce packages. It seems that the project has become complex enough to separate different functionality into independent packages. So the structure might look like this:

/package-1  # (Ruby)
  /models
    file.rb
  /lib
    some-file.rb
/package-2  # (Node)
  /models
    ...
  /lib
    ...
/package-3  # (Node)
  /models
    ...
  /lib
    ...

Having structure like this opens up the possibility of updating code from each package independently, having clean APIs between them, then maybe even some independent versioning of each. Before you know it, you're gonna run full-blown Microservices architecture :-)

Of course every situation is different, but this pattern is very common for large services.

许可以下: CC-BY-SA归因
scroll top