Coder Social home page Coder Social logo

lucidarch / laravel Goto Github PK

View Code? Open in Web Editor NEW
376.0 33.0 68.0 530 KB

[DEPRECATED] See https://github.com/lucidarch/lucid

Home Page: https://lucidarch.dev

PHP 82.24% Shell 0.74% Blade 17.02%
laravel scalable-applications lucid-architecture microservices-architecture php microservices software-architecture software-engineering software-philosophy architecture

laravel's Introduction

Lucid

The Lucid Architecture is a software architecture that consolidates code-base maintenance as the application scales, from becoming overwhelming to handle, gets us rid of rotting code that will later become legacy code, and translate the day-to-day language such as Feature and Service into actual, physical code.

Read more about the Lucid Architecture Concept.

If you prefer a video, watch the announcement of The Lucid Architecture at LaraconEU 2016:

The Lucid Architecture for Building Scalable Applications - Laracon EU 2016

Abed Halawi - The Lucid Architecture for Building Scalable Applications

Join The Community on Slack

Slack Status

Index

Installation

8.x

To start your project with Lucid right away, run the following command:

composer create-project lucid-arch/laravel my-project

This will give you a Laravel 8 installation with Lucid out-of-the-box. If you wish to download other versions of Laravel you may specify it as well:

7.x

composer create-project lucid-arch/laravel=7.x my-project-7.x
6.x
composer create-project lucid-arch/laravel=6.x my-project-6.x
5.5
composer create-project lucid-arch/laravel=5.5.x my-project-5.5

Introduction

Directory Structure

src
├── Data
├── Domains
    └── * domain name *
            ├── Jobs
├── Foundation
└── Services
    └── * service name *
        ├── Console
        ├── Features
        ├── Http
        ├── Providers
        ├── Tests
        ├── database
        └── resources

Components

Component Path Description
Service src/Service/[service] Place for the Services
Feature src/Services/[service]/Features/[feature] Place for the Features of Services
Job src/Domains/[domain]/Jobs/[job] Place for the Jobs that expose the functionalities of Domains
Data src/Data Place for models, repositories, value objects and anything data-related
Foundation src/Foundation Place for foundational (abstract) elements used across the application

Service

Each part of an application is a service (i.e. Api, Web, Backend). Typically, each of these will have their way of handling and responding to requests, implementing different features of our application, hence, each of them will have their own routes, controllers, features and operations. A Service will seem like a sub-installation of a Laravel application, though it is just a logical grouping than anything else.

To better understand the concept behind Services, think of the terminology as: "Our application exposes data through an Api service", "You can manipulate and manage the data through the Backend service".

One other perk of using Lucid is that it makes the transition process to a Microservices architecture simpler, when the application requires it. See Microservices.

Service Directory Structure

Imagine we have generated a service called Api, can be done using the lucid cli by running:

You might want to Setup to be able to use the lucid command.

lucid make:service api

We will get the following directory structure:

src
└── Services
    └── Api
        ├── Console
        ├── Features
        ├── Http
        │   ├── Controllers
        │   ├── Middleware
        │   ├── Requests
        │   └── routes.php
        ├── Providers
        │   ├── ApiServiceProvider.php
        │   └── RouteServiceProvider.php
        ├── Tests
        │   └── Features
        ├── database
        │   ├── migrations
        │   └── seeds
        └── resources
            ├── lang
            └── views
                └── welcome.blade.php

Feature

A Feature is exactly what a feature is in our application (think Login feature, Search for hotel feature, etc.) as a class. Features are what the Services' controllers will serve, so our controllers will end up having only one line in our methods, hence, the thinnest controllers ever! Here's an example of generating a feature and serving it through a controller:

You might want to Setup to be able to use the lucid command.

IMPORTANT! You need at least one service to be able to host your features. In this example we are using the Api service generated previously, referred to as api in the commands.

lucid make:feature SearchUsers api

And we will have src/Services/Api/Features/SearchUsersFeature.php and its test src/Services/Api/Tests/Features/SearchUsersFeatureTest.php.

Inside the Feature class, there's a handle method which is the method that will be called when we dispatch that feature, and it supports dependency injection, which is the perfect place to define your dependencies.

Now we need a controller to serve that feature:

lucid make:controller user api

And our UserController is in src/Services/Api/Http/Controllers/UserController.php and to serve that feature, in a controller method we need to call its serve method as such:

namespace App\Services\Api\Http\Controllers;

use App\Services\Api\Features\SearchUsersFeature;

class UserController extends Controller
{
    public function index()
    {
        return $this->serve(SearchUsersFeature::class);
    }
}

Views

To access a service's view file, prepend the file's name with the service name followed by two colons ::

Example extending view file in blade:

