Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Initial design considerations #1

Closed
samdark opened this issue Jun 22, 2018 · 34 comments
Closed

Initial design considerations #1

samdark opened this issue Jun 22, 2018 · 34 comments

Comments

@samdark
Copy link
Member

samdark commented Jun 22, 2018

No description provided.

@schmunk42
Copy link

Do we really need this or can we handle it via yiisoft/app? See also yiisoft/yii2-app-basic#184 (comment)

@rustamwin
Copy link
Member

I think need do it via lite(core) version

@lukos
Copy link

lukos commented Jun 26, 2018

@schmunk42 what is your worry about having a separate template? For me, having something specific is much more desirable than something trying to do all things, otherwise they are not really templates.

@rustamwin Can you link to the lite version and what that is so I can see?

@roslov
Copy link

roslov commented Jun 26, 2018

It would be good to have separate templates:

  • for API services,
  • web services (here I mean main site or admin panel),
  • CLI (e. g. cron jobs, message queue listeners).

@schmunk42
Copy link

My experience is that whether you have an API, CLI or web-site your application (eg. models, components, modules, ...) account for most of the code.

I.e. all web-applications also have CLI commands, eg. yii migrate. Not necessarily an API, but nowadays it's also very likely - and as said above the API often also uses your application models. API projects also come with CLI commands.

So it boils down to three "entrypoints" for your application:

  • / (serving HTML)
  • /api (serving JSON or XML)
  • yii (CLI)

@roslov
Copy link

roslov commented Jun 26, 2018

I'm talking about microservice architecture where each service is absolutely independent from other components. @schmunk42, you are talking about monolith app.

@roslov
Copy link

roslov commented Jun 27, 2018

It’s often needed a service which 1) takes data from message queue channel, 2) does some conversion / processings / sending emails or push notifications, and so on, 3) sends data to another message queue channel.

There is no need in any endpoints other than CLI there. It should have very simple skeleton but with logs, tests, init and other Yii app functionality.

The same is about API app — mostly it has to serve API endpoints and send / get data from other services via internal API or message queue. Here also CLI needed but just for basic things like migrations.

Web app has much different structure and more visual components than API app.

So definitely all these three app types will be used for absolutely different purposes.

Now to create such services I have either to create a new microservice app from scratch (manually adding logs, tests, caches), or use “advanced” app and then remove all obsolete things (like backend or frontend namespaces) from there. Both these options take time, and prevent me from using updates, improvements or bugfixes for “advanced” or “basic” apps.

@schmunk42
Copy link

schmunk42 commented Jun 27, 2018

@roslov I agree in several points, currently there are way too many files in the app template, IMHO.

That's why I created a proposal here yiisoft/app#41

There will be always trade-offs, but nonetheless I think the above PR would be a step in the right direction.

CC: @yiisoft/core-developers @yiisoft/reviewers

@axtho
Copy link

axtho commented Jun 27, 2018

Having worked on angular for a while I found the approach that NRWL takes quite helpful. Maybe that would be something Yii could also offer, a workspace, where you have one vendor and cli folder that all possible "apps" would pull from, if needed.

A structure could look like this then:

-- /bin (with yii.php)
-- /apps
---- /web
---- /api
---- /vue-comp (all the JS stuff)
-- /libs (what is now modules, things that any of the apps can rely on, abstraction of core logic)
-- /vendor
-- /config (all of the common config stuff, each app can then have its own set, if needed)
-- composer.json
-- /node-modules (if one uses js dev somewhere in the apps)
-- package.json

Currently we are working on a software that started with template from kartik-v. We moved and deleted stuff ... now we are switching slowly to vuejs components, so there is a need for api controllers. I think this mix of pure php "web" and more api-driven code may become more common now.

Just my two cents worth :)

EDIT:
Thinking even further ... Yii could offer, as part of the cli, the option to start with a specific template, say, Yii-Vue or Yii-Advanced or Yii-jquery or whatever. The CLI would then create the necessary folders and add assets, etc.

E.g. yii app/create yii-vue

@rob006
Copy link

rob006 commented Jun 27, 2018

Actually I would prefer one modular template with everything (separate endpoints for backend, frontend, api, console) and some initial script which will ask 2-3 questions and remove unnecessary parts of template.

@samdark
Copy link
Member Author

samdark commented Jun 27, 2018

ask 2-3 questions and remove unnecessary parts of template.

That's probably a very good idea.

@lukos
Copy link

lukos commented Jun 27, 2018

