A comprehensive suite of packages for generating type-safe Dart models from Supabase databases, supporting both pure Dart and Flutter applications.
This monorepo contains four main packages:
The core package for generating type-safe Dart models from Supabase tables. Perfect for:
- Pure Dart applications
- Server-side Dart projects
- Custom Dart environments
Flutter-optimized package that extends the core functionality with Flutter-specific features:
- Automatic environment file loading from
config.env - Convenient getters for Supabase services (auth, realtime, storage, functions)
- Better integration with
supabase_flutter - Flutter-specific client management
Serverpod-optimized package that generates Serverpod database models from Supabase tables:
- Generates Serverpod model files for tables and enums
- Maps Supabase types to Serverpod types
- Excludes internal Serverpod tables automatically
Contains the Mason bricks used by the other packages to generate code. This package is internal and not meant to be used directly.
- Type-Safe Models: Automatically generates strongly-typed Dart classes from your Supabase tables
- Full IDE Support: Complete IntelliSense and autocomplete for all generated models
- Complex Relationships: Supports nested structures and table relationships
- Null Safety: All generated models are fully null-safe
- Custom Types: Support for enums and custom column types
- Flexible Configuration: YAML-based configuration with command-line overrides
- Flutter Integration: Specialized package for Flutter development
- Serverpod Support: specialized package for Serverpod development
- Testing Support: Built-in mock clients for comprehensive testing
-
Install the Flutter package:
flutter pub add supabase_codegen_flutter
-
Set up your environment: Create
config.envin your project root:SUPABASE_URL=https://your-project.supabase.co SUPABASE_ANON_KEY=your-anon-key
-
Initialize configuration:
dart run supabase_codegen_flutter:init
This creates the
.supabase_codegen.yamlconfiguration file. -
Add to pubspec.yaml:
flutter: assets: - config.env
-
Generate types:
dart run supabase_codegen_flutter:generate_types
-
Use in your app:
import 'package:supabase_codegen_flutter/supabase_codegen_flutter.dart'; void main() async { await loadClientFromEnv(); runApp(const MyApp()); }
-
Install the core package:
dart pub add supabase_codegen
-
Set up your environment: Create
.envin your project root:SUPABASE_URL=https://your-project.supabase.co SUPABASE_ANON_KEY=your-anon-key
-
Initialize configuration:
dart run supabase_codegen:init
This creates the
.supabase_codegen.yamlconfiguration file. -
Generate types:
dart run supabase_codegen:generate_types
-
Use in your app:
import 'package:supabase_codegen/supabase_codegen.dart'; void main() async { loadClientFromEnv(); // Your app code here }
Run this in your Serverpod server project (typically my_serverpod_server)
-
Install the Serverpod Codegen package:
dart pub add supabase_codegen_serverpod
-
Set up your environment: Create
.envin your project root:SUPABASE_URL=https://your-project.supabase.co SUPABASE_ANON_KEY=your-anon-key
-
Initialize configuration:
dart run supabase_codegen_serverpod:init
This creates the
.supabase_codegen.yamlconfiguration file. -
Generate models:
dart run supabase_codegen_serverpod:generate_types
-
Use in your Serverpod project: The generated
.spy.yamlfiles will be inlib/src/models(or your configured output). Runserverpod generateto create the Dart classes.
This project uses Melos for monorepo management.
- Dart SDK
- Flutter SDK (for Flutter package development)
- Melos for workspace management
-
Clone the repository:
git clone https://github.com/Khuwn-Soulutions/supabase_codegen.git cd supabase_codegen -
Install dependencies:
dart pub get melos bootstrap
-
Run tests:
melos run test -
Run tests with coverage:
melos run test:coverage
supabase_codegen/
βββ packages/
β βββ supabase_codegen/ # Core Dart package
β β βββ bin/ # CLI tools
β β βββ lib/ # Source code
β β βββ test/ # Unit tests
β β βββ example/ # Usage examples
β βββ supabase_codegen_flutter/ # Flutter package
β βββ bin/ # CLI tools
β βββ lib/ # Source code
β βββ test/ # Unit tests
β βββ example/ # Flutter example app
β βββ supabase_codegen_serverpod/ # Serverpod package
β βββ bin/ # CLI tools
β βββ lib/ # Source code
β βββ test/ # Unit tests
βββ .github/
β βββ workflows/ # CI/CD pipelines
βββ analysis_options.yaml # Code analysis configuration
melos run test- Run all testsmelos run test:coverage- Run tests with coveragemelos run coverage_badge- Update coverage badgesmelos run test:coverage_badge- Run tests and update badges
- Supabase project with tables
- Dart/Flutter development environment
- Supabase CLI (for local development)
The project includes comprehensive test suites for both packages:
# Run all tests
melos run test
# Run with coverage
melos run test:coverageEach package includes example projects that demonstrate real-world usage and serve as integration tests.
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes
- Run tests:
melos run test - Submit a pull request
This project uses:
- Very Good Analysis for strict linting
- Very Good Workflows for CI/CD
- Comprehensive test coverage requirements
This project is licensed under the MIT License - see the LICENSE file for details.
- Built using the great work by Kennerd at Supabase Flutter Codegen
- Powered by Very Good Ventures tooling
- GitHub Issues for bug reports and feature requests
- Discussions for questions and community support
Made with β€οΈ by Khuwn Soulutions