# Generator for application (or slice)

**URL:** <https://discourse.hanakai.org/t/generator-for-application-or-slice/21>\
**Category:** proposals\
**Created:** [January 19, 2015, 8:20am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21 "2015-01-19T08:20:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlfonsoUceda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alfonsouceda/32/17_2.png) [@AlfonsoUceda](https://discourse.hanakai.org/u/AlfonsoUceda)\
**Post date:** [January 19, 2015, 8:20am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/1 "2015-01-19T08:20:29Z")

</div>

Hi:

It would a good idea create a new command bundle exec lotus add this command will create a new application inside apps folder, e.g:

```
bundle exec lotus generate app admin

```

and then it will create the needed files inside apps folder and it will add the needed code in the route of application, in lib or when it’s needed.

Thoughts?

Original topic: [Lotus add new application for existing application · Issue #140 · hanami/hanami · GitHub](https://github.com/lotus/lotus/issues/140)

---

<div class="post-metadata">

**Author:** ![trung\_le](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/trung_le/32/4_2.png) [@trung\_le](https://discourse.hanakai.org/u/trung_le)\
**Post date:** [January 19, 2015, 8:24am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/2 "2015-01-19T08:24:53Z")

</div>

IMHO we should provide options to choose slice template. There are 2 types of slice that I could think of:

- Web
- API

Default to Web slice and provide `--slice_type` option to specify other type.

---

<div class="post-metadata">

**Author:** ![thecatwasnot](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/thecatwasnot/32/24_2.png) [@thecatwasnot](https://discourse.hanakai.org/u/thecatwasnot)\
**Post date:** [January 20, 2015, 1:13pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/3 "2015-01-20T13:13:37Z")

</div>

I agree. I think we should call it a slice generator tho. I think it’s pretty much there in the code already, it just needs to be hooked to the cli.

```auto
bundle exec lotus generate slice admin
bundle exec lotus generate slice api --type api

```

---

<div class="post-metadata">

**Author:** ![robyurkowski](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/robyurkowski/32/457_2.png) [@robyurkowski](https://discourse.hanakai.org/u/robyurkowski)\
**Post date:** [January 20, 2015, 1:34pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/4 "2015-01-20T13:34:05Z")

</div>

When I was discussing with @AlfonsoUceda earlier, I mentioned my preference for calling it a ‘slice’, so 👍.

---

<div class="post-metadata">

**Author:** ![AlfonsoUceda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alfonsouceda/32/17_2.png) [@AlfonsoUceda](https://discourse.hanakai.org/u/AlfonsoUceda)\
**Post date:** [January 24, 2015, 2:01pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/5 "2015-01-24T14:01:51Z")

</div>

now the generator to create new lotus app doesn’t support param type, should it be added this type param to this generator? because now the kind of slice is web type.

Thoughts?

---

<div class="post-metadata">

**Author:** ![thecatwasnot](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/thecatwasnot/32/24_2.png) [@thecatwasnot](https://discourse.hanakai.org/u/thecatwasnot)\
**Post date:** [January 24, 2015, 2:24pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/6 "2015-01-24T14:24:00Z")

</div>

I think we have 2 different things here. A new container application, that could have an api slice instead of a web one, and adding a slice to an existing container application. Am I right @AlfonsoUceda?

So new application, what about something like?

```bash
bundle exec lotus new chirp --slices admin:web api:api
 =>
chirp/apps/admin
chirp/apps/api

```

Then a slice generator too

`bundle exec lotus generate slice admin --type web`

I don’t think there is a defined api slice type yet.

---

<div class="post-metadata">

**Author:** ![AlfonsoUceda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alfonsouceda/32/17_2.png) [@AlfonsoUceda](https://discourse.hanakai.org/u/AlfonsoUceda)\
**Post date:** [January 25, 2015, 11:46am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/7 "2015-01-25T11:46:24Z")

</div>

the question is, how will it be the api slice? does make sense support two type of slice?

---

<div class="post-metadata">

**Author:** ![trung\_le](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/trung_le/32/4_2.png) [@trung\_le](https://discourse.hanakai.org/u/trung_le)\
**Post date:** [January 25, 2015, 12:07pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/8 "2015-01-25T12:07:40Z")

</div>

a very good question and IMHO I do believe in supporting different type of slice.

As Web Service API has emerged to be a quite popular paradigm. In fact, it is one of the most popular application that companies are using Lotus atm (that includes me). And FYi there is a bit of works and it would not be easy enough for new adopters.

My suggestion is to start with bare metal template with bare minimum numbers of middlewares and default configurations. It is then up to us and users to customise their own slice template.

---

<div class="post-metadata">

**Author:** ![AlfonsoUceda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alfonsouceda/32/17_2.png) [@AlfonsoUceda](https://discourse.hanakai.org/u/AlfonsoUceda)\
**Post date:** [January 25, 2015, 3:08pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/9 "2015-01-25T15:08:24Z")

</div>

then we should work in this api convention to integrate in the new command an later work in the generate slice method.

E.g: support api versioning like grape.

Thoughts?

---

<div class="post-metadata">

**Author:** ![trung\_le](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/trung_le/32/4_2.png) [@trung\_le](https://discourse.hanakai.org/u/trung_le)\
**Post date:** [January 27, 2015, 10:03am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/10 "2015-01-27T10:03:45Z")

</div>

@AlfonsoUceda when I have a chance, I’ll share the tweaked Lotus app for API Web Service.

Regarding versioning, it could be achieved with router, by mount it to different routes, for eg:

```
Lotus::Container.configure do
  mount ApiV1::Application, at: '/api/v1'
  mount ApiV2::Application, at: '/api/v2'
end
```

---

<div class="post-metadata">

**Author:** ![AlfonsoUceda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alfonsouceda/32/17_2.png) [@AlfonsoUceda](https://discourse.hanakai.org/u/AlfonsoUceda)\
**Post date:** [January 27, 2015, 11:20am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/11 "2015-01-27T11:20:02Z")

</div>

@trung_le ok perfect, we’ll let the routher the job 😉

---

<div class="post-metadata">

**Author:** ![thecatwasnot](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/thecatwasnot/32/24_2.png) [@thecatwasnot](https://discourse.hanakai.org/u/thecatwasnot)\
**Post date:** [January 31, 2015, 2:01pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/12 "2015-01-31T14:01:37Z")

</div>

You can even do a cascading version, with [Rack::Cascade](https://github.com/rack/rack/blob/master/lib/rack/cascade.rb)

Are we planning to do controller/view type generators too?

---

<div class="post-metadata">

**Author:** ![trung\_le](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/trung_le/32/4_2.png) [@trung\_le](https://discourse.hanakai.org/u/trung_le)\
**Post date:** [February 10, 2015, 1:25pm UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/13 "2015-02-10T13:25:01Z")

</div>

Yes, we are going to have generator for views/controllers too.

---

<div class="post-metadata">

**Author:** ![trung\_le](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/trung_le/32/4_2.png) [@trung\_le](https://discourse.hanakai.org/u/trung_le)\
**Post date:** [June 29, 2015, 8:47am UTC](https://discourse.hanakai.org/t/generator-for-application-or-slice/21/14 "2015-06-29T08:47:26Z")

</div>


