How rockhillz/nodecore-kit works
Purpose and Public Surface
nodecore-kit is a TypeScript backend SDK for Node.js services, packaging reusable infrastructure clients, security primitives, transport utilities, and framework-independent helpers. Consumers import its unified public API from src/index.ts; domain-level barrels expose subsystem APIs through src/core/index.ts, src/adapters/index.ts, src/security/index.ts, and src/transport/index.ts.
Layering and Dependency Boundaries
The architecture is explicitly layered: pure core utilities are the foundation; security, adapters, and transport build above them without becoming an application runtime. Adapters receive configuration through constructors rather than reading environment variables, preserving testability and allowing each consuming service to own deployment configuration.
• src/core/index.ts
• src/adapters/types.ts
• src/index.ts
Core Foundation
Core supplies shared types, error classes, validation, async control primitives, object/string transformations, and UUID handling. These are the dependency-safe building blocks used across higher-level modules; they should not depend on infrastructure or HTTP frameworks.
• src/core/types.ts
• src/core/error.ts
• src/core/async.ts
• src/core/uuid.ts
External-Service Adapters
Adapter classes encapsulate operational integrations and lifecycle behavior: Redis caching/data operations, AWS SQS enqueue/long-poll consumption with stopping/DLQ behavior, S3 object operations and signing, scheduled jobs, and pluggable mail delivery. This is the main boundary between application code and external infrastructure.
• src/adapters/redis.ts
• src/adapters/sqs.ts
• src/adapters/s3.ts
• src/adapters/cron.ts
• src/adapters/mailers.ts
Observability and Provider Abstraction
Logging is injectable rather than globally fixed: adapter-facing logger types support console-compatible or custom implementations, while Winston provides the included structured logger implementation. Mail delivery likewise separates the Mailer façade from SMTP, Resend, and SendGrid providers, enabling runtime provider replacement/fallback.
• src/adapters/types.ts
• src/adapters/loggers/winston.ts
• src/adapters/mailers.ts
Security Services
Security is isolated into dedicated services: password hashing and secure token/HMAC/fingerprinting operations, JWT encoding/verification and expiry inspection, plus symmetric encryption/decryption. Callers supply secrets/keys, keeping secret sourcing outside the library.
• src/security/hash.ts
• src/security/jwt.ts
• src/security/encrypt.ts
HTTP and Express Integration
Transport provides a typed fetch-based request wrapper with timeout/retry and pagination support, independent of server framework. Express integration is optional and limited to Joi request middleware and direct validation, creating a clear boundary between reusable validation semantics and Express request/response handling.
• src/transport/http.ts
• src/transport/express/express-middleware.ts
• src/transport/express/joiValidator.ts
Runtime and Infrastructure
The package targets Node.js with TypeScript compilation. Material external systems are Redis; AWS SQS and S3; SMTP/Nodemailer, Resend, and SendGrid; and Winston file/console logging. It is a library, not a standalone server: consuming services instantiate adapters, register cron/queue consumers, wire optional Express middleware, and own startup/shutdown signal handling.
Main entry points: src/index.ts Unified exports · core/index.ts Core exports · redis.ts Redis, SQS, S3 and cron · types.ts Adapter contracts
Components 17
Public API
- Unified exports
src/index.ts
Core Foundation
Framework- and infrastructure-independent building blocks.
- Core exports
src/core/index.ts - Types and errors
src/core/types.ts - Async control
src/core/async.ts - UUID handling
src/core/uuid.ts - Error classes
src/core/error.ts
Infrastructure Adapters
Constructor-configured integrations for consuming services.
- Adapter contracts · Supports injectable configuration and logging.
src/adapters/types.ts - Redis, SQS, S3 and cron · Caching, queue consumption, object operations, and scheduled jobs.
src/adapters/redis.ts - Mailer façade and providers · Selects SMTP, Resend, or SendGrid delivery providers.
src/adapters/mailers.ts - Winston logger
src/adapters/loggers/winston.ts
Security
- Hash, JWT and encryption · Caller-supplied secrets support hashing, tokens, JWTs, and encryption.
src/security/hash.ts
Transport
- HTTP client · Typed requests with timeout, retry, and pagination.
src/transport/http.ts - Express validation middleware
src/transport/express/express-middleware.ts - Joi validator
src/transport/express/joiValidator.ts
Other components
- Consuming Node.js service · Owns configuration, lifecycle, and secret sourcing.
- Redis and AWS · Redis plus AWS SQS and S3.
- Mail providers · SMTP/Nodemailer, Resend, and SendGrid.
Connections 22
- Consuming Node.js service → Unified exports: imports
- Consuming Node.js service → Adapter contracts: supplies config and logger
- Consuming Node.js service → Hash, JWT and encryption: supplies secrets
- Consuming Node.js service → Express validation middleware: optionally wires
- Unified exports → Core exports: exports
- Unified exports → Redis, SQS, S3 and cron: exports
- Unified exports → Hash, JWT and encryption: exports
- Unified exports → HTTP client: exports
- Core exports → Types and errors: exports
- Core exports → Async control: exports
- Core exports → UUID handling: exports
- Core exports → Error classes: exports
- Redis, SQS, S3 and cron → Adapter contracts: uses contracts
- Redis, SQS, S3 and cron → Async control: uses async control
- Redis, SQS, S3 and cron → Redis and AWS: operates
- Mailer façade and providers → Adapter contracts: uses contracts
- Mailer façade and providers → Mail providers: delivers through
- Winston logger → Adapter contracts: implements logger
- Hash, JWT and encryption → Error classes: uses errors
- HTTP client → Async control: uses retry control
- Express validation middleware → Joi validator: delegates validation
- Joi validator → Error classes: returns validation errors