@extends('servicename::index')

Usage with jobs is similar:

new RespondWithViewJob('servicename::user.login')

RespondWithJsonJob accepts the following parameters:

RespondWithViewJob($template, $data = [], $status = 200, array $headers = []);

Usage of template with data:

$this->run(new RespondWithViewJob('servicename::user.list', ['users' => $users]));

Or

$this->run(RespondWithViewJob::class, [
    'template' => 'servicename::user.list',
    'data' => [
        'users' => $users
    ],
]);

Job

A Job is responsible for one element of execution in the application, and play the role of a step in the accomplishment of a feature. They are the stewards of reusability in our code.

Jobs live inside Domains, which requires them to be abstract, isolated and independent from any other job be it in the same domain or another - whatever the case, no Job should dispatch another Job.

They can be ran by any Feature from any Service, and it is the only way of communication between services and domains.

Example: Our SearchUsersFeature has to perform the following steps:

  • Validate user search query
  • Log the query somewhere we can look at later
  • If results were found
    • Log the results for later reference (async)
    • Increment the number of searches on the found elements (async)
    • Return results
  • If no results were found
    • Log the query in a "high priority" log so that it can be given more attention

Each of these steps will have a job in its name, implementing only that step. They must be generated in their corresponding domains that they implement the functionality of, i.e. our ValidateUserSearchQueryJob has to do with user input, hence it should be in the User domain. While logging has nothing to do with users and might be used in several other places so it gets a domain of its own and we generate the LogSearchResultsJob in that Log domain.

To generate a Job, use the make:job <job> <domain> command:

lucid make:job SearchUsersByName user

Similar to Features, Jobs also implement the handle method that gets its dependencies resolved, but sometimes we might want to pass in input that doesn't necessarily have to do with dependencies, those are the params of the job's constructor, specified here in src/Domains/User/Jobs/SearchUsersByNameJob.php:

namespace App\Domains\User\Jobs;

use Lucid\Foundation\Job;

class SearchUsersByNameJob extends Job
{
    private $query;
    private $limit;

    public function __construct($query, $limit = 25)
    {
        $this->query = $query;
        $this->limit = $limit;
    }

    public function handle(User $user)
    {
        return $user->where('name', $this->query)->take($this->limit)->get();
    }
}

Now we need to run this and the rest of the steps we mentioned in SearchUsersFeature::handle:

public function handle(Request $request)
{
    // validate input - if not valid the validator should
    // throw an exception of InvalidArgumentException
    $this->run(new ValidateUserSearchQueryJob($request->input()));

    $results = $this->run(SearchUsersJob::class, [
        'query' => $request->input('query'),
    ]);

    if (empty($results)) {
        $this->run(LogEmptySearchResultsJob::class, [
            'date' => new DateTime(),
            'query' => $request->query(),
        ]);

        $response = $this->run(new RespondWithJsonErrorJob('No users found'));
    } else {
        // this job is queueable so it will automatically get queued
        // and dispatched later.
        $this->run(LogUserSearchJob::class, [
            'date' => new DateTime(),
            'query' => $request->input(),
            'results' => $results->lists('id'), // only the ids of the results are required
        ]);

        $response = $this->run(new RespondWithJsonJob($results));
    }

    return $response;
}

As you can see, the sequence of steps is clearly readable with the least effort possible when following each $this->run call, and the signatures of each Job are easy to understand.

A few things to note regarding the implementation above:

  • There is no difference between running a job by instantiating it like $this->run(new SomeJob) and passing its class name $this->run(SomeJob::class) it is simply a personal preference for readability and writing less code, when a Job takes only one parameter it's instantiated.
  • The order of parameters that we use when calling a job with its class name is irrelevant to their order in the Job's constructor signature. i.e.
$this->run(LogUserSearchJob::class, [
    'date' => new DateTime(),
    'query' => $request->input(),
    'resultIds' => $results->lists('id'), // only the ids of the results are required
]);
class LogUserSearchJob
{
    public function __construct($query, array $resultIds, DateTime $date)
    {
        // ...
    }
}

This will work perfectly fine, as long as the key name ('resultIds' => ...) is the same as the variable's name in the constructor ($resultIds)

  • Of course, we need to create and import (use) our Job classes with the correct namespaces, but we won't do that here since this is only to showcase and not intended to be running, for a working example see Getting Started.

Data

Data is not really a component, more like a directory for all your data-related classes such as Models, Repositories, Value Objects and anything that has to do with data (algorithms etc.).

Foundation

This is a place for foundational elements that act as the most abstract classes that do not belong in any of the components, currently holds the ServiceProvider which is the link between the services and the framework (Laravel). You might never need or use this directory for anything else, but in case you encountered a case where a class needs to be shared across all components and does belong in any, feel free to use this one.

