Coder Social home page Coder Social logo

Comments (34)

rob006 avatar rob006 commented on July 19, 2024 7

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.

from yii-base-api.

rob006 avatar rob006 commented on July 19, 2024 6

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024 4

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

That's probably a very good idea.

from yii-base-api.

axtho avatar axtho commented on July 19, 2024 1

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

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024 1

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024 1

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

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024 1

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.

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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

from yii-base-api.

rustamwin avatar rustamwin commented on July 19, 2024

I think need do it via lite(core) version

from yii-base-api.

lukos avatar lukos commented on July 19, 2024

@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?

from yii-base-api.

roslov avatar roslov commented on July 19, 2024

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).

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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)

from yii-base-api.

roslov avatar roslov commented on July 19, 2024

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

from yii-base-api.

roslov avatar roslov commented on July 19, 2024

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.

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

@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

from yii-base-api.

lukos avatar lukos commented on July 19, 2024

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?

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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.

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

I'd no tie this to composer.

Why not?

from yii-base-api.

lukos avatar lukos commented on July 19, 2024

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?

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

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

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

how do you run them without composer?

Why should you?

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

OK. How do you see it?

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

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

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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.

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

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

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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

from yii-base-api.

lukos avatar lukos commented on July 19, 2024

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?

from yii-base-api.

schmunk42 avatar schmunk42 commented on July 19, 2024

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

@samdark I can not close this issue, btw

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

@schmunk42 should it be closed?

from yii-base-api.

razonyang avatar razonyang commented on July 19, 2024

Is it has been finished?

from yii-base-api.

samdark avatar samdark commented on July 19, 2024

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

from yii-base-api.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.