I was just considering the same thing, we get to have a single source for the template but still allow correct customisation. For example, you could ask the dev if they want cookies enabled or not and modify the config appropriately.

Is this easy enough to do directly with Composer or would there be an easier way? Perhaps run a Yii console command after installing with Composer?

@schmunk42
Copy link

In addition to the above I'd like to see something like:

composer require yiisoft/yii2-bootstrap4
*** register asset-bundle***

...to get a theme.

composer require yiisoft-contrib/yii2-user

or

composer require 2amigos/yii2-usuario

to install a user-module.

@schmunk42
Copy link

Is this easy enough to do directly with Composer or would there be an easier way?

I'd no tie this to composer.

Perhaps run a Yii console command after installing with Composer?

A console command which is part of the framework would be great.

@samdark
Copy link
Member Author

samdark commented Jun 27, 2018

I'd no tie this to composer.

Why not?

@lukos
Copy link

lukos commented Jun 27, 2018

What do we want the script to configure for the developer?

  1. API or not
  2. Web app or not
  3. CLI or not
  4. Cookies enabled/disabled
  5. API uses modules for versioning or not
  6. Some module choice such as rbac, caching etc.

We can start with a simple set and see whether Composer can handle it. The script should be able to delete unrequired folders/files, modify config files and modify composer require. Anything else?

@samdark
Copy link
Member Author

samdark commented Jun 27, 2018

https://github.com/yiisoft/yii2-composer is a good example of what could be tied to Composer.

@schmunk42
Copy link

I'd no tie this to composer.
Why not?

Because composer's task is to install packages, not to prepare the project and its environment.
And script hooks in composer are hard to debug, how do you run them without composer?
If they fail your package installation process might fail also.

@samdark
Copy link
Member Author

samdark commented Jun 28, 2018

how do you run them without composer?

Why should you?

@schmunk42
Copy link

Why should you?

Because I don't want to bake the setup of my application into the package manager, as said above.
Because different environments might require slightly different setups.
Even if there is a postCreateProject hook (I made the PR once) you can't even modify what it is doing until you got the project code and ran it.

The question is more, why should we use composer for that? I also don't think yii2-composer is a good example of what could be tied to composer; with exception of the extensions part, since it's directly related to application packages, but not setting permissions or copying files.

@samdark
Copy link
Member Author

samdark commented Jun 28, 2018

OK. How do you see it?

@schmunk42
Copy link

For application setup I'd like to see a console command as part of the framework, see yiisoft/app-api#1 (comment)

composer create-project yiisoft/app
vendor/bin/yii app/init

* Asking questions like mentioned above...

We're using make for several of those tasks, but I think it might not be portable enough across different platforms.

@samdark
Copy link
Member Author

samdark commented Jun 28, 2018

Does it make sense to re-run that init command after install is done?

@schmunk42
Copy link

Does it make sense to re-run that init command after install is done?

Sure, for debugging or in case you have removed a folder like runtime. A CLI command is much better suited for that, than composer-hooks triggering class methods - how would you run those manually?

There is also difference between interactive setups (eg. first time project creation) and non-interactive ones for deployments.

@samdark
Copy link
Member Author

samdark commented Jun 28, 2018

You'll never deploy a template. It's always interactive.

@schmunk42
Copy link

We are talking about multiple tasks here:

  • interactive template setup (remove unneeded folders)
  • application setup (create folders, set permissions and copy config files)
  • environments management

@rob006
Copy link

rob006 commented Jun 28, 2018

I don't think we should bloat framework core with commands for app initialization. We could create separate composer package, which will provide commands for this task. These commands can be triggered by composer or manually.

After initialization package could be just removed. But with good design it could be used event after initialization, for example to add separate endpoint to existing application.

@lukos
Copy link

lukos commented Jul 8, 2018

So is everyone agreed that we will start by creating something with Composer and an interactive shell and see if we can get that to work?

@samdark
Copy link
Member Author

samdark commented Jul 8, 2018

Yep, I think that's the way to go.

@schmunk42
Copy link

Basic design considerations expound here yiisoft/yii-base-web#45 (comment)

@samdark I can not close this issue, btw

@samdark
Copy link
Member Author

samdark commented Aug 28, 2018

@schmunk42 should it be closed?

@schmunk42
Copy link

schmunk42 commented Aug 28, 2018

I think so, installation is done via composer require yiisoft/yii-base-api it's clear that this application will not have any assets or CLI commands.

@razonyang
Copy link

Is it has been finished?

@samdark
Copy link
Member Author

samdark commented Dec 30, 2018

The template? No. But we agreed on how to proceed with it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants