npm package: @mission-fabric/router-core
Description: Enterprise-grade routing solution that's ridiculously easy to use and secure
Author: Mission Fabric
Latest version: 1.0.1

# @mission-fabric/router-core

<p align="center">
  <img src="https://via.placeholder.com/200x200?text=MF+Router" alt="Mission Fabric Router Logo" width="200" height="200">
</p>

<h3 align="center">Enterprise-Grade Routing. Ridiculously Secure. Ridiculously Easy.</h3>

<p align="center">
  <a href="https://www.npmjs.com/package/@mission-fabric/router-core"><img src="https://img.shields.io/npm/v/@mission-fabric/router-core.svg" alt="NPM Version"></a>
  <a href="https://github.com/mission-fabric/router-core/actions"><img src="https://github.com/mission-fabric/router-core/workflows/CI/badge.svg" alt="Build Status"></a>
  <a href="https://codecov.io/gh/mission-fabric/router-core"><img src="https://codecov.io/gh/mission-fabric/router-core/branch/main/graph/badge.svg" alt="Coverage Status"></a>
  <a href="https://snyk.io/test/github/mission-fabric/router-core"><img src="https://snyk.io/test/github/mission-fabric/router-core/badge.svg" alt="Known Vulnerabilities"></a>
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
</p>

## Overview

Mission Fabric Router Core is an enterprise-grade routing library designed to provide military-grade security with developer-friendly ergonomics. Built for organizations that require the utmost in security, reliability, and performance, while still maintaining superior developer experience.

```typescript
// The easiest way to create an enterprise-grade API
import { Router, SecurityPolicies } from '@mission-fabric/router-core';

const router = new Router();

// Apply enterprise security with one line
router.use(SecurityPolicies.strictCSP());

// Define routes with strong typing and validation
router.addRoute({
  method: 'get',
  path: '/users/:id',
  auth: true,
  roles: ['admin'],
  handler: async (req, res) => {
    res.json({ id: req.params.id, name: 'John Doe' });
  }
});

// Connect to Express app
app.use(router.getRouter());
```

## Key Features

- 🔒 **Military-Grade Security**: RBAC, JWT, API keys, CSRF protection, rate limiting, and more
- 🚀 **High Performance**: Built-in performance monitoring, caching, compression, and circuit-breaking
- 📊 **Observability**: Detailed metrics, logging, and tracing capabilities built-in
- 🧩 **Modular Design**: Use only what you need, from simple routes to full API gateway features
- 🔄 **Versioning**: Easy API versioning and backward compatibility
- 🧪 **Testable**: First-class testing support with mocks and test harnesses
- 🏢 **Enterprise-Ready**: Designed for large-scale applications and microservices
- 📘 **TypeScript-First**: 100% TypeScript with comprehensive types for superb IDE integration

## Installation

```bash
npm install @mission-fabric/router-core
```

## Quick Start

### Basic Router

```typescript
import express from 'express';
import { Router } from '@mission-fabric/router-core';

const app = express();
const router = new Router();

// Add a simple GET route
router.addRoute({
  method: 'get',
  path: '/hello',
  handler: (req, res) => {
    res.send('Hello, world!');
  }
});

// Mount router with Express
app.use(router.getRouter());
app.listen(3000);
```

### Secure API with Authentication

```typescript
import { Router, MiddlewareFactory } from '@mission-fabric/router-core';

const router = new Router({
  security: {
    jwtSecret: process.env.JWT_SECRET,
    enableHelmet: true
  }
});

// Apply predefined security middleware
router.use(...MiddlewareFactory.apiSecurity({
  cors: { origin: 'https://example.com' },
  rateLimit: { max: 100, windowMs: 60000 } // 100 requests per minute
}));

// Secure route with authentication and roles
router.addRoute({
  method: 'post',
  path: '/admin/settings',
  auth: true,
  roles: ['admin'],
  handler: async (req, res) => {
    res.json({ success: true });
  }
});
```

### Route Groups

```typescript
// Group routes with shared middleware and prefix
const apiGroup = router.group('/api/v1', {
  middleware: [someSharedMiddleware],
  roles: ['user'] // Base role for all routes in this group
});

// Routes will be mounted at /api/v1/users
apiGroup.get('/users', listUsersHandler);
apiGroup.post('/users', createUserHandler, { roles: ['admin'] }); // Requires admin role

// Nested group for admin routes
const adminGroup = apiGroup.group('/admin', { roles: ['admin'] });
adminGroup.get('/stats', getStatsHandler);
```

## Comprehensive Documentation

Visit our [documentation site](https://docs.mission-fabric.io/router-core) for detailed guides, API references, and examples.

## Security Features

- **Request Validation**: Prevent injection and other input attacks
- **RBAC**: Fine-grained role-based access control
- **Rate Limiting**: Protection against brute-force and DoS attacks
- **CSRF Protection**: Built-in cross-site request forgery prevention
- **JWT Management**: Secure token handling with key rotation support
- **Security Headers**: CSP, HSTS, XSS protection, and more
- **API Key Authentication**: For service-to-service communication
- **OAuth Integration**: Connect with identity providers

## Enterprise Support

Enterprise support plans are available. Contact our [sales team](mailto:sales@mission-fabric.io) for more information.

## Contributing

We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for details.

## License

MIT © Mission Fabric