Skip to content

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.

Notifications You must be signed in to change notification settings

microfields/core

Repository files navigation


microfields

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.

JavaScript TypeScript Prisma Fastify

GitHub top language GitHub code size in bytes GitHub commit activity GitHub license

πŸ“– Table of Contents

πŸ“ Overview

  • Project Name: Microfields
  • License: MIT License
  • Contributors: gimbledev
  • Language: TypeScript
  • Libraries: amqplib (for RabbitMQ), Bunyan, Prisma (optional)

πŸ“¦ Features

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

βš™οΈ Modules

Microfields
File Summary
index.ts including library exports.
MicrofieldProps.ts Properties of Microfield
Microfields.ts Main class for Library
Service
File Summary
ServiceBase.ts Base Interface for Services
IServiceBaseProps.ts Properties for ServiceBase
ServiceGateway.ts Gateway for Messaging (RabbitMQ)
ServiceLoader.ts Loader Class for Services
ServiceManager.ts Service Registry
ServiceMetadata.ts Service Metadata, its holding your service
decorator data (name, port etc.)
Decorators
File Summary
ServiceDecorator.ts @Service Decorator, it holds port, name etc.
Router.ts @Router Decorator, it holds your router properties
(url, id, params, body, query etc.)
RouterMetadata.ts it holds decorator data.
Connections
File Summary
ConnectionPriority.ts HTTPStatus Exception: 401
ConnectionManager.ts HTTPStatus Exception: 401
Connection.ts HTTPStatus Exception: 401
Redis
File Summary
RedisConnector.ts HTTPStatus Exception: 401
RedisService.ts HTTPStatus Exception: 401
RedisCacheProvider.ts HTTPStatus Exception: 401
PrismaRedisExtension.ts HTTPStatus Exception: 401
Rabbitmq
File Summary
RabbitMQConnector.ts HTTPStatus Exception: 401
RabbitMQService.ts HTTPStatus Exception: 401

| ConnectionPriority.ts | Priority holder of Connection | | ConnectionManager.ts | Registry of Connections | | Connection.ts | Connection Interface |

Redis (Under Construction 🚧)
File Summary
RedisConnector.ts Connector of Redis
RedisService.ts Provider of Redis
RedisCacheProvider.ts Cache provider of Redis
PrismaRedisExtension.ts Extension for Prisma
RabbitMQ
File Summary
RabbitMQConnector.ts RabbitMQ Connector, it connects your service to RabbitMQ.
RabbitMQService.ts RabbitMQ Service Interface
Logger
File Summary
LoggerConnector.ts HTTPStatus Exception: 401

| LoggerConnector.ts | Connector for Logger (Bunyan) |

Prisma
File Summary
PrismaServiceProps.ts HTTPStatus Exception: 401
PrismaConnector.ts HTTPStatus Exception: 401
PrismaService.ts HTTPStatus Exception: 401
PrismaServiceProps.ts Properties of Prisma Service
PrismaConnector.ts Connector of Prisma, it connects your service to Prisma ORM.
PrismaService.ts Prisma Service Interface
Loader
File Summary
PrismaClientLoader.ts HTTPStatus Exception: 401

| PrismaClientLoader.ts | Loader of Prisma Client |


πŸš€ Getting Started

πŸ“¦ Dependencies

Please ensure you have the following dependencies installed on your system: - ℹ️ NodeJS >=18 (tested)

πŸ”§ Installation

  1. install package from npm.
npm install microfields

  1. 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();

  1. 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;

  1. 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;

πŸ€– Running microfields

npm start

πŸ§ͺ Tests

npm test

πŸ›£ Roadmap

  • ℹ️ Prisma Service
  • ℹ️ Caching in Redis

🀝 Contributing

Contributions are always welcome! Please follow these steps:

  1. Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
  2. Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
  3. Create a new branch with a descriptive name (e.g., new-feature-branch or bugfix-issue-123).
git checkout -b new-feature-branch
  1. Make changes to the project's codebase.
  2. 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.'
  1. Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
  1. 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.

πŸ“„ License

This project is licensed under the MIT License. See the MIT file for additional info.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published