samanbayaka 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,97 +1,159 @@
1
- # samanbayaka
1
+ <p align="center" style="margin: 0;">
2
+ <img style="background-color: #000; border-radius: 30%;" src="https://unpkg.com/samanbayaka/public/favicon.svg" width="256" />
3
+ </p>
2
4
 
3
- ##check environment variable before start the server
4
- $echo $SBK_CONFIG_PATH
5
- $echo export SBK_PORT=87xx for gateway services
5
+ # samanbayaka
6
6
 
7
+ This project is a modular, production-ready microservices framework built with Moleculer and Moleculer-Web latest, using NATS as a high-performance messaging transporter and AJV for robust schema validation. It provides a scalable foundation for developing distributed Node.js applications, emphasizing fault tolerance, clean architecture, and efficient service communication. The system is designed to support flexible orchestration of services while maintaining strong validation and reliability across components.
7
8
 
9
+ [![NPM version](https://img.shields.io/npm/v/samanbayaka.svg)](https://www.npmjs.com/package/samanbayaka)
10
+ [![License](https://img.shields.io/npm/l/samanbayaka.svg)](LICENSE)
8
11
 
9
- ## Getting started
12
+ # Features
10
13
 
11
- To make it easy for you to get started with GitLab, here's a list of recommended next steps.
14
+ - Moleculer-based microservices architecture
15
+ - NATS transporter for high-performance messaging
16
+ - Redpanda transporter for persistent,robust and scalability.
17
+ - In memory L1 cache and Redis cache for L2
18
+ - Schema validation using AJV
19
+ - Dynamic service loading (Gateway / Feature / Demo)
20
+ - Graceful shutdown handling (SIGINT, SIGTERM)
21
+ - Centralized error handling middleware
22
+ - REPL support for debugging
23
+ - Config-driven initialization
24
+ - Metrics and Log shipping for Grafana
12
25
 
13
- Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
14
26
 
15
- ## Add your files
16
27
 
17
- - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
18
- - [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
28
+ # Installation
19
29
 
30
+ ```bash
31
+ pnpm install samanbayaka
20
32
  ```
21
- cd existing_repo
22
- git remote add origin https://gitlab.com/dalal.suvendu/samanbayaka.git
23
- git branch -M main
24
- git push -uf origin main
33
+ # Prerequisites
34
+ It is assumed that NATS, Redpanda, and Redis are installed and properly configured. All services should be discoverable through the /etc/hosts file.
35
+ #### Minimum required Node.js version: >= 22.x.x
36
+ ```bash
37
+ node -v
38
+ nvm use 22
25
39
  ```
26
40
 
27
- ## Integrate with your tools
28
-
29
- - [ ] [Set up project integrations](https://gitlab.com/dalal.suvendu/samanbayaka/-/settings/integrations)
30
-
31
- ## Collaborate with your team
32
-
33
- - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
34
- - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
35
- - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
36
- - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
37
- - [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
38
-
39
- ## Test and Deploy
40
-
41
- Use the built-in continuous integration in GitLab.
42
-
43
- - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
44
- - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
45
- - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
46
- - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
47
- - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
48
-
49
- ***
50
-
51
- # Editing this README
52
-
53
- When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
54
-
55
- ## Suggestions for a good README
56
-
57
- Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
58
-
59
- ## Name
60
- Choose a self-explaining name for your project.
61
-
62
- ## Description
63
- Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
64
-
65
- ## Badges
66
- On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
41
+ #### Environment variables
42
+ To configure all required environment variables, copy the <your_project_name>/bash/sbk.sh file into the /etc/profile.d/ directory and update the environment variable values as needed. Before copying, ensure that your current working directory is the project directory.
43
+ ```bash
44
+ pwd
45
+ sudo cp bash/sbk.sh /etc/profile.d/
46
+ source /etc/profile.d/sbk.sh
47
+ ```
48
+ Optionally, you may verify the set environment variables.
49
+ ```bash
50
+ echo $SBK_PORT
51
+ ```
52
+ #### Configuration files
53
+ Create a directory to store the configuration files, then copy all configuration files from the current project path into this directory and update them as needed. Before copying, ensure that your current working directory is the project directory.
54
+ ```bash
55
+ pwd
56
+ sudo mkdir -p /usr/local/etc/<your_project_name>
57
+ sudo cp config/*.*  /usr/local/etc/<your_project_name>
58
+ ```
67
59
 
68
- ## Visuals
69
- Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
70
60
 
71
- ## Installation
72
- Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
61
+ # Usage
62
+ #### Create a service, gateway
63
+ The gateway is an important service that exposes all endpoints as REST APIs. At least one Gateway service is mandatory in the project.
64
+ ```bash
65
+ mkdir gateway
66
+ cd gateway
67
+ npm init -y
68
+ pnpm install samanbayaka
69
+ touch index.mjs
70
+ ```
73
71
 
74
- ## Usage
75
- Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
72
+ Open and edit the index.mjs file as follows
73
+ ```bash
74
+ import sbk from "samanbayaka"
75
+ await sbk.loadGatewayService()
76
+ ```
77
+ Run the service, gateway
78
+ ```bash
79
+ node index.mjs
80
+ ```
76
81
 
77
- ## Support
78
- Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
79
82
 
80
- ## Roadmap
81
- If you have ideas for releases in the future, it is a good idea to list them in the README.
83
+ #### Create your endpoints as a feature service, such as a test service
84
+ ```bash
85
+ mkdir test
86
+ cd test
87
+ npm init -y
88
+ pnpm install samanbayaka
89
+ touch index.mjs
90
+ ```
82
91
 
83
- ## Contributing
84
- State if you are open to contributions and what your requirements are for accepting them.
92
+ Open and edit the index.mjs file as follows
93
+ ```bash
94
+ import sbk from "samanbayaka"
95
+ await sbk.loadFeatureService.mainBus({
96
+ name: "test",
97
+ version: "v1",
98
+
99
+ actions: {
100
+ hello: {
101
+ rest: {
102
+ method: "GET",
103
+ path: "/hello"
104
+ },
105
+
106
+ /**
107
+ * Enable caching to this action
108
+ */
109
+ cache: {
110
+
111
+ /**
112
+ * These cache entries will be expired after 5 seconds instead of 30.
113
+ */
114
+ ttl: 2*60
115
+ },
116
+ handler(ctx){
117
+ return "Hello Samanbayaka"
118
+ }
119
+ },
120
+ welcome: {
121
+ rest: "GET /welcome",
122
+ handler(ctx) {
123
+ return `Welcome, ${ctx.params.query?.name || "Guest"} - ${ctx.broker.nodeID}`
124
+ }
125
+ },
126
+ createUser
127
+ },
128
+ })
85
129
 
86
- For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
130
+ ```
131
+ Run the service, test
132
+ ```bash
133
+ node index.mjs
134
+ ```
135
+ # Demo
136
+ You can also run the demo service to better understand how the system works.
137
+ ```bash
138
+ mkdir demo
139
+ cd demo
140
+ npm init -y
141
+ pnpm install samanbayaka
142
+ touch demo.mjs
143
+ ```
144
+ Open and edit the demo.mjs file as follows
145
+ ```bash
146
+ import sbk from "samanbayaka"
147
+ await sbk.loadDemo()
148
+ ```
149
+ Run the service, demo
150
+ ```bash
151
+ node demo.mjs
152
+ ```
87
153
 
88
- You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
89
154
 
90
- ## Authors and acknowledgment
91
- Show your appreciation to those who have contributed to the project.
92
155
 
93
- ## License
94
- For open source projects, say how it is licensed.
95
156
 
96
- ## Project status
97
- If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
157
+ <p align="center" style="margin-top: 100px;">
158
+ <img src="https://moleculer.services/images/banner.png" alt="Moleculer Logo" width="600">
159
+ </p>
package/bash/sbk.sh CHANGED
@@ -5,7 +5,10 @@
5
5
  ###############################################################################
6
6
 
7
7
  ##Configurations files path
8
- $export SBK_CONFIG_PATH="/usr/local/etc/your_folder"
8
+ export SBK_CONFIG_PATH="/usr/local/etc/your_folder"
9
9
 
10
10
  ##web server port 8760-8769
11
- $export SBK_PORT=8765
11
+ export SBK_PORT=8765
12
+
13
+ ##
14
+ export SBK_LOG_LEVEL=info
package/commit-hash.mjs CHANGED
@@ -1 +1 @@
1
- export const COMMIT_HASH = 'd6d0b66';
1
+ export const COMMIT_HASH = '95e0f1a';
package/config/broker.mjs CHANGED
@@ -156,4 +156,6 @@ export default Object.freeze({
156
156
  metadata: {
157
157
  // region: "eu-west1"
158
158
  },
159
+
160
+ logLevel: "trace",
159
161
  })
package/config/logger.mjs CHANGED
@@ -1,35 +1,35 @@
1
1
  /*logger.mjs*/
2
2
  export default Object.freeze({
3
- type: "Console",
3
+ type: "Pino",
4
4
  options: {
5
5
  /**
6
6
  * Logging level
7
7
  */
8
8
  level: "info",
9
9
 
10
- /**
11
- * Using colors on the output
12
- */
13
- colors: true,
10
+ // /**
11
+ // * Using colors on the output
12
+ // */
13
+ // colors: true,
14
14
 
15
- /**
16
- * Print module names with different colors (like docker-compose for containers)
17
- */
18
- moduleColors: true,
15
+ // /**
16
+ // * Print module names with different colors (like docker-compose for containers)
17
+ // */
18
+ // moduleColors: true,
19
19
 
20
- /**
21
- * Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
22
- */
23
- formatter: "full",
20
+ // /**
21
+ // * Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
22
+ // */
23
+ // formatter: "full",
24
24
 
25
- /**
26
- * Custom object printer. If not defined, it uses the `util.inspect` method.
27
- */
28
- objectPrinter: null,
25
+ // /**
26
+ // * Custom object printer. If not defined, it uses the `util.inspect` method.
27
+ // */
28
+ // objectPrinter: null,
29
29
 
30
- /**
31
- * Auto-padding the module name in order to messages begin at the same column.
32
- */
33
- autoPadding: false
30
+ // /**
31
+ // * Auto-padding the module name in order to messages begin at the same column.
32
+ // */
33
+ // autoPadding: false
34
34
  }
35
35
  })