Code Monkey home page Code Monkey logo

symlex's Introduction

Symlex: A lean framework stack for agile Web development based on Symfony and Vuetify

License: MIT Build Status Documentation GitHub contributors Community Chat Twitter

Symlex aims to simplify agile Web development by providing a working system that promotes best practices by example:

  • Built on top of well documented and tested standard components
  • Contains everything to create full-featured Web applications: Service container, REST routing & Twig template engine
  • Strict use of dependency injection for configuration and bootstrapping
  • Small code and memory footprint
  • Extremely fast compared to other PHP frameworks, especially in combination with RoadRunner

Since its initial release in 2014, it has proven to be well suited for rapidly building microservices, CLI and single-page applications. It comes complete with working examples from testing to forms and database abstraction. Simply delete what you don't need.

The kernel is tiny and only creates a service container for bootstrapping your application within its context. Using a single container for configuration and dependency injection reduces complexity and leads to improved performance compared to other frameworks. It also prevents developers from thoughtlessly installing bundles without understanding them. The result is less bloat and simpler, more maintainable and testable code that is fundamental for agile development.

Plain classes are used wherever possible to avoid vendor lock-in and enable framework independent code reuse. See TRADEOFFS.md.

You can combine the PHP based backend with any JavaScript library or REST client. The front-end boilerplate is there for your convenience and puts you straight on track for building impressive single-page applications with Webpack and Vuetify, see demo.symlex.org. A working example for command line applications is included as well.

Our complete framework documentation can be found on docs.symlex.org. Tuzi Liu maintains a Chinese translation for us.

Note: https://github.com/symlex/symlex-core contains the kernel and routers as reusable components.

Setup

Before you start, make sure you have PHP 7.3+, Composer and Docker installed on your system (howto for Mac OS X). Run get-composer.sh to install composer locally on Linux. Instead of using Docker, you can set up your own runtime environment based on the existing Dockerfile. In addition, you will need a database plus nodejs and npm to build the frontend.

Step 1: Run composer to create a new Symlex project:

composer create-project symlex/symlex myapp

Composer will ask for config values to generate app/config/parameters.yml for you.

Make sure storage/cache is writable so that cache files can be created by the app.

Step 2: Start RoadRunner and MariaDB using docker-compose:

cd myapp
docker-compose up

Note: This configuration is for testing and development purposes only, see comments in docker-compose.yml for details. You might need to tweak it if you run Docker with a different user for security reasons. On OS X, the current release of Docker is really slow in executing PHP from the host's file system. docker-compose up -d runs Docker in the background, but you won't see helpful log messages in this case.

Step 3: Let Make initialize the database and build the front-end components for you:

make terminal
make all database

To verify everything is working, run make test.

Note: You can also use this approach to execute other CLI commands later. Make should be pre-installed in typical Unix development environments - otherwise you might have to get it first e.g. by installing the Xcode Command Line Tools on OS X via xcode-select --install or by adding the build-base or build-essential package on Linux. The Makefile contains a list of all targets.

After successful installation, open the site at http://localhost:8081/ and log in as [email protected] using the password passwd.

YAML files located in app/config configure the app based on parameters and services. The main config files are app/config/web.yml and app/config/console.yml.

If you add localhost-debug to your /etc/hosts and access the site with that, it will load in debug mode (you'll see a stack trace and other debug information on the error pages).

The mailhog user interface is available at http://localhost:8025/. It can be used to receive and view mails automatically sent by the system, e.g. when new users are created.

If you want to build a more light-weight app, have a look at our other examples:

Full documentation: https://docs.symlex.org/en/latest/framework/

Login Screen

RoadRunner

Symlex now includes RoadRunner - a high-performance PHP application server - as an alternative to NGINX. It will be automatically downloaded when you build the Docker image.

Our installation instructions for Symlex >= 4.4.0 won't work for previous releases as they still use NGINX and PHP-FPM. Instead of web and php, there is now a single app service powered by RoadRunner. If you prefer NGINX, you can use an older release or copy the previous config to the new release. Some of our example apps use NGINX as well.

About

Symlex is maintained by Michael Mayer and aims to simplify agile Web development by providing a working system that promotes best practices by example. Michael released his first PHP framework in 2001 and has worked with various major framework vendors in the past. Building this would not have been possible without a lot of prior work by other developers. Thank you to those and everyone who contributed!

Choice is the enemy of productivity. Put another way, if your solution does everything, and has no opinions about anything, then it solves nothing. โ€• Asim Aslam

Feel free to send an e-mail to [email protected] if you have any questions, need commercial support or just want to say hello. We welcome contributions of any kind. If you have a bug or an idea, read our guide before opening an issue.

Performance

It's obvious that PHP framework performance mainly depends on the lines of code that have to be executed for each request. While Symlex was designed to be simple and lean, a good performance is a very important by-product of this approach.

The best code is no code. Where there is no code, there are no bugs. No API to learn. No awkward UI. The best refactors are deletions. โ€• Eric Elliott

As published by phpbenchmarks.com, REST requests are more than 40% faster compared to other common PHP frameworks:

Response times of popular PHP frameworks

Note that these response times were measured in fully optimized production mode on fast server hardware with only 5 concurrent requests. In practice, differences might be much larger in terms of absolute time. Memory consumption should be considered as well:

Memory footprint of popular PHP frameworks

Why should you care? First, your users will love it. As a rule of thumb, 100 ms is about the limit for having them feel that the system is reacting instantaneously, meaning that no special feedback is necessary except to display the result. The total response time also includes network (~25 ms), browser and other overhead, which only leaves a small fraction of those 100 ms for implementing the actual business logic. Second, you'll save a lot of money for server infrastructure and developers are more productive as tests are running faster.

Relationship with Symfony and Silex

Symlex was started in 2014 as a simple Silex boilerplate, since Silex itself doesn't come with a "Standard Edition" that points you in the right direction. Using Silex instead of Symfony was recommended by SensioLabs (the creators of both frameworks) as a light-weight alternative to Symfony + FOSRestBundle for quickly building high-performance REST services and single-page Web applications.

It was soon noticed that Pimple - the service container that comes with Silex - feels cumbersome for developers coming from Symfony and makes it hard to reuse existing code. In addition, many Silex code examples and even real-world applications accessed the service container from all parts of the code (not only the framework itself), which circumvents inversion of control and leads to awkward testability. Symlex therefore promotes the strict use of dependency injection and combines the convenience of a full-fledged service container with the speed of a micro-framework.

Today, Symlex has its own routing component (based on Symfony 4) and does not use Silex anymore. The framework has proven to be useful for a large number of different applications. Some of them were based on the regular Symfony kernel before and did the change because they were drowning in complexity and suffered from response times well above 30 seconds in development mode. Symlex brought them back on track without big changes to their existing code base.

Micro-Kernel Architecture

Donations

Symlex is a non-profit project run entirely by volunteers. You're most welcome to support us via GitHub Sponsors, especially if you need help with using our software. They will match every donation in the first year.

Please leave a star if you like this project, it provides additional motivation to keep going. Thank you very much! <3

symlex's People

Contributors

graciousgrey avatar lastzero avatar mbezhanov 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

symlex's Issues

Installation: Mismatch between code and documentation

There is no dev.xml , only build.xml, and running it will report syntax error.
After running 'docker-compose up' and 'docker-compose exec php sh'.

/var/www/html # bin/phing build
Buildfile: /var/www/html/build.xml

App > build:


App > build-database:

Are you sure you wish to drop the database "web"? (y/n)y
Database "web" dropped
Database "web" created
Loading configuration from file: migrations.yml

Parse error: syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST) in /var/www/html/vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php on line 29
[phingcall] /var/www/html/build.xml:33:96: Task exited with code 255

