- π Table of Contents
- π Overview
- π¦ Features
- π Repository Structure
- βοΈ Modules
- π Getting Started
- π£ Roadmap
- π€ Contributing
- π License
- 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
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 |
Please ensure you have the following dependencies installed on your system:
- βΉοΈ NodeJS >=18 (tested)
- install package from npm.
npm install microfields
- 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;
npm start
npm test
βΉοΈ Prisma Service
βΉοΈ Caching in Redis
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
orbugfix-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.