Microfields is a lightweight TypeScript microservice library designed to simplify the development of microservices. It provides essential tools and utilities for building scalable and maintainable microservices, allowing you to focus on your business logic.
- Project Name: Microfields
- License: MIT License
- Contributors: gimbledev
- Language: TypeScript
- Libraries: amqplib (for RabbitMQ), Bunyan, Prisma (optional)
- TypeScript Ready: Microfields is written in TypeScript and provides strong typing out of the box for a better developer experience.
- RabbitMQ Integration: Seamlessly integrate with RabbitMQ using the
amqplib library, enabling asynchronous communication between microservices.
- Logging: Microfields comes with the Bunyan logger preconfigured to help you track and debug your microservices easily.
- Prisma Support (Optional): If needed, you can use the Prisma ORM for database operations. Microfields offers optional support for Prisma.
Microfields
Service
Decorators
Connections
Redis
Rabbitmq
| ConnectionPriority.ts | Priority holder of Connection |
| ConnectionManager.ts | Registry of Connections |
| Connection.ts | Connection Interface |
Redis (Under Construction π§)
RabbitMQ
Logger
| LoggerConnector.ts | Connector for Logger (Bunyan) |
Prisma
Loader
| PrismaClientLoader.ts | Loader of Prisma Client |
Please ensure you have the following dependencies installed on your system:
- βΉοΈ NodeJS >=18 (tested)
- install package from npm.
- Create your first microservice:
// index.ts
import { PrismaClient } from "@prisma/client";
import { Microfields, PrismaConnector, RabbitMQConnector } from "microfields";
const m = new Microfields();
const db = new PrismaClient();
m.addConnection(new RabbitMQConnector()).addConnection(new PrismaConnector({client: db,}));
await m.start();
- Create your first service!
// services/example/index.ts
import { ServiceBase, Service } from "microfields";
@Service({ port: 3981, name: "my_service" })
class MyService extends ServiceBase implements RabbitMQService, RedisService {
redis!: Redis;
mq!: Connection;
channel!: Channel;
async init() {
// your code...
}
}
export default MyService;
- Create your first router!
// routes/example.route.ts
import { Router, Route, RouteData } from "microfields";
import { z } from "zod";
import { MyService } from "..";
@Router({
id: "example_router",
path: "example", // URL, /example
body: z.object({ // π« Zod Validation
username: z.string(),
email: z.string(),
password: z.string()
})
)}
class ExampleRouter extends Route<MyService> {
async action(data: RouteData) { // TRIGGERS POST METHOD
// your backend codes...
return {
message: "Hello World!",
};
}
async loader(data: RouteData) { // TRIGGERS GET METHOD
// your backend codes...
return {
message: "Hello World!",
};
}
}
export default ExampleRouter;
Contributions are always welcome! Please follow these steps:
- Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
- Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
- Create a new branch with a descriptive name (e.g.,
new-feature-branch or bugfix-issue-123).
git checkout -b new-feature-branch
- Make changes to the project's codebase.
- Commit your changes to your local branch with a clear commit message that explains the changes you've made.
git commit -m 'Implemented new feature.'
- Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
- Create a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary.
The project maintainers will review your changes and provide feedback or merge them into the main branch.
This project is licensed under the MIT License. See the MIT file for additional info.