# Architectual question: Engine with all common models

**URL:** <https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929>\
**Category:** Rails\
**Created:** [April 7, 2009, 3:02pm UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929 "2009-04-07T15:02:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [April 7, 2009, 3:02pm UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929/1 "2009-04-07T15:02:40Z")

</div>

I am maintaining a large Rails application, that consists of several  
“interfaces”:

1. The web interface (figures)
2. Import of data from external providers
3. Export of data to a large range of customers

It seems to me quite bloated to have all the code from 2) and 3) inside  
the web-application, since they functionally have nothing in common. The  
only reason for them being there, is that they also need the business  
rules implemented in the models.

Enter Rails 2.3 and Engines…

I am thinking about restructuring the application the following way, and  
my question regards whether this is a sound idea.

i) Make a Rails engine, consisting only of all models, that are shared  
by two or more of the above “interfaces”

ii) Split my current application into 3 seperate applications - each  
only containing what is nessecary for its own uses:

1a) Web interface should only keep: Controllers, Views, Mailer-“models”  
(and other dependent files in e.g. lib)  
2a) Import of data should only keep code needed for the import  
3) Same as 2a)

All three of them should then add the “model-engine” in their vendor  
folder.

I am not sure if Engines were meant to be used like this - but somehow  
it fits in my mind. Any thoughts on this?

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [April 12, 2009, 11:46am UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929/2 "2009-04-12T11:46:04Z")

</div>

I allow myself to bump this question just once, since I believe, that it  
is quite relevant at the moment, considering the release of Rails 2.3

- Carsten

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [April 13, 2009, 1:45am UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929/3 "2009-04-13T01:45:35Z")

</div>

Carsten G. wrote:

> I am maintaining a large Rails application, that consists of several  
> “interfaces”:
> 
> 1. The web interface (figures)
> 2. Import of data from external providers
> 3. Export of data to a large range of customers
> 
> It seems to me quite bloated to have all the code from 2) and 3) inside  
> the web-application, since they functionally have nothing in common. The  
> only reason for them being there, is that they also need the business  
> rules implemented in the models.  
> […]  
> ii) Split my current application into 3 seperate applications - each  
> only containing what is nessecary for its own uses:  
> […]

I am not 100% sure that I’m correctly understanding the current  
structure of your app, but if I am, my advice is this: you have one  
application, accessible through multiple channels. Keep it that way –  
since it’s one application, it probably shouldn’t be broken down any  
further from the user’s point of view. Just keep everything modularized  
well enough that the interfaces don’t have much coupling to the models.

(Of course, Phlip is liable to say something totally different, and if  
he does, you should definitely listen to him, not me.)

## Best,

Marnen Laibow-Koser  
removed\_email\_address@domain.invalid  
[http://www.marnen.org](http://www.marnen.org)

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [April 13, 2009, 4:20am UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929/4 "2009-04-13T04:20:12Z")

</div>

One issue with splitting the application into 3 will be consistency of  
deployment. If the models in the engine change you need to at a  
minimum run all the tests in all 3 systems, and possibly make updates,  
then find the time to deploy all 3. I know these situations are  
solvable, but I don’t think it’s worth introducing them if you strive  
to keep all your interfaces (web, import, export) well separated. You  
could add something like app/importers and app/exporters and treat  
them like “controllers” for the alternate interfaces. Also, the use of  
modules and namespaces can be useful for situations likes this.

On Apr 12, 6:45 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![tuktuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tuktuk](https://www.ruby-forum.com/u/tuktuk)\
**Post date:** [April 13, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/architectual-question-engine-with-all-common-models/164929/5 "2009-04-13T14:05:26Z")

</div>

Marnen:

> you have one application, accessible through multiple channels.  
> Keep it that way – since it’s one application

Andrew:

> One issue with splitting the application into 3 will be  
> consistency of deployment  
> You could add something like app/importers and app/exporters  
> and treat them like “controllers” for the alternate interfaces.

These are good points, both of you, and they made me think some more  
about the layout of my application.

What really bothers me is that, right now, all import code is started by  
executing “script/runner Janitor.perform\_daily\_tasks”, where Janitor is  
a class defined in the model folder. This means, that the “Janitor code”  
is automatically loaded by Rails, adding code to each mongrel that has  
nothing to do with the web interface.

I think I will try to convince my colleague, that do the app/importers &  
app/exporters approach. It seems the right way.

Thanks a bunch both of you.

- Carsten
