Strategic

Domain-Driven-Design 

for

Improving

Flutter

Architecture

Majid Hajian

mhadaily

Updated - April 2020

mhadaily

Share Experiences

Well?

Best Practices

mhadaily

Patterns

Methodology

+

mhadaily

Resource Capacity

Project Complexity

App development Complexity Growth

without DDD

Resource Capacity

Project Complexity

App development Complexity Growth

with DDD

When DDD can help?

Flutter APP

Amount of data

Performance

Business Logic complexity 

Technical complexity

YAGNI

You are not gonna need it

Shortening development time

KISS

Keep it short and simple

Maintainable code

DDD

Focus on essential parts

Simplifying the problem

What we will learn today

Introduction to DDD

1

Proposed Flutter architectures 

1

Strategic Domain Driven Design

1

DEMO

1

mhadaily

ME.dart

import 'package:flutter/material.dart';

MaterialApp(
   ThemeData(
        name: "Majid Hajian",
        location: "Oslo, Norway",
        description: '''
        	Passionate Software engineer, 
	        Community Leader, Author and international Speaker
         ''',
        main: "Flutter/Dart, PWA, IoT",
        homepage: "https://www.majidhajian.com",
        socials: {
          twitter: "https://www.twitter.com/mhadaily",
          github: "https://www.github.com/mhadaily"
        },
        books: {
          "Progressive Web App with Angular": {
             version: "1.0.0", 
             publishedBy: "Apress", 
             foundOn: "www.pwawithangular.com",
          }
        },
        author: {
          packtpub: "PWA development, 7 hours video course",
          Udemy: "PWA development, 7 hours video course"
        }
        founder: "Softiware As (www.Softiware.com)"
        devDependencies: {
          tea: "green", mac: "10.14+",
        },
        engines: {
          MobileEraConference: "Orginizer",
          ngVikingsConference: "Orginizer", 
          MobileMeetupOslo:"Co-Orginizer",
          FlutterDartOslo: "Co-Orginizer",
          GDGOslo: "Co-Orginizer",          
        }
     ),
 )

mhadaily

Find me on the internet by

mhadaily

Domain

Driven

Design 

mhadaily

When we develop a Software 

Primarily focus is

Technology

 

 

mhadaily

When we develop a Software 

Primarily focus is

Technology

Business

 

mhadaily

Write code

Build An App

Understand Client Needs

Solve Problems

D

is for

DOMAIN

mhadaily

Strategic design tools

Tactical

 design tools

mhadaily

Strategic design tools

Tactical

 design tools

mhadaily

Why is Strategic Domain-Driven Design Important?

Strategic

DDD

Decomposing 

mhadaily

Strategic

DDD

Decomposing 

Core Domain

Sub Domains

mhadaily

A Manufacturer App

Sales

Manage Employees

Accounting

Marketing

Product Catalog

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Employees

customer 

id

address

availability

Marketing

customer 

id

name

payment method

 

Accounting

mhadaily

customer 

id

name

interest

0
 Advanced issue found
 

Sales

customer 

id

name

email

phone

Support

customer 

id

address

availability

Order

customer 

id

name

payment method

 

Accounting

Bounded Context

 

 

By

Namespace

Folder

Project

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Employees

Ubiquitous Language

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Employees

customer 

id

address

availability

Marketing

customer 

id

name

payment method

 

Accounting

Context Map

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Employees

customer 

id

address

availability

Marketing

customer 

id

name

payment method

 

Accounting

Shared

Kernel

 

e.g.

USER

Authentication

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Support

customer 

id

address

availability

Order

customer 

id

name

payment method

 

Accounting

Open Host Service

mhadaily

customer 

id

name

interest

Sales

customer 

id

name

email

phone

Support

customer 

id

address

availability

Order

customer 

id

name

payment method

 

Accounting

Open Host Service

API

mhadaily

mhadaily

Navigation

Map

 

by Eric Evans

Flutter

Architecture

mhadaily

Enterprise

Manufacturing App

mhadaily

Sales

Common

Catalog

E-commerce App

mhadaily

Sales

Common

Catalog

E-commerce App

Presentation

Presentation

Presentation

Screen

Logic Holder

Widgets

Smart UI - Feature

Screen

Logic Holder

Smart UI - Feature

BLoC

ChangeNotifier

BLoC

ChangeNotifier

mhadaily

Sales

Common

Catalog

E-commerce App

Presentation

Presentation

Presentation

Application

Application

Application

Use Case Specific Facades

 

Simplify

mhadaily

Sales

Common

Catalog

E-commerce App

Domain

Domain

Domain

Presentation

Presentation

Presentation

Application

Application

Application

Text

Entities

Interfaces

Logic

mhadaily

Object Values

Sales

Common

Catalog

E-commerce App

Domain

Domain

Domain

Infrastructure

Infrastructure

Infrastructure

Presentation

Presentation

Presentation

Application

Application

Application

Text

Remote Data Source

Models

Local Data Source

Geo Location, ... 

Raw Data

Raw Data

Raw Data

Models

Repositories

Sales

Catalog

E-commerce App

Domain

Domain

Infrastructure

Infrastructure

Presentation

Presentation

Application

Application

mhadaily

Sales

Catalog

E-commerce App

Domain

Domain

Infrastructure

Infrastructure

Presentation

Presentation

Application

Application

API

mhadaily

mhadaily

Simpler

Sales

Common

Catalog

E-commerce App

