Skip to content

khode-io/nest-dart

Repository files navigation

Nest Dart

A NestJS-inspired dependency injection framework for Dart, bringing modular architecture and type-safe service management to Dart applications.

Features

  • 🏗️ Modular Architecture - Organize code into reusable modules
  • 💉 Dependency Injection - Type-safe service resolution with GetIt
  • 🔒 Access Control - Services are private by default, must be explicitly exported
  • 🔧 Multi-Platform - Works with Flutter, Dart Frog, and pure Dart applications
  • 🚦 Module-Based Routing - GoRouter integration with automatic route collection

Packages

Package Version Description
nest_core pub version Core dependency injection and module system
nest_flutter pub version Flutter integration with GoRouter and provider support
nest_frog pub version Dart Frog backend integration with middleware support

Quick Start

Core Application

import 'package:nest_core/nest_core.dart';

class AppModule extends Module {
  @override
  List<Module> get imports => [CoreModule(), UserModule()];
  
  @override
  void providers(Locator locator) {
    locator.registerSingleton<UserService>(UserService());
  }
  
  @override
  List<Type> get exports => [UserService];
}

// Initialize the application
final container = ApplicationContainer();
await container.registerModule(AppModule());

Flutter Integration

import 'package:flutter/material.dart';
import 'package:nest_flutter/nest_flutter.dart';

void main() {
  runApp(
    ModularApp(
      module: AppModule(),
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: Modular.router((router) {
        return GoRouter(
          routes: router.configuration.routes,
          initialLocation: '/',
        );
      }),
    );
  }
}

Module with Routes

class UserModule extends Module {
  @override
  List<RouteBase> get routes => [
    GoRoute(
      path: '/users',
      builder: (context, state) => UserListPage(),
    ),
  ];

  @override
  void providers(Locator locator) {
    locator.registerSingleton<UserService>(UserService());
  }
}

Examples

  • Flutter App - Mobile app with modular architecture and GoRouter integration
  • Frog Backend - REST API server with dependency injection and middleware

Documentation

Development

# Install dependencies
dart pub get

# Run tests
melos run test

# Format code
melos run format

License

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

About

A NestJS-inspired dependency injection framework for Dart

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages