From fat controllers to use cases
Rails (API) app that shows different kinds of architecture (one per commit), and in the last one, how to use the Micro::Case gem to handle the application business logic.
Rails (API) app that shows different kinds of architecture (one per commit), and in the last one, how to use the Micro::Case gem to handle the application business logic. The project is written primarily in Ruby, first published in 2019. Key topics include: architecture, clean-architecture, concerns, domain-objects, fat-controller.
From fat controllers to use cases
Rails (API) app that shows different kinds of architecture (one per commit), and in the last one, how to use the Micro::Case gem to handle the application business logic.
Instructions to run this application
- Ruby version:
2.6.5 - System dependencies:
sqlite3 - Configuration and database creation:
bin/setup - How to run the test suite:
bin/rails test
The different kinds of architecture (project versions)
| Version | Description | Rubycritic Score |
|---|---|---|
| 1 | Fat controller | 91.53 |
| 2 | Fat model, skinny controller | 87.45 |
| 3 | Concerns | 89.25 |
| 4 | Service objects | 92.55 |
| 4.1 | Service objects - Inheritance | 92.93 |
| 4.2 | Service objects - Inheritance overusing | 93.15 |
| 5 | Interactors | 96.36 |
| 6 | Domain objects | 94.71 |
| 7 | Use cases (Micro::Case) | 94.97 |
| 7.1 | Use cases - Dryer version | 95.24 |
| 7.2 | Use cases- Improving the SRP | 95.11 |
Hint: in any of the versions above, use bin/rails rubycritic to see the full report result.
Extra: How to list all the use cases?
Use the use_cases task. e.g:
shbin/rails use_cases # Lines: # 11 ./app/models/user/register/step/serialize_as_json.rb # 12 ./app/models/user/register/step/validate_password.rb # 17 ./app/models/user/register/step/create_record.rb # 19 ./app/models/user/register/step/normalize_params.rb # 10 ./app/models/user/register/flow.rb # 18 ./app/models/todo/list/add_item.rb # 16 ./app/models/todo/list/complete_item.rb # 14 ./app/models/todo/list/delete_item.rb # 12 ./app/models/todo/list/fetch_items.rb # 14 ./app/models/todo/list/find_item.rb # 19 ./app/models/todo/list/update_item.rb # 16 ./app/models/todo/list/activate_item.rb # 21 ./app/models/todo/serialize.rb # 199 total # # Files: 13
Note: This task will only be available in the branches with use cases (v7, v7.1, v7.2).
Contributors
Showing top 1 contributor by commit count.