Every service must be registered inside the foundation's service provider after being created for Laravel to know about it, simply add $this->app->register([service name]ServiceProvider::class); to the register methods of the foundation's ServiceProvider. For example, with an Api Service:

// ...
use App\Services\Api\Providers\ApiServiceProvider;
// ...
public function register()
{
    $this->app->register(ApiServiceProvider::class);
}

Getting Started

This project ships with the Lucid Console which provides an interactive user interface and a command line interface that are useful for scaffolding and exploring Services, Features, and Jobs.

Setup

The lucid executable will be in vendor/bin. If you don't have ./vendor/bin/ as part of your PATH you will need to execute it using ./vendor/bin/lucid, otherwise add it with the following command to be able to simply call lucid:

export PATH="./vendor/bin:$PATH"

For a list of all the commands that are available run lucid or see the CLI Reference.

Launching the Interactive Console (UI)

  1. Serve Application One way is to use the built-in server by running:
php artisan serve

Any other method would also work (Apache, Nginx, etc...)

  1. Run php artisan vendor:publish --provider="Lucid\Console\LucidServiceProvider"
  2. Visit your application at /lucid/dashboard

1. Create a Service

CLI
lucid make:service Api
UI

Using one of the methods above, a new service folder must've been created under src/Services with the name Api.

The Api directory will initially contain the following directories:

src/Services/Api
├── Console         # Everything that has to do with the Console (i.e. Commands)
├── Features        # Contains the Api's Features classes
├── Http            # Routes, controllers and middlewares
├── Providers       # Service providers and binding
├── database        # Database migrations and seeders
└── resources       # Assets, Lang and Views

One more step is required for Laravel to recognize the service we just created.

Register Service

  • Open src/Foundation/Providers/ServiceProvider
  • Add use App\Services\Api\Providers\ApiServiceProvider
  • In the register method add $this->app->register(ApiServiceProvider::class)

2. Create a Feature

CLI
lucid make:feature ListUsers api
UI

Using one of the methods above, the new Feature can be found at src/Services/Api/Features/ListUsersFeature.php. Now you can fill up a bunch of jobs in its handle method.

3. Create a Job

This project ships with a couple of jobs that can be found in their corresponding domains under src/Domains

CLI
lucid make:job GetUsers user
UI

Using one of the methods above, the new Job can be found at src/Domains/User/Jobs/GetUsers and now you can fill it with functionality in the handle method. For this example we will just add a static return statement:

public function handle()
{
    return [
        ['name' => 'John Doe'],
        ['name' => 'Jane Doe'],
        ['name' => 'Tommy Atkins'],
    ];
}

4. All Together

Back to the Feature we generated earlier, add $this->run(GetUsersJob) (remember to use the job with the correct namespace App\Domains\User\Jobs\GetUsersJob).

Run The Job

In ListUsersFeature::handle(Request $request)

public function handle(Request $request)
{
    $users = $this->run(GetUsersJob::class);

    return $this->run(new RespondWithJsonJob($users));
}

The RespondWithJsonJob is one of the Jobs that were shipped with this project, it lives in the Http domain and is used to respond to a request in a structured JSON format.

Serve The Feature

To be able to serve that Feature we need to create a route and a controller that does so.

Generate a plain controller with the following command

lucid make:controller user api --plain

Add the get method to it:

class UserController extends Controller
{
    public function get()
    {
        return $this->serve(ListUsersFeature::class);
    }
}

We just need to create a route that would delegate the request to our get method:

