OPEngine
Github

Born out of a personal need for a bloat-free framework, OPEngine is what I'm currently building. I wanted to build a microservice that would just render statistics collected from this blog, cloudflare, and push them into Grafana for graphing. A simple enough task, since it's scope is relatively small, and not a lot of logic is required (as it's mostly remote API calls), I need something that's free of bloat - I don't need a view engine, I don't want to be vendor-locked into something.

My first thought was to just spit out a simple Express-based server, run it under pm2 behind nginx and call it a day. For the most part this would've worked, but I wanted to leverage Typescript and the typings available. I ran into NestJS which is a great full-fledged framework, if I had to build a large application I'd certainly consider - but for my needs, way too much bloat.

I next considered Restify, while Restify is a great framework to work with, it wasn't what I was really hoping for. I wanted something where I could have everything typed, have some concept of MVC (primarily, controllers which also manage their own routes dynamically, and models). A desire for a simple "npm install {SOMETHING}", then a flat-file configuration pointing to my controller, models. A structure I defined based on what met my needs.

Four days of searching, nothing fit the bill. I sat back, and began to create OPEngine. OPEngine is still under active development, and any contributions are appreciated!

What's OPEngine?

OPEngine ( pronounced "open engine" ), is a lightweight, modular yet bloat-free framework, you have a set of security options available, CSRF protections, XSS protection with controllers and models. You can define your own directory structure, and must explicitly include the files you want to be executed at run time.

Introducing Controllers

Controllers in OPEngine work the same as many other frameworks, you'll notice the similarities right off the bat. Take this debug controller for example:

import * as express from 'express';
import Controller from './Controller';
import JsonResponse from '../tools/response/JsonResponse';

export class DebugPage extends Controller {
    showInformationPage( request: express.Request, response: express.Response ) {
        let json_resp = new JsonResponse({
            status: 'OK',
            debug: true,
            message: 'This debug page is online, and it is loading successfully.'
        });

        response.send(json_resp.write());
    }

    showPostInformationPage( request: express.Request, response: express.Response ) {
        let json_resp = new JsonResponse({
            status: 'OK',
            debug: true,
            is_post: true,
            message: 'This debug page is online, and it is loading successfully.'
        });

        response.send(json_resp.write());
    }

    setupRoutes() {
        this.router.get('/debug', this.showInformationPage);
        this.router.post('/debug', this.showPostInformationPage);
    }
}

A simple controller, that defines routes for GET and POST, constructing a JsonResponse in each of the functions, and sending that response to the user. Nothing complex, and very easy to understand – no steep learning curve.

Initial Server Setup

When you launch a new application, you define a server.ts file, this file imports your dependencies, creates the server instance, and listens on the desired port. Here's a good example of how this all works:

import { server_init } from '../src/server/init';
import Security from '../src/core/enums/security/policy';
import { DebugPage } from '../src/core/controllers/DebugPage';

const server = new server_init();

// ---- SETUP SECURITY POLICY ----
server.setSecurityPolicy( Security.POLICY_DEFAULT );

// ---- DEFINE USABLE CONTROLLERS ----

server.setupControllers([
    new DebugPage()
]);

server.listen();

You import the server_init class, define your security policy, and then load in your controllers. Finally, call the listen function to start the server.

Behind the name

The naming of this framework just happened to be rather random, I wanted something that struck the fact this framework is open to how you like it (no vendor lock-in), so OPEngine it became.

Check out the Github repository here for more information, including installation instructions!

engineering opengine

Mike

Senior Software Engineer, Labber, Sysadmin. I make things scale rapidly. Optimize everything.

Read More