Clean Architecture Global Structure
Generate a clean architecture structure with its respective files (Data sources, Repositories, Models, Entities, Use cases) at the root of your project.
Getting Started š
-
Install mason
dart pub global activate mason_cli
-
Add the brick
mason add -g clean_architecture_global_structure
-
Make a new Dart package
mason make clean_architecture_global_structure
Variables āØ
Variable | Description | Default | Type | Conditional | When |
---|---|---|---|---|---|
feature_name | The name of the feature | Auth | string | false | N/A |
Outputs š¦
Data directory outputs š§±
āāā data
ā Ā āāā datasources
ā Ā ā āāā auth.dart
ā Ā āāā models
ā Ā ā āāā auth_model.dart
ā Ā āāā repositories
ā Ā ā āāā auth_repository_impl.dart
ā Ā āāā ...
āāā ... Ā
Domain directory outputs š§±
āāā domain
ā Ā āāā repositories
ā Ā ā āāā auth_repository.dart
ā Ā āāā entities
ā Ā ā āāā auth_entity.dart
ā Ā āāā usecases
ā Ā ā āāā auth_use_case.dart
ā Ā āāā ...
āāā ... Ā
Aplication layer directory outputs š§±
āāā application_layer
ā Ā āāā auth
ā Ā ā āāā bloc
ā ā ā āāā auth
ā Ā ā ā ā āāā auth_bloc.dart
ā Ā ā ā ā āāā auth_event.dart
ā Ā ā ā ā āāā auth_state.dart
ā Ā ā ā ā āāā bloc.dart
ā Ā ā ā āāā ...
ā āĀ Ā Ā āāā pages
ā ā ā āāā auth_page.dart
ā āĀ Ā Ā āāā widgets
ā ā ā āāā .gitkeep
ā ā āāā ...
ā Ā āāā ...
āāā ... Ā
General outputs š§±
āāā lib
ā Ā āāā application_layer
ā Ā ā Ā āāā auth
ā Ā ā āĀ Ā Ā āāā pages
ā Ā ā ā ā āāā auth_page.dart
ā Ā ā āĀ Ā Ā āāā widgets
ā ā ā ā āāā .gitkeep
ā ā Ā ā Ā āāā ...
ā Ā ā Ā āāā ...
ā Ā āāā core
ā Ā ā Ā āāā errors
ā Ā ā Ā ā āāā failures.dart
ā Ā ā Ā āāā usecases
ā Ā ā Ā ā āāā usecase.dart
ā Ā āāā data
ā Ā ā Ā āāā datasources
ā Ā ā Ā ā āāā auth.dart
ā Ā ā Ā āāā models
ā Ā ā Ā ā āāā auth_model.dart
ā Ā ā Ā āāā repositories
ā Ā ā Ā ā āāā auth_repository_impl.dart
ā Ā ā Ā āāā ...
ā Ā āāā domain
ā Ā ā Ā āāā repositories
ā Ā ā Ā ā āāā auth_repository.dart
ā Ā ā Ā āāā entities
ā Ā ā Ā ā āāā auth_entity.dart
ā Ā ā Ā āāā usecases
ā Ā ā Ā ā āāā auth_use_case.dart
ā Ā ā Ā āāā ...
ā Ā āāā ... Ā
āāā ...
Outputs Example
Data
Datasource class
abstract class AuthDataSource {
// TODO: implement your AuthDataSource
}
class AuthDataSourceImpl implements AuthDataSource {
// TODO: implement your AuthDataSourceImpl
}
Model class
import 'package:any/domain/entities/auth_entity.dart';
class AuthModel extends AuthEntity {
// TODO: implement your AuthModel
}
Repository implementation class
import "package:any/domain/repositories/auth_repository.dart";
class AuthRepositoryImpl implements AuthRepository {
// TODO: implement your AuthRepositoryImpl
}
Domain
Entity
import 'package:equatable/equatable.dart';
class AuthEntity extends Equatable {
// TODO: implement your AuthEntity
@override
// TODO: implement props
List<Object?> get props => throw UnimplementedError();
}
Repository
class AuthRepository {
// TODO: implement your AuthRepository
}
Use case
import 'package:dartz/dartz.dart';
import 'package:any/core/usecases/usecase.dart';
import 'package:any/core/error/failure.dart';
class AuthUseCase implements UseCase<void, AuthParams> {
// TODO: implement the output of your AuthUseCase
@override
Future<Either<Failure, void>> call(AuthParams params) {
// TODO: implement call
throw UnimplementedError();
}
}
class AuthParams {
// TODO: implement your AuthParams
const AuthParams();
}
Core
Use case
import 'package:dartz/dartz.dart';
import 'package:any/core/errors/failures.dart';
abstract class UseCase<Output, Input> {
Future<Either<Failure, Output>> call(Input params);
}
Failures
import 'package:equatable/equatable.dart';
abstract class Failure extends Equatable {
final int? statusCode;
final String? responseMessage;
final Exception? exception;
const Failure([this.statusCode, this.responseMessage, this.exception]);
@override
List<Object?> get props => [statusCode, responseMessage, exception];
}
Aplication layer
Page
import 'package:flutter/material.dart';
class AuthPage extends StatelessWidget {
const AuthPage ({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const SizedBox();
}
}