BUILD FAILED
/var/www/html/build.xml:25:43: Execution of the target buildfile failed. Aborting.

And running ' make terminal ' didn't work too.
make: *** No rule to make target 'terminal'. Stop.

File name incorrect

In main.js is the line:

text: 'lib/requirejs-text'

but that is invalid. In the lib folder are:

require.js
require-text.js

Documentation: information about working with middlewares

Most modern routers provide a system for working with middlewares for common tasks ranging from authentication to CORS and other custom needs. I wasn't able to find any kind of information about middlewares with the Symlex router. Is it possible to amend the documentation?

Docker: Improve config to fix permission problems with different users

As a developer, I want the Docker (Compose) configuration to work with different users so that I don't run into permission problems.

One developer recently had issues running our example because storage/cache was not writable by the app, see community chat.

Running chmod -R 777 storage fixed the issue. Git doesn't allow to create files with 666 or 777, only 644 or 755 - and it's good like that. Instead we should find a way to run Docker with the same user that the files belong to so that the cache directory is writable without changing permissions to 777.

A pull request for our Docker config would be really amazing if some entrypoint magic can fix it.

Please provide demo app without docker overhead

This looks very interesting! However, t would be much easier to get into this framework if I could run the demo just from a local dev server without docker, sqlite instead of mysql and no redis. It woud be great to have such a demo that is easy to use without infrastructure gymnastics!

Not enough information about Authentication and Authorization

The demo app screenshots show some basic user management, however there is not enough information about how to implement authenticaion and authorization with this framework - while browsing the docs I found one single page about "Interceptors" that seem to be related to this, but I am not able to find that page again, it was hidden in some very specific library description and not where I am expecting it. Auth & Auth are most important parts of a framework and should have a very prominent place in the documentation - it would be great to better understand how to implement:

  • handling of roles / groups / permissions e.g. in a RBAC-like schema
  • object-level security ("only edit my posts") in the controller, the view and the database layer
  • login / logout / "remember me" / several authentication schemas like e.g. oauth with social auth providers
  • controllers, models and security in a way that makes sense with the framework paradigm

Also an extended example app (that only needs php, nothing else!) would be a great way to better understand your approach to these important things.

Thank you very much for your attention!

Some questions.

First of all, thank you for sharing this. You really did a good job. However, I ripped out all the AngularJS stuff because the current version will become unsupported. And I just don't want to be dependent on something so big and evasive and changing. So here are my questions:

  • Registration page: I cannot seem to find any kind of registration or sign up page. Am I just missing it, was it intentionally left out, is that planned for the future, or am I just supposed to make my own?
  • When I go to the /users I get page not found. Is that because I messed something up?
  • When I go to the root page / the nav bar displays but not the body. I know this is because I removed AngularJS so
    will no longer work. So what is a good way to get the body in that spot without Angular?

Thank you again for a fine framework.

Not enoug information about how to use migrations

I can see in the framework docs that there are some "migration" commands - but there is no documentation about how to actually use these migrations. Is there something that creates models? Something like the symfony maker bundle? I guess that maker bundle itself will not be compatible.
Is this the exact same thing like symfony migrations?

Not enough information about how to handle complex model relations

One more thing: currently I am not sure I can interpolate from the existing docs how I would implement a complex form with multiple models involved with this framework - it would be very interesting to see a real life example with multiple model relations, as the ultra-simplistic examples in the docs give no opportunity to show how to work with your framework in a more realistic scenario. Of course with auth and auth :)

Thanks again and I hope this will become a very popular alternative to other frameworks - looks very promising!

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.