In src/Services/Api/Http/routes.php you will find the route group Route::group(['prefix' => 'api'], function() {... Add the /users route within that group.

Route::get('/users', 'UserController@get');

Now if you visit /api/users you should see the JSON structure.

Microservices

If you have been hearing about microservices lately, and wondering how that works and would like to plan your next project based on microservices, or build your application armed and ready for the shift when it occurs, Lucid is your best bet. It has been designed with scale at the core and the microservice transition in mind, it is no coincidence that the different parts of the application that will (most probably) later on become the different services with the microservice architecture are called Service. However, it is recommended that only when your monolith application grow so large that it becomes crucial to use microservices for the sake of the progression and maintenance of the project, to do the shift; because once you've built your application using Lucid, the transition to a microservice architecture will be logically simpler to plan and physically straight-forward to implement. There is a microservice counterpart to Lucid that you can check out here.

With more on the means of transitioning from a monolith to a microservice.

Event Hooks

Lucid exposes event hooks that allow you to listen on each dispatched feature, operation or job. This is especially useful for tracing:

use Illuminate\Support\Facades\Event;
use Lucid\Foundation\Events\FeatureStarted;
use Lucid\Foundation\Events\OperationStarted;
use Lucid\Foundation\Events\JobStarted;

Event::listen(FeatureStarted::class, function (FeatureStarted $event) {
    // $event->name
    // $event->arguments
});

Event::listen(OperationStarted::class, function (OperationStarted $event) {
    // $event->name
    // $event->arguments
});

Event::listen(JobStarted::class, function (JobStarted $event) {
    // $event->name
    // $event->arguments
});

laravel's People

Contributors

adiachenko avatar adibhanna avatar arnoudhgz avatar dependabot[bot] avatar harris21 avatar imrealashu avatar jbaron-mx avatar kohlerdominik avatar mulkave avatar sharik709 avatar speccode avatar vitoo avatar websmurf avatar zeraist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel's Issues

composer install --no-dev fails

When I create new Lucid project

composer create-project lucid-arch/laravel test-lucid

and run

cd test-lucid/
composer install --no-dev

It fails with error

In ProviderRepository.php line 208:

Class 'Lucid\Console\LucidServiceProvider' not found

Lucid\Console\LucidServiceProvider class is used in config https://github.com/lucid-architecture/laravel/blob/master/config/app.php#L164
and specified as dev dependency https://github.com/lucid-architecture/laravel/blob/master/composer.json#L21

I expect dev dependencies not to be used in production code and config.
What is preferred way this issue to be solved?

Problem when trying to use Factories

i couldn't load database factories located in [ src/Services/{serviceName}/Database/factories ],

the Illuminate\Database\Eloquent\Factory class has a static constructor, i tried to change the factory paths by placing the below inside my ServiceProvider::register() function

$faker =  new Faker;
$this->app->singleton(Factory::class, function () use ($faker) {
      return Factory::construct($faker, realpath(__DIR__.'/../Database/factories'));
});

now the factories are available but for some reason faker stopped working properly, giving Unknown formatter "xx" errors

Error while executing Unittests

Hi there,

Based on your presentatie we started to build an application using the Lucid principe.
I'm running into an issue while executing the unittests from the services.

The error I'm getting is:

adam@mpb-adam api (master) $ vendor/bin/phpunit
PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

III.PHP Fatal error:  Cannot declare class Lucid\Console\Controller, because the name is already in use in /Users/adam/Sites/customers.dev/api/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 107
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:763
Stack trace:
#0 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/adam/Sit in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 763

Fatal error: Cannot declare class Lucid\Console\Controller, because the name is already in use in /Users/adam/Sites/customers.dev/api/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 107

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:763
Stack trace:
#0 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/adam/Sit in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 763

I've narrowed it down to /vendor/lucid-arch/laravel-console/src/Http/routes.php, there is a class "Controller" defined there. The unit tests load this file more than one time, resulting in the duplicate class error. Any thoughts on how to resolve this?

Lucid Dashboard not showing

Hello,

Did a fresh 5.6 installation by following the Getting Started instructions, but can't get the Lucid Dashboard to show by visiting the /lucid/dashboard page, it is throwing a 404 page instead, looks like the routes are not being registered.

  • Working on Homestead 6.4
  • Clean installation, no services/features were added.

Any idea on where to look first?

Should feature depend on a Request object?

Hi Abed! Just watched your great talk on LaraconEU and one thing keeps jumping in my head.

Should Feature really depend on Http Request?
I mean there might be different cases where we want to call the feature (for example from console command). I always thought of Controllers as adapters between HTTP world and internal business logic.

What is your opinion on that?

I'd say there can be some decoupling like this:

class SomeFeature() extends Feature {
    public function handle($input_data) {}
}

...

class SomeController extends Controller {
    public function some(Request $request) {
        // pass request payload as an input to a feature
        $data = $this->serve(SomeFeature::class, $request->all());
        return Response::json($data);
    }
}

PHP Notice: Constant DS already defined

I have a project that has 2 packages installed that are using this constant:

  • Lucid
  • Arcanedev log viewer

Even though it is just a notice, what should I do to prevent this?

PHP Notice:  Constant DS already defined in /var/www/html/vendor/lucid-arch/laravel-console/src/Finder.php on line 23
PHP Stack trace:
PHP   1. {main}() /var/www/html/vendor/lucid-arch/laravel-console/lucid:0
PHP   2. spl_autoload_call() /var/www/html/vendor/lucid-arch/laravel-console/lucid:19
PHP   3. Composer\Autoload\ClassLoader->loadClass() /var/www/html/vendor/lucid-arch/laravel-console/lucid:19
PHP   4. Composer\Autoload\includeFile() /var/www/html/vendor/composer/ClassLoader.php:322
PHP   5. include() /var/www/html/vendor/composer/ClassLoader.php:444
PHP   6. spl_autoload_call() /var/www/html/vendor/lucid-arch/laravel-console/src/Commands/ChangeSourceNamespaceCommand.php:27
PHP   7. Composer\Autoload\ClassLoader->loadClass() /var/www/html/vendor/lucid-arch/laravel-console/src/Commands/ChangeSourceNamespaceCommand.php:27
PHP   8. Composer\Autoload\includeFile() /var/www/html/vendor/composer/ClassLoader.php:322
PHP   9. include() /var/www/html/vendor/composer/ClassLoader.php:444
PHP  10. define() /var/www/html/vendor/lucid-arch/laravel-console/src/Finder.php:23

Note: Prior to updating Lucid to Laravel 6, this will cause PHP Error instead of just a notice. What I did before is I commented the constant value to make it work (inside the vendor. Yes I know it is not good, but I have to make it work)

Namespace in lucid "make" command

Please add an option to set namespace when creating file like: controller, job, etc. In artisan we can do like this: php artisan make:controller "Catalog\ProductController", then this file will be located on app\Http\Controllers\Catalog\ProductController.php. Can we do it on lucid command which is similar to the artisan command?

Thank you.

InvalidInputException returns wrong status code

Hi, InvalidInputException should return status code 422 and not 500.
5XX are server errors and 4XX are client errors. I get this status when I validate user input...
As I can see there is no way to set status code on your Validator class

How to use Domain/Queue?

I see class AbstractQueue, but i dont see code example for use it.
Can you help me show demo ?

5.1, 5.2, 5.3 and 5.4 installation not working

Hello,

I've been testing out the Installation section and found out it is failing for Laravel 5.1, 5.2, 5.3 and 5.4. It is throwing the following error message

Your requirements could not be resolved to an installable set of packages.

CLI output for 5.1 installation:

vagrant@homestead:~/Code$ composer create-project lucid-arch/laravel=5.1.x lucid51
Installing lucid-arch/laravel (v5.1.5)
  - Installing lucid-arch/laravel (v5.1.5): Loading from cache
Created project in lucid51
> php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install symfony/console v3.1.10
    - Conclusion: don't install laravel/framework v5.3.31
    - Conclusion: don't install laravel/framework v5.3.30
    - Conclusion: don't install laravel/framework v5.3.29
    - Conclusion: don't install laravel/framework v5.3.28
    - Conclusion: don't install laravel/framework v5.3.27
    - Conclusion: don't install laravel/framework v5.3.26
    - Conclusion: don't install laravel/framework v5.3.25
    - Conclusion: don't install laravel/framework v5.3.24
    - Conclusion: don't install laravel/framework v5.3.23
    - Conclusion: don't install laravel/framework v5.3.22
    - Conclusion: don't install laravel/framework v5.3.21
    - Conclusion: don't install laravel/framework v5.3.20
    - Conclusion: don't install laravel/framework v5.3.19
    - Conclusion: don't install laravel/framework v5.3.18
    - Conclusion: don't install laravel/framework v5.3.17
    - Conclusion: don't install laravel/framework v5.3.16
    - Conclusion: don't install laravel/framework v5.3.15
    - Conclusion: don't install laravel/framework v5.3.14
    - Conclusion: don't install laravel/framework v5.3.13
    - Conclusion: don't install laravel/framework v5.3.12
    - Conclusion: don't install laravel/framework v5.3.11
    - Conclusion: don't install laravel/framework v5.3.10
    - Conclusion: don't install laravel/framework v5.3.9
    - Conclusion: don't install laravel/framework v5.3.8
    - Conclusion: don't install laravel/framework v5.3.7
    - Conclusion: don't install laravel/framework v5.3.6
    - Conclusion: don't install laravel/framework v5.3.5
    - Conclusion: don't install laravel/framework v5.3.4
    - Conclusion: don't install laravel/framework v5.3.3
    - Conclusion: don't install laravel/framework v5.3.2
    - Conclusion: don't install laravel/framework v5.3.1
    - Conclusion: don't install symfony/console v3.1.9
    - Conclusion: don't install symfony/console v4.1.7
    - Installation request for laravel/framework 5.3.* -> satisfiable by laravel/framework[v5.3.0, v5.3.1, v5.3.10, v5.3.11, v5.3.12, v5.3.13, v5.3.14, v5.3.15, v5.3.16, v5.3.17, v5.3.18, v5.3.19, v5.3.2, v5.3.20, v5.3.21, v5.3.22, v5.3.23, v5.3.24, v5.3.25, v5.3.26, v5.3.27, v5.3.28, v5.3.29, v5.3.3, v5.3.30, v5.3.31, v5.3.4, v5.3.5, v5.3.6, v5.3.7, v5.3.8, v5.3.9].
    - Conclusion: don't install symfony/console v4.1.6
    - Conclusion: don't install symfony/console v3.1.1|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Conclusion: don't install symfony/console v3.1.2|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Conclusion: don't install symfony/console v3.1.3|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Conclusion: don't install symfony/console v3.1.4|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Conclusion: don't install symfony/console v3.1.5|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Conclusion: don't install symfony/console v3.1.6|install symfony/console v4.1.6|install symfony/console v4.1.7
    - Installation request for lucid-arch/laravel-console dev-master -> satisfiable by lucid-arch/laravel-console[dev-master].
    - Conclusion: don't install symfony/console v3.1.7|install symfony/console v4.1.6|install symfony/console v4.1.7
    - lucid-arch/laravel-console dev-master requires symfony/console ^4.0 -> satisfiable by symfony/console[v4.0.0, v4.0.1, v4.0.10, v4.0.11, v4.0.12, v4.0.13, v4.0.14, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7].
    - Can only install one of: symfony/console[v4.0.0, v3.1.0].
    - Can only install one of: symfony/console[v4.0.1, v3.1.0].
    - Can only install one of: symfony/console[v4.0.10, v3.1.0].
    - Can only install one of: symfony/console[v4.0.11, v3.1.0].
    - Can only install one of: symfony/console[v4.0.12, v3.1.0].
    - Can only install one of: symfony/console[v4.0.13, v3.1.0].
    - Can only install one of: symfony/console[v4.0.14, v3.1.0].
    - Can only install one of: symfony/console[v4.0.2, v3.1.0].
    - Can only install one of: symfony/console[v4.0.3, v3.1.0].
    - Can only install one of: symfony/console[v4.0.4, v3.1.0].
    - Can only install one of: symfony/console[v4.0.5, v3.1.0].
    - Can only install one of: symfony/console[v4.0.6, v3.1.0].
    - Can only install one of: symfony/console[v4.0.7, v3.1.0].
    - Can only install one of: symfony/console[v4.0.8, v3.1.0].
    - Can only install one of: symfony/console[v4.0.9, v3.1.0].
    - Can only install one of: symfony/console[v4.1.0, v3.1.0].
    - Can only install one of: symfony/console[v4.1.1, v3.1.0].
    - Can only install one of: symfony/console[v4.1.2, v3.1.0].
    - Can only install one of: symfony/console[v4.1.3, v3.1.0].
    - Can only install one of: symfony/console[v4.1.4, v3.1.0].
    - Can only install one of: symfony/console[v4.1.5, v3.1.0].
    - laravel/framework v5.3.0 requires symfony/console 3.1.* -> satisfiable by symfony/console[v3.1.0, v3.1.1, v3.1.10, v3.1.2, v3.1.3, v3.1.4, v3.1.5, v3.1.6, v3.1.7, v3.1.8, v3.1.9].
    - Conclusion: don't install symfony/console v3.1.8|install symfony/console v4.1.6|install symfony/console v4.1.7

The problem seems to be introduced since the dependencies got updated in the lucid-arch/laravel-console repo. Commit 6abdcc3.

What would be the best approach to take?

  1. Update the composer.json for the branches 5.1, 5.2, 5.3 and 5.4 by locking up the lucid-arch/laravel-console dependency to 5.5.*. Currently it is set to dev-master. Tested out and it worked. Let me know and I can submit the PR.
  2. Forget about the older versions and only support from 5.5 from now on.

Data and migrations

I feel like there is a lack of database migration support in Lucid.

  1. There is a folder within each service called database where I can see database/migration but the data is also located in Data folder. How do those relate to each other?
  2. lucid does not have any way to make a migration (while it has a make:model command). Why?

Laravel 5.6

Hi Dears!
The upgrade to Laravel 5.6 is on the roadmap?

Regards!

What to test exactly in a FeatureTest

Hi there,

Just wondering about the following. What exact do you advise to test while testing a feature?
The response of the feature? Or if all steps that are defined are being called?

Best regards

Adam

Event based execution flow and Lucid Features

I wonder how Lucid architecture describes event based business logic.
How does event handling lays into Lucid paradigm?

For example both CreateNormalAccountFeature and CreateVipAccountFeature create a new account. Let's say, later we decided to have a notification about new accounts. One way is to insert "sendNotificationJob" into each Feature, the other is to hook an event "account_created" and send notification then.

What is your opinion about event based execution?

The requested package lucid-arch/laravel-foundation ^7.0 exists as lucid-arch/laravel-foundation ...

Hello. Try to install new project, use commad
composer create-project lucid-arch/laravel my-project
and get error

Problem 1
- The requested package lucid-arch/laravel-foundation ^7.0 exists as lucid-arch/laravel-foundation[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.2, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev, 6.0.x-dev, dev-master, v5.1.0, v5.1.1, v5.2.0, v5.2.1, v5.3.0, v5.3.1, v5.3.2, v5.3.3, v5.3.4, v5.4.0, v5.4.1, v5.4.3, v5.4.4, v5.5.0, v5.5.1, v5.5.2, v5.5.3, v5.5.4, v5.6.0, v5.6.1, v5.6.2, v5.6.3, v5.7.0, v5.7.1, v5.8.0, v5.8.1, v6.0.0] but these are rejected by your constraint.

I use php 7.4.5, please help

It does not seem to work

Unfortunately it doesn't seem to work correctly. When following the instructions from the README I'm getting "BadMethodCallException in Controller.php line 79: Method [dispatchFromArray] does not exist."

I wanted to start a new project because everything has sound so good at your Laracon EU talk. But it seems like lucid isn't production ready yet, isn't it?

API versioning

Is working with multiple versions of api supported?
/api/v1/users
/api/v2/users

`TypeError: this.$els.jobCodeDialog.showModal is not a function` when viewing a Domain job code

Summary

In the browser developer tools console, there is an error: TypeError: this.$els.jobCodeDialog.showModal when viewing a Domain job code. Viewing of code in Services and Features also does not work.

Steps to Reproduce:

  • composer create-project lucid-arch/laravel my-project
  • cd my-project
  • php artisan vendor:publish --provider="Lucid\Console\LucidServiceProvider"
  • In the browser, go to '/lucid/dashboard/domains' > Http > Respond With Json Error > Click the Code.

Expected Result

It should display a modal showing the code of the selected Job

Actual Result

TypeError: this.$els.jobCodeDialog.showModal is not a function when viewing a Domain job code

State

  • Laravel version: 5.6
  • OS: Win10
  • XAMPP stack using vhost

Factories - model class not found

I am currently writing test code for one of my project and in need to use factories.

composer.json (autoload block):

"autoload": {
    "classmap": [
        "database",
        "database/factories"
    ],
    "psr-4": {
        "Framework\\": "app/",
        "App\\": "src/",
        "Tests\\": "tests/"
    }
},

Company model (located at src/Data/Company.php)

<?php
namespace App\Data;
use Illuminate\Database\Eloquent\Model;

class Company extends Model

Company factory (located at app/database/factories/CompanyFactory.php)

<?php
use Faker\Generator as Faker;

$factory->define(App\Data\Company::class, function (Faker $faker) { //updated
    return [
        'trade_name' => $faker->name,
        'address' => $faker->address,
        'country' => $faker->country,
    ];
});

Test code (located at tests/Feature/Register.php)

public function test_something()
{
    $company = factory(App\Data\Company::class)->create(); //updated

   dd($company);die;
}

I am getting Error: Class 'Company' not found

Note:

  • However, if I move the src/Data/Company.php to app/Company.php and change the namespace, it works.
  • Factories works for User if I use factories('Framework\User')->raw(); and will not work if I use factories('Framework\User')->create();

My issues:

  • How to make it work (factories and model) with Lucid default setting (Or I can update some settings if required to make it work correctly)
  • Should I move it to the app/? If yes, then lucid make:model <name> is creating model in src/Data/
  • Should I create the factory under src/Services/<name>/database/factories instead?

Your helps is very much appreciated. Thank you

Passing arguments to a template from a Controller

Hi,
First of all, thanks for a great library and architecture definition.

I have just started applying this architecture. Currently, I am trying to figure out how to pass some arguments from a Controller to a template.

Consider, we have a BaseController class and it has the getMenuItems method, some other controllers may override this method to provide additional items.

public function getMenuItems() {
	return [];
}

In controller I pass a feature class to the serve method:

public function homePage() {
	return $this->serve( HomePageDashboardFeature::class, $this->getMenuItems());
}

However this doesn't work.

Maybe I am doing something wrong, but I am trying to move all common functionality into base classes.

I can create a base Feature and move all these methods there, however not sure whether this will be the right decision.

What is a better way to handle such cases?

Thanks.

laravel/helpers dependency missing

I recently started a migration of a laravel project to lucid, so I ran the composer require lucid-arch/laravel-foundation lucid-arch/laravel-console command.

When I tried to generate a service with the lucid make:service web command, it gave a PHP Fatal error: Uncaught Error: Call to undefined function Lucid\Console\studly_case() error.

I fixed it by adding the dependency laravel/helpers to my project. I think you can use the Str Laravel helpers to do that instead of that dependency. If you can't modify the code, maybe you can add the dependency to your packages so the migrations can be done more smoothly.

Incompatiblity with Laravel8-ModelFactories

Hi there

Is the Boilerplate incompatbile with Laravel8 ModelFactories?

The reworked implementation guesses Factory-Names by default. It takes the Container-Namespace and strips it from the Model-Class, then prepends it it with the new path.

But because in Lucid, the Container lives in \Framework namespaces, while Models live in \App-Namespace, the Namespace gets not stripped correctly. Sure, its possible to overwrite that, but it's not very convenient.


From Factoy.php::704:

$appNamespace = static::appNamespace();
// $appNamespace = "Framework"

$modelName = Str::startsWith($modelName, $appNamespace.'Models\\')
    ? Str::after($modelName, $appNamespace.'Models\\')
    : Str::after($modelName, $appNamespace);
// $modelName = "App\Data\Models\User"

return static::$namespace.$modelName.'Factory';
// return = "Database\Factories\App\Data\Models\UserFactory"

how do I use @extend blade function?

What I am asking is. Like normally we extend our page to master blade page. How do I extend service views to layouts/master folder which is inside of service's resource view folder.

Is this project active??

Hello!

I really enjoy this project, and woud like to know is it still active??

Any other documentation apat from github and the video from laracon?

Thanks.

Laravel 5.5

Hello.
Any future plan abaut update to laravel 5.5?
I really need this! 👍

Method [dispatchFromArray] does not exist.

BadMethodCallException in Controller.php line 107:
Method [dispatchFromArray] does not exist.

I'm checking DispathcesJobs trait and this method doesn't exist. I've installed 5.2.x

How about GraphQL and CommandBus?

Hi, thanks for the god job!
I'm considering LUCID adoption, but my current app uses GraphQL and CommandBus (via Tacitian). I'm wondering how these pieces come in the LUCID architecture. Any suggestions?
Thanks,
Ely

New way of installing Lucid

N.B. There's a change coming next month to the way you install Lucid into a project which will get us rid of waiting for an upgrade of this boilerplate. It will be as simple as composer require lucid-arch/cli then lucid init which can be run into an existing project as well!

Hi @Mulkave , please can you tell us when this way of installing Lucid will be available ?

How to use a middleware inside src/Services/SomeService/Http/Middleware folder?

Hi, I created a middleware that is inside the src/Services/MyService/Http/Middleware folder, but when I try to use it the application says

Class Framework\Http\Middleware\Something does not exist

Is this supposed to happen? The Service is registered on src/Foundation/ServiceProvider.php, is it necessary to do anything else in order to use the middlewares?

Thanks.
And by the way, good job with this repository it is an excellent idea.

Upgrade to laravel 5.4

After watching the talk on Laracan Amsterdam I was really excited to use lucid for our next application. Unfortunately Lucid is is not yet build to be compatible with laravel 5.4. Could lucid be upgraded to use laravel 5.4?

How to inject dependencies from the IoC Container

Hi,

I have the following problem. I've defined a repository interface and an implementation as follows:

interface UserRepositoryContract extends BaseRepository {
	function getAllUsers();
}

And in the service provider, I register this repository as a singleton:

class DataRepositoriesProvider extends ServiceProvider {
	/**
	 * Register services.
	 *
	 * @return void
	 */
	public function register() {
		$this->app->singleton( UserRepositoryContract::class, UsersRepository::class );
	}

}

But how to inject these dependencies into a Feature or a Job. When I try to inject via a constructor, I get the following error:

Unable to map parameter [userRepository] to command [App\Services\Web\Features\Admin\HomePageDashboardFeature]

But these dependencies are successfully injected into controllers and controllers' actions.
What is the right way to inject dependencies?
I have found only one solution to create a Feature manually passing all required dependencies like that:

public function homePage( UserRepositoryContract $usersRepository ) {
	return $this->serve( HomePageDashboardFeature::class, [ 'usersRepository' => $usersRepository ] );
}

Is it fine to do in that way?

I would be grateful for any comments and suggestions!

Object of class could not be converted to string

Hi,

Found this by accident.

MarshalTrait.php, Line 61

throw new Exception("Unable to map parameter [{$parameter->name}] to command [{$command}]");

when I hit this line received following error

Object of class could not be converted to string

I suspect that it complains about $command

Thanks

How to introduce Lucid architecture into an existing project?

Hello guys!

I'm starting with Lucid and would like some tips on how to add it to an existing project. How do I add the Lucid library to an existing project? How do I add the Lucid console to an existing project? I would like at the moment to use Lucid just for new features and gradually go refactoring the code to adhere to the architecture. Remembering that the project is monolithic and the idea is that Lucid facilitate a possible change to architecture microservice.

Thank you.

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.