Presentation

Presentation

Screen

 

Logic Holder

BLoC

Widgets

Screen

 

Logic Holder

BLoC

mhadaily

Utils

Sales

Common

Catalog

E-commerce App

Logic

Presentation

Presentation

Presentation

Text

0
 Advanced issue found
 

mhadaily

Logic

Business logic

 

GetLatestNewsWithAuthorsUseCase

Sales

Common

Catalog

E-commerce App

Logic

Data

Presentation

Presentation

Presentation

Text

Remote Data Source

Local Data Source

Geo Location, ... 

Raw Data

Raw Data

Raw Data

Models

Logic

Repositories

Sales

Catalog

E-commerce App

Logic

Data

Presentation

Presentation

Logic

mhadaily

Demo

├── lib
│   ├── catalog
│   │   ├── api
│   │   │   └── index.dart
│   │   ├── application
│   │   │   └── catalog_facade_service.dart
│   │   ├── domain
│   │   │   ├── entities
│   │   │   │   └── product.dart
│   │   │   ├── interfaces
│   │   │   │   └── product_interface.dart
│   │   │   └── logic
│   │   │       ├── catalog_logic.dart
│   │   │       └── get_official_product_manufacturer.dart
│   │   ├── infrastructure
│   │   │   ├── data_sources
│   │   │   │   ├── product_local_data_provider.dart
│   │   │   │   └── product_remote_data_provider.dart
│   │   │   ├── models
│   │   │   │   └── product_model.dart
│   │   │   └── repositories
│   │   │       └── product_repository.dart
│   │   └── presentation
│   │       ├── catalog-detail
│   │       │   ├── bloc
│   │       │   │   ├── bloc.dart
│   │       │   │   ├── catalog_detail_bloc.dart
│   │       │   │   ├── catalog_detail_event.dart
│   │       │   │   └── catalog_detail_state.dart
│   │       │   └── catalog_detail_screen.dart
│   │       ├── catalog-list
│   │       │   ├── bloc
│   │       │   │   ├── bloc.dart
│   │       │   │   ├── catalog_list_bloc.dart
│   │       │   │   ├── catalog_list_event.dart
│   │       │   │   └── catalog_list_state.dart
│   │       │   └── catalog_list_screen.dart
│   │       └── widgets
│   │           └── catalog_name.dart
│   ├── common
│   │   ├── config
│   │   │   └── config.dart
│   │   ├── exceptions
│   │   │   ├── exceptions.dart
│   │   │   ├── local_exceptions.dart
│   │   │   └── server_exceptions.dart
│   │   ├── helpers
│   │   │   └── helpers.dart
│   │   ├── platform
│   │   │   └── connectivity.dart
│   │   ├── utils
│   │   │   └── utils.dart
│   │   └── widgets
│   │       └── widgets.dart
│   ├── injections.dart
│   └── main.dart

mhadaily

Advanced

── catalog
│   ├── logic
│   │   ├── catalog_logic.dart
│   │   ├── get_official_product_manufacturer.dart
│   │   └── product_repository.dart
│   └── presentation
│       ├── catalog-detail
│       │   ├── bloc
│       │   │   ├── bloc.dart
│       │   │   ├── catalog_detail_bloc.dart
│       │   │   ├── catalog_detail_event.dart
│       │   │   └── catalog_detail_state.dart
│       │   └── catalog_detail_screen.dart
│       ├── catalog-list
│       │   ├── bloc
│       │   │   ├── bloc.dart
│       │   │   ├── catalog_list_bloc.dart
│       │   │   ├── catalog_list_event.dart
│       │   │   └── catalog_list_state.dart
│       │   └── catalog_list_screen.dart
│       └── widgets
│           └── catalog_name.dart
├── common
│   ├── config
│   │   └── config.dart
│   ├── exceptions
│   │   ├── exceptions.dart
│   │   ├── local_exceptions.dart
│   │   └── server_exceptions.dart
│   ├── helpers
│   │   └── helpers.dart
│   ├── platform
│   │   └── connectivity.dart
│   ├── utils
│   │   └── utils.dart
│   └── widgets
│       └── widgets.dart
├── data_sources
│   ├── product_local_data_provider.dart
│   ├── product_model.dart
│   └── product_remote_data_provider.dart
├── injections.dart
└── main.dart

mhadaily

Simple

NOT HARD RULES

BUT GUIDANCE

 

 

LET DDD GUIDE US

Summary

mhadaily

Introduction to DDD

1

Flutter architecture inspired by DDD

1

Strategic Domain Driven Design Ideas

1

What we have learned

mhadaily

Majid Hajian

mhadaily

Slides and link to source code

bit.ly/ddd-flutter

majid[at]softiware[dot]com

Strategic Domain-Driven Design for Improving Flutter architecture

By Majid Hajian

Strategic Domain-Driven Design for Improving Flutter architecture

Architecting software, especially on a large-scale where it needs to meet the business requirements is always a challenge and Flutter apps are not an exception. Strategic Domain-Driven Design techniques ensure your application is optimized to support business goals while identifying cohesive modules, known as bounded context which creates a maintainable, comprehensible codebase by isolating dependencies and describe business value. In this talk, I explorer the idea of the ubiquitous language, the bounded context, sub-domains while they are being implemented in a real application. All in all, You'll learn how I attempted to architect a (large-scale) Flutter application by technical solution and appropriate methodology in order to have a sustainable app.

  • 9,665