Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update file tree structure #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions src/content/docs/architecture/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@ While providers, routes, and tests, can live in the root backend project, consid

```txt
my_app/
|- api/
| |- lib/
| | |- src/
| | | |- middleware/
| |- packages/
| | |- models/
| | | |- lib/
| | | | |- src/
| | | | | |- endpoint_models/
| | | | | |- shared_models/
| | | |- test/
| | | | |- src/
| | | | | |- endpoint_models/
| | | | | |- shared_models/
| | |- data_source/
| | | |- lib/
| | | | |- src/
| | | |- test/
| | | | |- src/
| |- routes/
| | |- api/
| | | |- v1/
| | | | |- todos/
| | |- test/
| | | |- src/
| | | | |- middleware/
| | | |- routes/
| | | | |- api/
| | | | | |- v1/
| | | | | | |- todos/
└── api/
├── lib/
│ └── src/
│ └── middleware
├── packages/
│ ├── models/
│ │ ├── lib/
│ │ │ └── src/
│ │ │ ├── endpoint_models/
│ │ │ └── shared_models/
│ │ └── test/
│ │ └── src/
│ │ ├── endpoint_models/
│ │ └── shared_models/
│ └── data_source/
│ ├── lib/
│ │ └── src
│ └── test/
│ └── src
└── routes/
├── api/
│ └── v1/
│ └── todos
└── test/
├── src/
│ └── middleware/
└── routes/
└── api/
└── v1/
└── todos/
```

### Models
Expand Down
90 changes: 45 additions & 45 deletions src/content/docs/architecture/barrel_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ For a package, the structure could look something like:

```text
my_package/
|-lib/
| |- src/
| | |- models/
| | | - model_1.dart
| | | - model_2.dart
| | |- widgets/
| | | - widget_1.dart
| | | - widget_2.dart
|- test/...
|- pubspec.yaml
├── lib/
│ └── src/
├── models/
│ ├── model_1.dart
│ └── model_2.dart
└── widgets/
├── widget_1.dart
└── widget_2.dart
├── test/
└── pubspec.yaml
```

And for a feature, it could look like:

```text
my_feature/
|- bloc/
| - feature_bloc.dart
| - feature_event.dart
| - feature_state.dart
|- view/
| - feature_page.dart
| - feature_view.dart
|- widgets/
- widget_1.dart
- widget_2.dart
├── bloc/
│ ├── feature_bloc.dart
│ ├── feature_event.dart
│ └── feature_state.dart
├── view/
│ ├── feature_page.dart
│ └── feature_view.dart
└── widgets/
├── widget_1.dart
└── widget_2.dart
```

In both cases, if we want to use both `widget_1.dart` and `widget_2.dart` in other parts of the app, we will have to import them separately like:
Expand All @@ -58,34 +58,34 @@ A package with barrel files should look like:

```text
my_package/
|-lib/
| |- src/
| | |- models/
| | | - model_1.dart
| | | - model_2.dart
| | | - models.dart
| | |- widgets/
| | | - widget_1.dart
| | | - widget_2.dart
| | | - widgets.dart
| |- my_package.dart
|- test/...
|- pubspec.yaml
├── lib/
│ ├── src/
│ │ ├── models/
│ │ │ ├── model_1.dart
│ │ │ ├── model_2.dart
│ │ │ └── models.dart
│ │ └── widgets/
│ │ ├── widget_1.dart
│ │ ├── widget_2.dart
│ │ └── widgets.dart
│ └── my_package.dart
├── test/
└── pubspec.yaml
```

And for a feature, it should look like:

```text
my_feature/
|- bloc/
| - feature_bloc.dart
| - feature_event.dart
| - feature_state.dart
|- view/
| - feature_page.dart
| - feature_view.dart
| - view.dart
|- my_feature.dart
├── bloc/
│ ├── feature_bloc.dart
│ ├── feature_event.dart
│ └── feature_state.dart
├── view/
│ ├── feature_page.dart
│ ├── feature_view.dart
│ └── view.dart
└── my_feature.dart
```

Finally let's see what these files contain. Continuing with the package example, we have three barrel files: `models.dart`, `widgets.dart` and `my_package.dart`.
Expand Down Expand Up @@ -121,9 +121,9 @@ By convention, blocs are typically broken into separate files consisting of the

```text
bloc/
- feature_bloc.dart
- feature_event.dart
- feature_state.dart
├── feature_bloc.dart
├── feature_event.dart
└── feature_state.dart
```

