npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@plyaz/core

v1.23.4

Published

Shared core logic and utilities for Plyaz apps, services, and future SDKs – centralized, reusable, and scalable.

Readme

@plyaz/core

Foundational full-stack framework for the Plyaz ecosystem

The @plyaz/core package serves as the orchestration layer that provides domain service infrastructure, automatic dependency injection, and unified service management across frontend and backend environments.

Key Features

  • Domain Service Framework - Base classes for backend and frontend services with automatic CRUD, validation, and lifecycle hooks
  • Service Registry - Centralized service management with automatic dependency injection
  • Unified Infrastructure - Single initialization for DB, API, Cache, Storage, Notifications, and Observability
  • Multi-Runtime Support - Node.js, Next.js, NestJS, Browser, Edge, Bun, Deno
  • Event-Driven Architecture - Typed events with CoreEventManager
  • Feature Flags - Rule-based evaluation with targeting and rollouts
  • CLI Tooling - Interactive feature generation with plyaz-core

Quick Start

Backend Service

import { Core, ServiceRegistry } from '@plyaz/core';

// Initialize all services at once
await Core.initialize({
  db: {
    adapter: 'sql',
    sql: { connectionString: process.env.DATABASE_URL },
  },
  api: {
    baseUrl: process.env.API_BASE_URL,
  },
  cache: {
    provider: 'memory',
    ttl: 300,
  },
});

// Register domain services
ServiceRegistry.register({
  key: 'users',
  serviceClass: UserDomainService,
  config: { enabled: true },
});

// Get service instance with injected dependencies
const userService = await ServiceRegistry.getAsync<UserDomainService>('users');
const user = await userService.getById('user-123');

Creating Domain Services

import { BaseBackendDomainService } from '@plyaz/core/backend';

class UserDomainService extends BaseBackendDomainService<
  UserConfig,
  UserRepository,
  User,
  CreateUserDTO,
  UpdateUserDTO
> {
  protected eventPrefix = 'user';

  // Fluent queries via repository.query()
  async findActiveAdmins() {
    return this.repository.query()
      .where('status', 'eq', 'active')
      .andWhere('role', 'eq', 'admin')
      .orderByDesc('createdAt')
      .getMany();
  }

  // Lifecycle hooks
  protected async afterCreate(entity: User) {
    await this.sendWelcomeEmail(entity);
  }
}

Architecture

@plyaz/core
├── init/                    # Core initialization & ServiceRegistry
├── services/                # Infrastructure services
│   ├── DbService           # Database (wraps @plyaz/db)
│   ├── ApiClientService    # HTTP client (wraps @plyaz/api)
│   ├── CacheService        # Caching (memory/redis)
│   ├── StorageService      # File storage (Supabase/R2)
│   ├── NotificationService # Email/SMS/Push (Infobip/SendGrid)
│   └── ObservabilityService # Metrics, tracing, logging
├── domain/                  # Base domain service classes
│   ├── BaseDomainService
│   ├── BaseBackendDomainService
│   └── BaseFrontendDomainService
├── events/                  # CoreEventManager
├── models/                  # Repositories & data access
└── adapters/               # NestJS, Next.js integrations

Service Injection Flow

Core.initialize(config)
    ↓
ServiceRegistry.initialize()
    ↓
Build service configs (db, api, cache, storage, notifications)
    ↓
ServiceRegistry.register({ key, serviceClass, config })
    ↓
DomainService.create(config, { injected: { db, api, cache, storage, notifications } })
    ↓
Access via this.config.injected?.db / storage / notifications

Infrastructure Services

DbService

Database connection manager with adapter chain (soft delete, caching, audit, encryption):

import { DbService } from '@plyaz/core';

await DbService.initialize({
  adapter: 'sql',
  sql: { connectionString: process.env.DATABASE_URL },
  softDelete: { enabled: true },
  cache: { enabled: true, ttl: 300 },
});

const db = DbService.getInstance().getDatabase();

CacheService (Backend-only)

Server-side caching with Redis or in-memory providers:

import { CacheService } from '@plyaz/core';

await CacheService.initialize({
  strategy: 'redis',
  ttl: 300,
  redisConfig: {
    url: process.env.REDIS_URL,
    keyPrefix: 'app:',
  },
});

const cache = CacheService.getInstance();
await cache.set('user:123', userData, 600); // 10 minute TTL
const cached = await cache.get('user:123');

StorageService (Backend-only)

Multi-provider file storage with automatic routing:

import { StorageService } from '@plyaz/core';

const storage = StorageService.getInstance().getStorage();
await storage.uploadFile({
  file: buffer,
  filename: 'document.pdf',
  bucket: 'documents',
});

NotificationService (Backend-only)

Multi-channel notifications with provider failover:

import { NotificationService } from '@plyaz/core';

const notifications = NotificationService.getInstance().getNotifications();
await notifications.sendEmail({
  to: '[email protected]',
  templateId: 'welcome',
  templateData: { name: 'John' },
});

QueryBuilder Integration

Fluent query API via @plyaz/db integrated with BaseRepository:

// In domain service
const users = await this.repository.query()
  .where('status', 'eq', 'active')
  .andWhere('tier', 'eq', 'premium')
  .whereNotNull('verifiedAt')
  .orderByDesc('createdAt')
  .paginate(1, 25)
  .getMany();

// Raw SQL for complex queries
const results = await this.repository.query()
  .where('status', 'eq', 'active')
  .whereRaw('"metadata"->\'score\' > $1', [80])
  .getMany();

CLI

Generate features interactively:

# Interactive mode
pnpm plyaz-core generate

# Direct generation
pnpm plyaz-core generate user --type backend

# Options
--type backend|frontend|universal
--skip-validator
--skip-mapper
--dry-run

Feature Flags

import { useFeatureFlag } from '@plyaz/core/frontend';

// React hook
const isEnabled = useFeatureFlag('DARK_MODE');

// Backend check
const flags = await FeatureFlagService.getFlags();
if (flags.PREMIUM_FEATURES) {
  // Premium logic
}

Documentation

| Guide | Description | |-------|-------------| | Quick Start | Get started in 5 minutes | | Architecture | System design overview | | Initialization | Configuration options | | Services | Domain service patterns | | Base Classes API | Full API reference | | DbService Guide | Database integration | | CacheService Guide | Caching (Redis/in-memory) | | StorageService Guide | File storage | | NotificationService Guide | Notifications |

Related Packages

| Package | Purpose | |---------|---------| | @plyaz/db | Database adapters, repositories, QueryBuilder | | @plyaz/api | HTTP client, fetchers, request handling | | @plyaz/storage | File storage providers (Supabase, R2) | | @plyaz/notifications | Email/SMS/Push providers | | @plyaz/types | Shared TypeScript types | | @plyaz/errors | Error handling utilities |

Development

# Install dependencies
pnpm install

# Development
pnpm dev           # Watch mode
pnpm build         # Build package
pnpm type:check    # Type checking

# Testing
pnpm test          # Run tests
pnpm test:watch    # Watch mode
pnpm test:coverage # With coverage

# Code quality
pnpm lint          # Lint code
pnpm lint:fix      # Fix issues
pnpm format        # Format code

# NestJS server (if configured)
pnpm nest:dev      # Development server
pnpm nest:start    # Production server

License

MIT