Skip to content

Commit

Permalink
Migration to lighttouch app
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-zam committed Jan 29, 2019
1 parent c91b9e9 commit a00aa59
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.mp
/contentdb
/third-party
/log
65 changes: 65 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p align="center"><img width="100" src="https://i.imgur.com/zwjfmrF.png" alt="lighttouch logo"><br>This Project is Currently in Stealth Mode.<br>please do not post a news story until v0.1 is released very shortly.<br>thank you.</p>

<p align="center">
<a href="https://github.com/foundpatterns/lighttouch/issues"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=" alt="Contributions Welcome"></a>
<a href="https://discord.gg/b6MY7dG"><img src="https://img.shields.io/badge/chat-on%20discord-7289da.svg" alt="Chat"></a>
</p>

Lighttouch is a framework that makes complex application development simpler. It does this through broad use of [component-oriented design](https://en.wikipedia.org/wiki/Component-based_software_engineering) intended to offer programmers a well-researched alternative to starting with a blank canvas - "put your code anywhere".

[Code organized](https://en.wikipedia.org/wiki/Structured_programming) this way is:
- easier to program
- unlimited in its reusability of implementations
- easier to extend with other developers' plugins
- possible to socially cross-pollenate diverse and complex applications
- possible to use as a base for [visual programming environments](https://en.wikipedia.org/wiki/Visual_programming_language)

Without this, applications tend to:
- get walled into handling only a single use case
- grow, but at huge cost and pain while extending
- repetively [make messy mistakes](https://news.ycombinator.com/item?id=18443327), like [spaghetti code](http://wiki.c2.com/?SpaghettiCode) and [code duplication](http://wiki.c2.com/?DuplicatedCode)
- suffer too many layers of abstraction

Below you'll learn what is ECA-Rules, but to begin let's start with a simple diagram from the [Drupal Rules module](https://drupal.org/project/rules), a project which greatly influenced this one.

<img src="https://dev.acquia.com/sites/default/files/blog/rules_eca.png" alt="ECA-Rules diagram">

### Lighttouch Packages

Packages are Lighttouch's main unit of addon functionality. They leverage [event-driven](https://en.wikipedia.org/wiki/Event-driven_programming), [rule-based](https://en.wikipedia.org/wiki/Rule-based_system) programming. This basically means that packages have actions, events, and rules. Events are like [hooks](https://stackoverflow.com/questions/467557/what-is-meant-by-the-term-hook-in-programming) where additional logic can run. Rules check a conditional statement of any complexity and trigger events. When an event triggers, its actions run in weight order. Actions are the individual mechanisms of additional functionality that have a distilled purpose and can run on any associated event.

80% of this functionality builds on top of [Luvent: A Simple Event Library for Lua](https://github.com/ejmr/Luvent). You could probably get away with the summary below of Lighttouch's use of its API, but it's still worth checking out. It has a great Readme. The basic difference between what Luvent does and what Lighttouch does is that while writing a Lighttouch app, you put functionality into individual files, and Lighttouch sets everything up for you.

Events are very simple. They get loaded into a global list by reading each package's `events.txt` file. They can be disabled in a `disabled_events.txt` file. (aside: Potential improvements include a simpler interface and ordering execution by weight.)

Rules are basically an `IF` statement with some metadata. If the configured conditions, specified in the body of a rule as Lua code are `TRUE`, then the specified events will trigger and the objects specified in the input parameters will get passed to the attached actions.

Actions are individual, [lazy loaded functions](https://whatis.techtarget.com/definition/lazy-loading-dynamic-function-loading) that can run where they are needed. You simply code what you want to do, and leave the parts about when it will run and in what order to the other logic connected through the yaml header. Actions should not have conditions in them.

### Core Modules (including third-party)

Lighttouch also provides modules for content management, robust logging, syntax sugar, and more. These core modules + loaders mentioned for packages + and init script make up [Lighttouch Base](https://github.com/foundpatterns/lighttouch-base), which has:
- Packaged ECA-Rules Loaders: described above
- Content Module: file-based, document-oriented databases (see Grav) with data models in YAML, similar to JSON Schema (content types), and validation
- Logging: automatically setup out of the box (set log level in `config.toml`, default is `INFO`)
- ...

### Packages

- Lighttouch Web Logging: (for web automation) log every incoming request, outgoing response, outgoing request, and incoming response (server and client logging out of the box.. makes debugging web applications much easier) to log directory (log entries are content, btw)
- Lighttouch JSON Interface: REST API built on content module
- Lighttouch HTTP Interface: form-driven content entry mechanism, username:password protected (autogenerated at each initialization)
- Lighttouch Crypto Tools: setup a profile with cryptographic signing keys for yourself and friends to verify incoming responses and requests, and sign outgoing requests and responses + and more

### Installation

Lightouch has 3 dependencies:
* **[torchbear](https://github.com/foundpatterns/torchbear)** (an [application framework](https://stackoverflow.com/questions/4241919/what-is-meant-by-application-framework))
* **[git](https://git-scm.com)** (a [version control manager](https://en.wikipedia.org/wiki/Version_control))
* **[peru](https://github.com/buildinspace/peru)** (a [package manager](https://en.wikipedia.org/wiki/Package_manager))

Once these are installed, clone the repo with git, run `peru sync` to install its components, and run it with `torchbear`. To update, use `git pull` and `peru reup`.

### Developing

To modify any functionality in Lighttouch, create a git repo outside of it for the component your are modifying, and add an override in `peru.yaml` so that it will use that source directory. For example, to modify `lightouch-base`, clone it somewhere else, then run `peru override add lighttouch-base {{ path to lighttouch-base repo }}`. Then, after making each change to the source, run `peru sync` to update your Lighttouch.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title = "Fast"
model = "slide"
slideshow = "c800a360-d198-4a87-877e-b353f7dd0a9d"
image-address = "http://unsplash.com/photos/CpkOjOcXdUY/download?force=true"
weight = 1
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title = "Simple"
model = "slide"
slideshow = "c800a360-d198-4a87-877e-b353f7dd0a9d"
image-address = "http://unsplash.com/photos/x2Tmfd1-SgA/download?force=true"
weight = 2
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title = "Powerful"
model = "slide"
slideshow = "c800a360-d198-4a87-877e-b353f7dd0a9d"
image-address = "http://unsplash.com/photos/pqvp1P7re-w/download?force=true"
weight = 3
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title = "Found Patterns Introduction"
model = "slideshow"
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
model = "key"
kind = "sign_private"
profile = "d3562615-c6c9-4a41-8fb9-f39117ed55cd"
...
+qEY1pRSYy7gTfJ58GLrDQTuhgiTf49Cy9yEgvix3vHGkq2b5t55E36RPtVYgnTn+2SF0Of8nEeVOyTvcvlnnQ==
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
model = "key"
kind = "sign_public"
profile = "d3562615-c6c9-4a41-8fb9-f39117ed55cd"
...
xpKtm+beeRN+kT7VWIJ05/tkhdDn/JxHlTsk73L5Z50=
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
host = "http://foundpatterns.com:3000/"
model = "place"
profile = "d3562615-c6c9-4a41-8fb9-f39117ed55cd"
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
model = "profile"
name = "foundpatterns"
...
1 change: 1 addition & 0 deletions home-store.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0382e080-dd03-46e2-9610-115b72b3af27
63 changes: 49 additions & 14 deletions import.scl
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
imports = {
luvent = "third-party/",
valua = "third-party/",
torchbear-libs = "third-party/",
contentdb-lua = "contentdb",
torchbear-libs-dev = "third-party/",
lighttouch-logging = "packages/lighttouch-logging",
lighttouch-json-interface = "packages/lighttouch-json-interface",
lighttouch-html-interface = "packages/lighttouch-html-interface",
homepage-package = "packages/homepage-package",
base-theme = "themes/base-theme",
send-file-package = "packages/send-file-package",
lighttouch-change-management = "packages/lighttouch-change-management",
luvent = "third-party/",
valua = "third-party/",
torchbear-libs = "third-party/",
contentdb-lua = "contentdb",
torchbear-libs-dev = "third-party/",
}

torchbear-libs = {
url = "https://github.com/foundpatterns/torchbear-libs",
repo = true,
url = "https://github.com/foundpatterns/torchbear-libs",
repo = true,
}

torchbear-libs-dev = {
url = "https://github.com/foundpatterns/torchbear-libs-dev",
repo = true,
url = "https://github.com/foundpatterns/torchbear-libs-dev",
repo = true,
}

luvent = {
url = "https://github.com/ejmr/Luvent",
export = "src"
url = "https://github.com/ejmr/Luvent",
export = "src"
}
valua = {
url = "https://github.com/sailorproject/valua",
pluck = "valua.lua",
url = "https://github.com/sailorproject/valua",
pluck = "valua.lua",
}

contentdb-lua = {
url = "https://github.com/foundpatterns/contentdb.lua",
url = "https://github.com/foundpatterns/contentdb-lua",
}

lighttouch-logging = {
url = "https://github.com/foundpatterns/lighttouch-logging",
}

lighttouch-json-interface = {
url = "https://github.com/foundpatterns/lighttouch-json-interface",
}

lighttouch-html-interface = {
url = "https://github.com/foundpatterns/lighttouch-html-interface",
}

homepage-package = {
url = "https://github.com/foundpatterns/homepage-package",
}

base-theme = {
url = "https://github.com/foundpatterns/base-theme",
}

send-file-package = {
url = "https://github.com/foundpatterns/send-file-package",
}

lighttouch-change-management = {
url = "https://github.com/foundpatterns/lighttouch-change-management",
}
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env torchbear
-- Lighttouch · Torchbear App

-- this config must be before requires
Expand Down
15 changes: 15 additions & 0 deletions torchbear.scl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
web-server = {
address = "0.0.0.0",
port = "3000",
single_actor = true,
}

general = {
init = "lighttouch-base/init.lua",
theme = "base-theme",
log_level = "trace",
sitename = "Lighttouch",
slideshow = "c800a360-d198-4a87-877e-b353f7dd0a9d",
user = "admin",
password = "admin",
}

0 comments on commit a00aa59

Please sign in to comment.