Coder Social home page Coder Social logo

lajavel's Introduction

Lajavel: A Student MVC / ADR web framework

logo

latest release badge github stars badge github forks badge

latest commit to main badge

github open issues badge github open prs badge

Lajavel is a project given to students to deepen their knowledge in object-oriented programming.

It is an attempt at a framework with the particularity of not following the conventional MVC architecture design pattern but rather the ADR pattern.

Note: This project is a student project

Table of Contents

  1. Installation
  2. Getting started
  3. Features
  4. Graphic design
  5. Further Reading

Installation

Git clone this project.

Getting started

To start the server simply write :

Application.start(8080);

Then you can register any route you want :

public class MyApp {
    public static void main(String[] args) {
        Application.start(7070);
        // Register route through MVC pattern
        Route.register(HttpVerb.GET, "/", IndexController.class, "index");
        // Register route through ADR pattern
        Route.register(HttpVerb.GET, "/html/search", ShowBookAction.class, ShowBookHtmlResponder.class);
        Route.register(HttpVerb.GET, "/api/search", ShowBookAction.class, ShowBookApiResponder.class);

    }
}

ADR pattern

Action

To create an action you must extend the Action class as follows :

public class IndexAction extends Action {

    public IndexAction(Responder responder, Context context) {
        super(responder, context);
    }

    @Override
    public void execute(Context context) {
        //Here you can call all the entities you want
        //Then you must pass this objects to the responder, like this :
        //Book book = BookRepository.getOneBook();
        //this.responder.define(book);
        this.responder.respond();
    }
}

Responder

The response function is what the server will respond to. In this function you can change the response as much as you want. The View.make() function fetches the HTML file from the resources/views folder.

public class IndexResponder extends Responder {

    public IndexResponder(Context context) {
        super(context);
    }

    @Override
    public void respond() {
        this.context.html(View.make("index"));
    }

}

MVC pattern

Once you have registered your controller through the route you can create it as follows :

public class IndexController extends Controller {
    public void index(Context context) {
        context.html(View.make("index"));
    }
}

The method name must be the same as the route you registered, and you must have a context parameter.

Don't forget to create the index.html file in the resources/views folder.

Features

  • HTML Template engine

Graphic design

List of colors used in this projects :

Color Color Color Color

Further Reading

Action–domain–responder (ADR) is a software architectural pattern that was proposed by Paul M. Jones as a refinement of Model–view–controller (MVC) that is better suited for web applications. He explain it as follows:

classDiagram
Domain <|-- Action
Responder <|-- Action
Action <.. Domain

Action Domain Responder organizes a single user interface interaction between an HTTP client and a HTTP server-side application into three distinct roles.

Action Domain Responder is an alternative to the "Model 2" misappropriation (for server-side over-the-network request/response interfaces) of the original Model View Controller user interface pattern (for client-side in-memory graphical user interfaces). ADR is a user interface pattern specifically intended for server-side applications operating in an over-the-network, request/response environment.

Aligning expectations and factoring concerns away from the modern derivations of "Model 2" MVC toward Action Domain Responder is not difficult. Here is one way of working through the change in approach.

Components

Action is the logic to connect the Domain and Responder. It invokes the Domain with inputs collected from the HTTP Request, then invokes the Responder with the data needed to build an HTTP Response.

Domain is an entry point to the domain logic forming the core of the application. It may be a Transaction Script, Service Layer, Application Service, or something similar.

Responder is the presentation logic to build an HTTP Response using data it receives from the Action. It deals with status codes, headers and cookies, content, formatting and transformation, templates and views, and so on.

You can find the rest of this explanation on the repository of Paul M. Jones.

lajavel's People

Contributors

damiendabernat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

benji22ben

lajavel's Issues

Add a landing page to the starter kit

We can add a landing page to the starter kit to show how to use the framework.
We can also use this landing page has official landing page of Lajavel.

Add asset annotation to the HTML template engine ?

Like twig :

The asset() function's main purpose is to make the application more portable. If your application lives at the root of your host (e.g. https://example.com), then the rendered path should be /images/logo.png. But if your application lives in a subdirectory (e.g. https://example.com/my_app), each asset path should render with the subdirectory (e.g. /my_app/images/logo.png). The asset() function takes care of this by determining how your application is being used and generating the correct paths accordingly.

{# the image lives at "public/images/logo.png" #}
<img src="{{ asset('images/logo.png') }}" alt="Symfony!"/>

{# the CSS file lives at "public/css/blog.css" #}
<link href="{{ asset('css/blog.css') }}" rel="stylesheet"/>

{# the JS file lives at "public/bundles/acme/js/loader.js" #}
<script src="{{ asset('bundles/acme/js/loader.js') }}"></script>

Template engine documentation

There is currently no documentation for the template engine.

In the getting started part, maybe we could add some information about the usage of the template engine?

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.