Getting Started

This guide will help you get started with DRFT and create your first resource stack.

Installation

Prerequisites

  • Dart SDK 3.0 or higher
  • A Dart project (or create a new one)

Add DRFT to Your Project

Add DRFT to your pubspec.yaml:

dependencies:
  drft: ^0.1.0

Then install dependencies:

dart pub get

Your First Stack

Let's create a simple stack with a mock resource to get familiar with DRFT.

1. Create a Stack

import 'package:drft/drft.dart';

void main() async {
  final stack = DrftStack(
    name: 'my-first-stack',
    providers: [
      MockProvider(), // For testing
    ],
    resources: [
      // We'll add resources here
    ],
  );
}

2. Define a Resource

For now, let's use a simple test resource. In a real scenario, you'd use resources from providers like Firebase, AWS, etc.

final stack = DrftStack(
  name: 'my-first-stack',
  providers: [MockProvider()],
  resources: [
    TestResource(
      id: 'my-resource',
      name: 'Hello DRFT',
    ),
  ],
);

3. Plan Changes

Before applying changes, always plan first to see what will happen:

final plan = await stack.plan();
print(plan.summary);

This will show you what operations DRFT will perform (create, update, or delete).

4. Apply Changes

Once you're happy with the plan, apply it:

final result = await stack.apply(plan);
print(result.summary);

Understanding the Workflow

DRFT follows a simple workflow:

  1. Define your desired resources in code
  2. Plan to see what changes will be made
  3. Apply to execute the changes
  4. State is automatically tracked

Next Steps

Common Tasks

View Current State

final state = await stack.stateManager.load();
print('Current resources: ${state.resources.length}');

Refresh State

Refresh state from the actual system:

final state = await stack.refresh();

Destroy Resources

To remove all resources:

final plan = await stack.plan();
// Filter for delete operations if needed
await stack.apply(plan);

Troubleshooting

State File Not Found

If you see errors about state files, DRFT will create them automatically. Make sure you have write permissions in your project directory.

Provider Not Found

Ensure you've added the correct provider to your stack and that it's properly configured.

Resources Not Updating

Check that your resource definitions match the actual state. Use refresh() to sync state.

Getting Help