@sentzunhat/zacatl 0.0.0-alpha.7 → 0.0.0-alpha.9
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,40 +1,120 @@
|
|
|
1
1
|
# zacatl
|
|
2
2
|
|
|
3
|
-
blazing fast minimal straightforward
|
|
3
|
+
A blazing fast, minimal, and straightforward microservice framework for Node.js, designed for rapid development of high-performance APIs and distributed systems.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Project Description
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**zacatl** (published as `@sentzunhat/zacatl`) is a TypeScript-first microservice library that enables you to bootstrap robust, scalable services with minimal configuration. Built on top of Fastify and Mongoose, it provides a modular architecture for defining application logic, infrastructure, and service orchestration, while supporting advanced features like dependency injection, localization, and flexible error handling.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Features
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- **Fastify-based HTTP server**: Ultra-fast routing and extensibility.
|
|
12
|
+
- **Mongoose integration**: Easy MongoDB data modeling and repository pattern.
|
|
13
|
+
- **Modular architecture**: Clean separation of application, domain, infrastructure, and platform layers.
|
|
14
|
+
- **Dependency injection**: Powered by `tsyringe` for testability and flexibility.
|
|
15
|
+
- **Gateway support**: Proxy requests to upstream services with minimal setup.
|
|
16
|
+
- **Internationalization (i18n)**: Built-in support for multiple locales.
|
|
17
|
+
- **Comprehensive error handling**: Custom error classes and route error utilities.
|
|
18
|
+
- **Type-safe route and hook handlers**: Strongly-typed REST entry points using Zod and Fastify.
|
|
19
|
+
- **Testing utilities**: Vitest configuration and helpers for fast, isolated unit tests.
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
## Architecture Overview
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
The framework is organized into the following layers:
|
|
24
|
+
|
|
25
|
+
- **Application**: Defines REST entry points (routes and hooks) and configures i18n.
|
|
26
|
+
- **Domain**: Registers business logic providers.
|
|
27
|
+
- **Infrastructure**: Manages repositories and external dependencies.
|
|
28
|
+
- **Platform**: Orchestrates service startup, database connections, and server/gateway configuration.
|
|
29
|
+
|
|
30
|
+
Each layer is extensible and testable, supporting clean code and maintainability.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bun install
|
|
36
|
+
# or
|
|
37
|
+
npm install @sentzunhat/zacatl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Here's how to quickly spin up a microservice:
|
|
16
43
|
|
|
17
44
|
```ts
|
|
18
45
|
import Fastify from "fastify";
|
|
19
|
-
import { MicroService } from "@sentzunhat/
|
|
46
|
+
import { MicroService } from "@sentzunhat/zacatl";
|
|
20
47
|
|
|
21
|
-
const fastifyApp = Fastify(
|
|
48
|
+
const fastifyApp = Fastify();
|
|
22
49
|
|
|
23
50
|
const microServer = new MicroService({
|
|
24
|
-
|
|
51
|
+
architecture: {
|
|
52
|
+
application: {
|
|
53
|
+
entryPoints: {
|
|
54
|
+
rest: {
|
|
55
|
+
hookHandlers: [], // Add your hook handler classes here
|
|
56
|
+
routeHandlers: [], // Add your route handler classes here
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
domain: { providers: [] }, // Add your domain provider classes here
|
|
61
|
+
infrastructure: { repositories: [] }, // Add your repository classes here
|
|
62
|
+
service: {
|
|
63
|
+
name: "my-service",
|
|
64
|
+
server: {
|
|
65
|
+
type: "SERVER",
|
|
66
|
+
vendor: "FASTIFY",
|
|
67
|
+
instance: fastifyApp,
|
|
68
|
+
},
|
|
69
|
+
databases: [
|
|
70
|
+
// Example for MongoDB:
|
|
71
|
+
// {
|
|
72
|
+
// vendor: "MONGOOSE",
|
|
73
|
+
// instance: new Mongoose(),
|
|
74
|
+
// connectionString: "mongodb://localhost/mydb",
|
|
75
|
+
// }
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
25
79
|
});
|
|
26
80
|
|
|
27
81
|
microServer.start({ port: 9000 });
|
|
28
82
|
```
|
|
29
83
|
|
|
30
|
-
|
|
84
|
+
## Configuration
|
|
31
85
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
86
|
+
- **Localization**: Place your locale JSON files in `src/locales/` (e.g., `en.json`, `fr.json`).
|
|
87
|
+
- **Environment Variables**: Configure your database connection strings and other settings as needed.
|
|
88
|
+
- **Custom Handlers**: Implement route and hook handlers by extending the provided abstract classes.
|
|
89
|
+
|
|
90
|
+
## Testing
|
|
35
91
|
|
|
36
|
-
|
|
92
|
+
Run all unit tests with coverage:
|
|
37
93
|
|
|
38
94
|
```bash
|
|
39
|
-
bun run
|
|
95
|
+
bun run test
|
|
96
|
+
# or
|
|
97
|
+
npm run test
|
|
40
98
|
```
|
|
99
|
+
|
|
100
|
+
Test configuration uses Vitest with in-memory MongoDB for fast, isolated tests.
|
|
101
|
+
|
|
102
|
+
## API Reference
|
|
103
|
+
|
|
104
|
+
- **Application Layer**: See `src/micro-service/architecture/application/`
|
|
105
|
+
- **Domain Layer**: See `src/micro-service/architecture/domain/`
|
|
106
|
+
- **Infrastructure Layer**: See `src/micro-service/architecture/infrastructure/`
|
|
107
|
+
- **Platform Layer**: See `src/micro-service/architecture/platform/`
|
|
108
|
+
- **Error Handling**: See `src/error/` for custom error classes and utilities.
|
|
109
|
+
|
|
110
|
+
## Contributing
|
|
111
|
+
|
|
112
|
+
Contributions are welcome! If you find this software useful and make improvements, please consider submitting a pull request. See the [LICENSE](./LICENSE) for details.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT License © 2025 sentzunhat
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
**zacatl** is built for speed, simplicity, and extensibility. For questions, issues, or feature requests, please open an issue on [GitHub](https://github.com/sentzunhat/zacatl).
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { FastifySchema } from "fastify";
|
|
2
3
|
|
|
3
4
|
import { AbstractRouteHandler } from "./abstract";
|
|
@@ -8,10 +9,11 @@ export type GetRouteHandlerConstructor = {
|
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export abstract class GetRouteHandler<
|
|
11
|
-
TBody,
|
|
12
|
-
TResponse,
|
|
12
|
+
TBody = never,
|
|
13
|
+
TResponse = never,
|
|
14
|
+
TQuerystring = z.ZodSchema<Record<string, string>>,
|
|
13
15
|
TParams = void
|
|
14
|
-
> extends AbstractRouteHandler<TBody, TResponse, TParams> {
|
|
16
|
+
> extends AbstractRouteHandler<TBody, TQuerystring, TResponse, TParams> {
|
|
15
17
|
constructor(args: GetRouteHandlerConstructor) {
|
|
16
18
|
super({
|
|
17
19
|
url: args.url,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { FastifySchema } from "fastify";
|
|
2
3
|
|
|
3
4
|
import { AbstractRouteHandler } from "./abstract";
|
|
@@ -8,10 +9,11 @@ export type PostRouteHandlerConstructor = {
|
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export abstract class PostRouteHandler<
|
|
11
|
-
TBody,
|
|
12
|
-
TResponse,
|
|
12
|
+
TBody = never,
|
|
13
|
+
TResponse = never,
|
|
14
|
+
TQuerystring = z.ZodSchema<Record<string, string>>,
|
|
13
15
|
TParams = void
|
|
14
|
-
> extends AbstractRouteHandler<TBody, TResponse, TParams> {
|
|
16
|
+
> extends AbstractRouteHandler<TBody, TQuerystring, TResponse, TParams> {
|
|
15
17
|
constructor(args: PostRouteHandlerConstructor) {
|
|
16
18
|
super({
|
|
17
19
|
url: args.url,
|