Project

categoria

0.0
The project is in a healthy, maintained state
categoria presents a set of generators for domain-driven development in rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
~> 5.16
~> 13.0
~> 1.21
~> 0.5
~> 1.2
~> 0.12

Runtime

~> 7.0
~> 2.6
 Project Readme

κατηγορία

i argue that the default way to structure a rails application is bad, and subsequently encourages bad design because components of a logical unit are spread all over the place: in the models directory, the services (the mechanism the rails community seems to have settled on for bundling executive code together), sometimes concerns, etc.

look at discourse, my favorite rails project of all time, and it's almost impossible to figure out the essence of the application. the entries in the app/models directory continues to grow with no end in sight. the relationships between these models—who works with who and in what capacity?—isn't immediately obvious.

categoria fixes this. it regroups data and executive code and separates them along domain lines. it's similar in spirit to phoenix's context. the point of departure is the following:

a category/domain doesn't concern itself with the web part of the application. that is because the web concerns tend to be cross-cutting (across domains). in a controller action, it's possible to invoke several commands from different domains in service of the request. the returned response might also be a combination of data from different domains. in order to allow this freedom, all app components that directly handle web requests can remain in their conventional locations.

what to call controllers? typically they have matched a given model. you have a Document model, here's the DocumentsController. now that the document model is subsumed under a domain of different name, the controller should be allowed to float freely. it could be an interface to a domain, or to several domains at the same time. an appropriate name should be chosen.

directory structure of a domain

domains live under app/lib of the rails application. internally, it is organized into three main categories, represented by directories and ruby module namespaces. all domains are sub-namespaced under the application's main namespace. an initializer is added to override zeitwerk's default behavior of using Object as the root namespace for classes loaded from app/lib.

internal

command

data

Test

the same structure is repeated under the test directory, under universal Test namespace. just so constant loading, in non-test local and remote (prod) environments don't load unnecessary code. the Test namespace should only be loaded in a test environment.