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

@ecopex/ecopex-framework

v1.0.13

Published

Javascript Framework for API and Admin Panel

Readme

SB System

A Node.js system built with Fastify, Knex, and Ajv for automatic routing and database management with PM2 process management.

Features

  • Fastify: High-performance web framework
  • Knex: SQL query builder with migrations and seeds
  • Ajv: JSON schema validation
  • MySQL: Database support
  • PM2: Process management for production
  • Microservices: Separate admin and API services
  • Automatic Routing: Dynamic route loading from directory structure

Project Structure

sb_system/
├── workers/
│   ├── admin.js             # Admin service worker
│   └── api.js               # API service worker
├── routes/
│   ├── admin/
│   │   └── users/
│   │       ├── route.js      # Route definitions
│   │       ├── handler.js    # Route handlers
│   │       └── validation.js # Validation schemas
│   └── api/
├── database/
│   ├── migrations/
│   └── seeds/
├── config/
│   └── database.js
├── utils/
│   ├── routeLoader.js
│   └── validator.js
├── logs/                    # PM2 log files
├── ecosystem.config.js     # PM2 configuration
└── package.json

Installation

  1. Install dependencies:
npm install
  1. Set up environment variables:
# Copy the example and configure your settings
cp env.example .env
  1. Configure your environment in .env:
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=sb_system

# Server Configuration
API_PORT=3000
ADMIN_PORT=3001
HOST=0.0.0.0

# Optional: Internationalization
DEFAULT_LOCALE=en
SUPPORTED_LOCALES=en,tr,es
  1. Run database migrations:
npm run migrate
  1. Seed the database (optional):
npm run seed

Note: See ENVIRONMENT.md for complete environment variable documentation.

Usage

Development

# Start both services with PM2
npm run dev

# Or start individual services for development
npm run dev:api      # API service only
npm run dev:admin    # Admin service only

Production

# Start all services
npm start

# Or start with production environment
npm run prod

PM2 Management

# View status
npm run status

# View logs
npm run logs

# Restart services
npm run restart

# Stop services
npm run stop

# Reload services (zero-downtime)
npm run reload

# Delete all services
npm run delete

Services

API Service (Port 3000)

  • Health Check: GET http://localhost:3000/health
  • Documentation: GET http://localhost:3000/docs
  • Welcome: GET http://localhost:3000/
  • Language Management:
    • GET /api/language - Get supported languages
    • POST /api/language/set - Set preferred language
    • GET /api/language/detect - Detect language from headers

Admin Service (Port 3001)

  • Health Check: GET http://localhost:3001/health
  • Documentation: GET http://localhost:3001/docs
  • User Management:
    • GET /admin/users - Get all users (with pagination)
    • GET /admin/users/:id - Get user by ID
    • POST /admin/users - Create new user
    • PUT /admin/users/:id - Update user
    • DELETE /admin/users/:id - Delete user

Adding New Routes

  1. Create a new directory under routes/admin/ or routes/api/
  2. Add three files:
    • route.js - Define your routes
    • handler.js - Implement route handlers
    • validation.js - Define validation schemas

Example Route Structure

// routes/admin/products/route.js
module.exports = [
  {
    method: 'GET',
    url: '',
    handlerName: 'getAllProducts',
    validationName: 'getAllProductsValidation',
    schema: {
      // Fastify schema definition
    }
  }
];

// routes/admin/products/handler.js
class ProductHandler {
  static async getAllProducts(request, reply) {
    // Handler implementation
  }
}

module.exports = ProductHandler;

// routes/admin/products/validation.js
module.exports = {
  getAllProductsValidation: {
    // Ajv validation schema
  }
};

Database

The system uses Knex.js for database operations with MySQL. Migrations and seeds are included for easy setup.

Available Commands

  • npm run migrate - Run migrations
  • npm run migrate:rollback - Rollback migrations
  • npm run seed - Run seeds

Multi-Language Support

The system includes comprehensive internationalization (i18n) support with automatic language detection and validation error translation.

Supported Languages

  • English (en) - Default
  • Turkish (tr) - Türkçe
  • Spanish (es) - Español

Language Detection

The system automatically detects language from:

  1. Accept-Language header
  2. X-Language header
  3. lang query parameter
  4. Falls back to default locale

Language Endpoints

# Get supported languages
GET /api/language

# Set preferred language
POST /api/language/set
{
  "language": "tr"
}

# Detect language from headers
GET /api/language/detect

Usage Examples

# Request with Turkish language
curl -H "Accept-Language: tr" http://localhost:3000/api/language

# Request with custom language header
curl -H "X-Language: es" http://localhost:3000/admin/users

# Request with query parameter
curl "http://localhost:3000/admin/users?lang=tr"

Validation

The system uses Ajv for JSON schema validation with multi-language error messages. Validation schemas are defined in the validation.js files and automatically applied to routes.

License

MIT