System with microservice architecture may have heterogeneous technology stacks and different programming languages, therefore it will be very helpful if the services are developed with popular, standarized and transferable knowledge that developers can apply to various technology.
- Dependency Injection: for decoupling and unit testing. Dependencies in MicroFleet are automatically resolved.
- Remote procedure call (RPC): Very crucial for service communication. You will love our RPC utilities.
- Object-relation mapping (ORM): Optional, but if you need, we have it.
- Model auto mapping: Our utility class can help you avoid boilerplate when translating DTO model <=> Domain model <=> ORM model.
- Repository pattern: We provide a repository class with common CRUD operations (count, create, findById, page, delete etc.), all of them support atomic transaction.
- Domain-driven design: MicroFleet is not strictly opinionate, you can use and patterns (MVC, Anemic, Domain-driven design...)
MicroFleet doesn't enforce any architecture design, here are just some examples:
A lot of you may be familiar with this architecture, especially those who are new to microservice. In this architecture, all services are RESTful, accepting requests from clients or other services, and communicating with one another via HTTP calls.
Another popular architecture, here we have REST services accepting clients' requests and passing them to message queue / message broker. Internal domain services pick queued requests to process then send reponses back to message broker for the caller REST service to receive and respond to client.
Notice that we also have direct communication between services, in addition to mediate communication via message broker.
For the sake of brevity, we don't mention any more architectures here. We believe you can implement any architecture with MicroFleet. Should you bump into any problems, don't forget our issue page.
Building various architectures with similar code interfaces.
Regardless you are developing RESTful service, domain service, or batch processing, monitoring, logging service... MicroFleet keeps the way you code mostly the same. Let's have a look:
import { inject } from '@micro-fleet/common'
import { decorators as d } from '@micro-fleet/web'
@d.controller('accounts')
export default class AccountController {
@d.GET('/:id')
public details() {
// Make RPC request via broker topic "request.accounts.getDetails"
return // Returned value to client-side
}
}This controller listens to mediate RPC requests, and at the same time it also accepts direct RPC requests.
import { inject } from '@micro-fleet/common'
import { decorators as d } from '@micro-fleet/service-communication'
@d.mediateController('accounts')
@d.directController('accounts')
export default class AccountController {
@d.action('getDetails')
public details() {
// Does heavy-duty task here
// Returns value to RPC caller via broker topic "response.accounts.getDetails"
return 'Account details'
}
}This controller listens to mediate RPC communication among other services for monitoring / logging purpose.
import { inject } from '@micro-fleet/common'
import { decorators as d } from '@micro-fleet/service-communication'
@d.mediateController('accounts')
export default class MonitorController {
@d.action({ rawDest: 'request.accounts.*' })
public monitor() {
// Receives all requests related to "accounts"
}
}Firstly, grabbing some concepts will be helpfull before you jump to code.
Micro Fleet is written in TypeScript, but you can develop with native JavaScript. Our [cookbook] will offer both TypeScript and JavaScript version.
To start developing, these commands need executing:
- Install global dependencies:
npm i -g- or
yarn global add lerna
- Install dependencies:
- Make sure you have
cdto the workspace root. lerna bootstrap
- Make sure you have
In case you want to start a new monorepo like this one. This project structure is inspired from lerna-yarn-workspaces-example but added some customizations:
- Use
independentmode of lerna - The major task runner is NPM, with
scriptssection inpackage.json, as inspired from how-to-use-npm-as-a-build-tool

