appwrite_generator 0.1.0 copy "appwrite_generator: ^0.1.0" to clipboard
appwrite_generator: ^0.1.0 copied to clipboard

A powerful Dart CLI tool that generates type-safe, production-ready Dart models from Appwrite configuration JSON files with automatic serialization and null-safety support.

Appwrite Generator #

coverage style: very good analysis License: MIT

A powerful Dart CLI tool that generates type-safe, production-ready Dart models from Appwrite configuration JSON files. Streamline your Appwrite development workflow by automatically generating models, enums, and attribute constants directly from your database schema.

Features ✨ #

  • 🎯 Type-Safe Models: Generates Dart classes with full type safety
  • πŸ”„ Complete Serialization: Automatic fromJson, toJson, and copyWith methods
  • πŸ“ Enum Support: Creates proper Dart enums from enum-type columns
  • πŸ”‘ Attribute Constants: Type-safe property access with generated constants
  • βœ… Null Safety: Respects the required flag in your schema
  • πŸ”— Relationship Support: Handles one-to-one, one-to-many, many-to-one, and many-to-many relationships
  • πŸ“¦ Well-Organized Output: Models organized by collection with clear structure
  • ⚑ Fast & Efficient: Quickly generates all models with a single command

Getting Started πŸš€ #

Installation #

From Source (Currently Available)

Clone the repository and activate locally:

git clone https://github.com/moinsen-dev/appwrite_generator.git
cd appwrite_generator
dart pub global activate --source=path .

From Pub (Coming Soon)

Once published on pub.flutter-io.cn:

dart pub global activate appwrite_generator

Prerequisites #

  • Dart SDK 3.9.0 or higher
  • An appwrite.json configuration file from your Appwrite project

Usage #

Basic Commands #

# Generate models from appwrite.json in current directory
$ appwrite_generator generate

# Specify custom input and output paths
$ appwrite_generator generate --input my_config.json --output lib/generated

# Show CLI version
$ appwrite_generator --version

# Show usage help
$ appwrite_generator --help

# Update the CLI to the latest version
$ appwrite_generator update

What Gets Generated #

From your appwrite.json configuration, the generator creates:

  • Type-safe model classes with fromJson, toJson, and copyWith methods
  • Enums for all enum-type columns
  • Attribute constants for type-safe property access
  • Null-safe code based on the required flag in your schema

Example #

Given this appwrite.json:

{
  "tables": [{
    "$id": "users",
    "name": "Users",
    "columns": [
      {
        "key": "handle",
        "type": "string",
        "required": true,
        "size": 20
      },
      {
        "key": "age_band",
        "type": "string",
        "required": false,
        "elements": ["18-24", "25-34", "35-44", "45+"],
        "format": "enum"
      }
    ]
  }]
}

The generator creates:

// lib/models/users/user.dart
class User {
  const User({required this.handle, this.ageBand});

  final String handle;
  final AgeBand? ageBand;

  factory User.fromJson(Map<String, dynamic> json) { ... }
  Map<String, dynamic> toJson() { ... }
  User copyWith({String? handle, AgeBand? ageBand}) { ... }
}

// lib/models/users/user_enums.dart
enum AgeBand {
  value18to24('18-24'),
  value25to34('25-34'),
  value35to44('35-44'),
  value45Plus('45+');

  final String value;
  const AgeBand(this.value);
  factory AgeBand.fromString(String value) { ... }
}

// lib/models/users/user_attributes.dart
class UserAttributes {
  static const String handle = 'handle';
  static const String ageBand = 'age_band';
}

Supported Attribute Types #

The generator supports all Appwrite attribute types:

Appwrite Type Dart Type Notes
string String Includes support for enum format
integer int With min/max validation support
double double Floating-point numbers
boolean bool True/false values
datetime DateTime ISO 8601 format
email String Email validation in schema
ip String IP address validation
url String URL validation
enum Custom Enum Generates dedicated enum class
relationship N/A Documented but not directly generated

Real-World Example #

Check out the example directory for a complete Flutter application with a comprehensive to-do list schema featuring:

  • 5 interconnected tables: Projects, Todos, Tags, TodoTags (junction table), and Comments
  • Multiple enum types: Project status, todo priority, todo status
  • Various attribute types: strings, integers, datetimes, enums
  • Relationships: One-to-many and many-to-many patterns
  • Complete Flutter app: Working example showing generated models in action

Development πŸ› οΈ #

Running Tests with Coverage #

# Activate coverage tool
$ dart pub global activate coverage 1.15.0

# Run tests with coverage
$ dart test --coverage=coverage

# Format coverage data
$ dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info

# Generate HTML coverage report (requires lcov)
$ genhtml coverage/lcov.info -o coverage/

# Open coverage report
$ open coverage/index.html

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Roadmap πŸ—ΊοΈ #

  • ❌ Publish to pub.flutter-io.cn
  • ❌ Add support for custom templates
  • ❌ Generate repository/service layers
  • ❌ Add validation helpers
  • ❌ Support for custom attribute types
  • ❌ Generate API documentation
  • ❌ Migration generator for schema changes

License #

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

Copyright (c) 2025 Moinsen Development

Acknowledgments #


0
likes
150
points
102
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful Dart CLI tool that generates type-safe, production-ready Dart models from Appwrite configuration JSON files with automatic serialization and null-safety support.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

args, cli_completion, mason_logger, mustache_template, path, pub_updater, recase, yaml

More

Packages that depend on appwrite_generator