Appwrite Generator
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
, andcopyWith
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
, andcopyWith
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Roadmap πΊοΈ
License
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2025 Moinsen Development
Acknowledgments
- Built with Very Good CLI
- Uses mason_logger for beautiful CLI output
- Follows Very Good Analysis style guide
Libraries
- appwrite_generator
- appwrite_generator, Appwrite code generator