Skip to content

πŸš€ A powerful, enterprise-ready Node.js/TypeScript framework with advanced authorization, dynamic CRUD operations, and seamless integrations. Features CASL-based permissions, smart data handling, and extensible architecture for building scalable applications.

License

Notifications You must be signed in to change notification settings

miirshe/nexus-express-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Nexus Express TypeScript

Node.js CI

πŸš€ A powerful, extensible Node.js/TypeScript framework built for scalability, with advanced features and ready for enterprise integrations.

πŸ“‹ Table of Contents

🌟 Core Features

1. Advanced Authorization with CASL

  • Fine-grained permission control using CASL
  • Role-based access control (RBAC) integration
  • Dynamic ability checks for all CRUD operations
  • Declarative permission definitions

2. Dynamic CRUD Operations

Introducing a powerful baseHandler that provides:

// Example usage
import baseHandler from '../utils/baseHandler';

router.post('/', baseHandler.createOne(YourModel, {
  auth: true,
  ability: true,
  discriminator: {
    field: 'type',
    models: { /* your model mapping */ }
  }
}));

Supported Operations:

  • createOne: Single document creation
  • createMany: Bulk document creation
  • getAll: Smart paginated listing
  • getOne: Single document retrieval
  • updateOne: Document updates
  • deleteOne: Single document deletion
  • deleteMany: Bulk deletion
  • getSelf: Current user document

3. Smart Data Handling

  • Automatic Population:
    // Automatically detects and populates references
    const data = await Model.findById(id).populate(autoDetectedFields);
  • Dynamic Search:
    // Example search query
    GET /api/v1/resources?search={"keyword":"search","fields":["name","description"]}
  • Complex Filtering:
    // Support for complex query parameters
    GET /api/v1/resources?query={"status":"active"}&options={"sort":"createdAt"}

4. Enterprise-Ready Features

  • Type discrimination for flexible data modeling
  • Automatic audit trails (createdBy/updatedBy)
  • Extensible authentication system
  • Ready for multiple integration patterns

πŸ› οΈ Installation

  1. Clone the repository:

    git clone https://github.com/miirshe/nexus-express-typescript.git
    cd nexus-express-typescript
  2. Install dependencies:

    npm install
    # or
    yarn install
  3. Set up environment variables:

    cp .env.example .env
  4. Start development server:

    npm run dev
    # or
    yarn dev

πŸ“š Documentation

Base Handler Options

interface HandlerOptions {
    auth?: boolean;          // Enable/disable authentication
    ability?: boolean;       // Enable/disable authorization
    discriminator?: {
        field: string;       // Field for type discrimination
        models: { [key: string]: Model<any> }; // Model mapping
    };
}

API Examples

  1. Create with Type Discrimination:
POST /api/v1/resources
{
    "type": "custom",
    "name": "Example Resource",
    "metadata": { /* custom fields */ }
}
  1. Smart Search:
GET /api/v1/resources?search={"keyword":"example","fields":["name","metadata"]}
  1. Complex Queries:
GET /api/v1/resources?query={"status":"active"}&options={"sort":"-createdAt","populate":"relations"}

πŸ”’ Security Features

  • Authentication checks in every handler
  • CASL-based authorization
  • Type-safe implementations
  • Request validation
  • Error handling with proper status codes

πŸ”„ Integration Ready

  • Authentication providers
  • Notification systems
  • External APIs
  • Message queues
  • Caching layers
  • Monitoring systems

πŸ— Architecture

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Nexus Express TypeScript                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   API Layer β”‚  Services   β”‚  Data Layer    β”‚  Integrations β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ REST API  β”‚ β€’ Business  β”‚ β€’ MongoDB      β”‚ β€’ Auth        β”‚
β”‚ β€’ GraphQL   β”‚   Logic     β”‚ β€’ Redis Cache  β”‚   Providers   β”‚
β”‚ β€’ WebSocket β”‚ β€’ Validationβ”‚ β€’ Elasticsearchβ”‚ β€’ Payment     β”‚
β”‚ β€’ gRPC      β”‚ β€’ CASL Auth β”‚ β€’ Queue System β”‚   Gateways    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  1. API Layer

    • REST endpoints with OpenAPI/Swagger
    • Optional GraphQL support
    • Real-time WebSocket capabilities
    • gRPC for microservices
  2. Service Layer

    • Business logic isolation
    • CASL-based authorization
    • Service-to-service communication
    • Event handling
  3. Data Layer

    • MongoDB with Mongoose
    • Redis for caching
    • Elasticsearch for search
    • Message queues
  4. Integration Layer

    • Authentication providers
    • Payment systems
    • External APIs
    • Monitoring systems

πŸ”Œ Integration Patterns

1. Authentication Providers

// Support for multiple auth strategies
interface AuthProvider {
  initialize(): Promise<void>;
  authenticate(credentials: any): Promise<User>;
  verify(token: string): Promise<boolean>;
}

// Implementation examples:
class JWTAuthProvider implements AuthProvider { ... }
class OAuth2Provider implements AuthProvider { ... }
class SAMLProvider implements AuthProvider { ... }

2. Notification System

// Unified notification interface
interface NotificationChannel {
  send(message: NotificationMessage): Promise<void>;
}

// Multiple channel support
class EmailNotification implements NotificationChannel { ... }
class SMSNotification implements NotificationChannel { ... }
class PushNotification implements NotificationChannel { ... }

3. Payment Integration

// Generic payment interface
interface PaymentGateway {
  processPayment(payment: Payment): Promise<Transaction>;
  refund(transaction: Transaction): Promise<Refund>;
}

// Multiple provider support
class StripeGateway implements PaymentGateway { ... }
class PayPalGateway implements PaymentGateway { ... }

4. Caching Strategy

// Flexible caching interface
interface CacheProvider {
  get<T>(key: string): Promise<T>;
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
}

// Implementation examples:
class RedisCache implements CacheProvider { ... }
class MemcachedCache implements CacheProvider { ... }

🎯 Roadmap

Phase 1: Core Enhancement (Current)

  • CASL Integration
  • Dynamic CRUD Operations
  • Type Discrimination
  • Smart Data Handling

Phase 2: Authentication & Security (Next)

  • Multi-factor Authentication
  • OAuth2 Provider Integration
  • SAML Support
  • Rate Limiting
  • API Key Management

Phase 3: Performance & Scaling

  • Redis Caching Layer
  • Elasticsearch Integration
  • Message Queue System
  • Horizontal Scaling Support
  • GraphQL API Layer

Phase 4: Developer Experience

  • OpenAPI/Swagger Documentation
  • CLI Tool for Code Generation
  • Development Container Support
  • Enhanced Debugging Tools
  • Integration Test Framework

Phase 5: Enterprise Features

  • Audit Logging System
  • Business Event System
  • Workflow Engine
  • Report Generation
  • Data Export/Import

Phase 6: Monitoring & Operations

  • APM Integration
  • Metrics Collection
  • Alert System
  • Log Aggregation
  • Performance Analytics

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸš€ A powerful, enterprise-ready Node.js/TypeScript framework with advanced authorization, dynamic CRUD operations, and seamless integrations. Features CASL-based permissions, smart data handling, and extensible architecture for building scalable applications.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published