In this case, we don't add an extra barrel file since the `feature_bloc.dart` file is working as such, thanks to the `part of` directives. You can read more about it in the [bloc documentation][bloc_documentation].
Expand Down
78 changes: 39 additions & 39 deletions src/content/docs/architecture/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,43 @@ Good ✅

```txt
my_app/
|- lib/
| |- login/
| | |- bloc/
| | | - login_bloc.dart
| | | - login_event.dart
| | | - login_state.dart
| | |- view/
| | | - login_page.dart
| | | - view.dart
|- packages/
| |- user_repository/
| | |- lib/
| | | |- src/
| | | | |- models/
| | | | | - models.dart
| | | | | - user.dart
| | | | |- user_repository.dart
| | | - user_repository.dart
| | |- test/
| | | |- models/
| | | | - user_test.dart
| | | - user_repository_test.dart
| |- api_client/
| | |- lib/
| | | |- src/
| | | | - api_client.dart
| | | - api_client.dart
| | |- test/
| | | - api_client_test.dart
|- test/
| |- login/
| | |- bloc/
| | | - login_bloc_test.dart
| | | - login_event_test.dart
| | | - login_state_test.dart
| | |- view/
| | | - login_page_test.test
├── lib/
│ └── login/
├── bloc/
│ ├── login_bloc.dart
│ ├── login_event.dart
│ └── login_state.dart
└── view/
├── login_page.dart
└── view.dart
├── packages/
│ ├── user_repository/
│ │ ├── lib/
│ │ │ ├── src/
│ │ │ │ ├── models/
│ │ │ │ │ ├── models.dart
│ │ │ │ │ └── user.dart
│ │ │ │ └── user_repository.dart
│ │ │ └── user_repository.dart
│ │ └── test/
│ │ ├── models/
│ │ │ └── user_test.dart
│ │ └── user_repository_test.dart
│ └── api_client/
├── lib/
│ ├── src/
│ │ └── api_client.dart
│ └── api_client.dart
└── test/
└── api_client_test.dart
└── test/
└── login/
├── bloc/
├── login_bloc_test.dart
├── login_event_test.dart
└── login_state_test.dart
└── view/
└── login_page_test.dart
```

Each layer abstracts the underlying layers' implementation details. Avoid indirect dependencies between layers. For example, the repository layer shouldn't need to know how the data is fetched in the data layer, and the presentation layer shouldn't directly access values from Shared Preferences. In other words, the implementation details should not leak between the layers. Using layered architecture ensures flexibility, reusability, and testability as the codebase grows.
Expand Down Expand Up @@ -183,9 +183,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
'email': state.email,
'password': state.password,
},
);
);

emit(const LoginSuccess());
emit(const LoginSuccess());
} catch (error, stackTrace) {
addError(error, stackTrace);
emit(const LoginFailure());
Expand Down
39 changes: 19 additions & 20 deletions src/content/docs/testing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,37 @@ This `my_package` library contains `models` and `widgets`. The `test` folder sho

```txt
my_package/
|- lib/
| |- models/
| | - model_a.dart
| | - model_b.dart
| | - models.dart
| |- widgets/
| | - widget_1.dart
| | - widget_2.dart
| | - widgets.dart
|- test/
...
├── lib/
│ ├── models/
│ │ ├── model_a.dart
│ │ ├── model_b.dart
│ │ └── models.dart
│ └── widgets/
│ ├── widget_1.dart
│ ├── widget_2.dart
│ └── widgets.dart
└── test/
```

Bad ❗️

```txt
test/
|- model_a_test.dart
|- model_b_test.dart
|- widgets_test.dart
├── model_a_test.dart
├── model_b_test.dart
└── widgets_test.dart
```

Good ✅

```txt
test/
|- models/
| - model_a_test.dart
| - model_b_test.dart
|- widgets/
| - widget_1_test.dart
| - widget_2_test.dart
├── models/
│ ├── model_a_test.dart
│ └── model_b_test.dart
└── widgets/
├── widget_1_test.dart
└── widget_2_test.dart
```

> Note: `models.dart` and `widgets.dart` are barrel files and do not need to be tested.
Expand Down
8 changes: 4 additions & 4 deletions src/content/docs/theming/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ To keep things organized, fonts are generally stored in an `assets` folder:

```txt
assets/
|- fonts/
| - Inter-Bold.ttf
| - Inter-Regular.ttf
| - Inter-Light.ttf
└── fonts/
├── Inter-Bold.ttf
├── Inter-Regular.ttf
└── Inter-Light.ttf
```

Then declared in the `pubspec.yaml` file:
Expand Down