← Graph

Namespace-Based Folder Hierarchy

concept 2 connections

Ivan Nemytchenko's recommendation: instead of flat folders, create namespaces based on entity dependencies (loosely related to aggregate roots) and bounded contexts. Models that don't make sense without a parent (e.g. Comment without Article) become Article::Comment and live inside an article/ folder. Top-level controller namespaces separate waves of usage (web, API, RSS feeds, PDF reports) and bounded contexts (e.g. Web::Moderation::ArticlesController vs Web::ArticlesController). Rails supports this fully — worst case is specifying class_name on the first model. Must be done from day one because retrofitting forces dealing with renames. Benefits: zero internal cost, mirrors URL structure, removes conditional logic per wave/context, exposes what the application is about on the top level.

category
practice
about
Namespace-Based Folder Hierarchy concept
Recommended alternative to flat folders for both models and controllers.
recommends
Namespace-Based Folder Hierarchy concept
Core recommendation to structure models and controllers via namespaces from day one.

Provenance

Read by
12 extractions