Giter VIP home page Giter VIP logo

kangaroojs's Introduction

Kangaroojs

Simple skeleton for MVC express apps (nodejs)

Main features:

  • Modular design
  • Ships with user accounts, login system and an admin
  • Fully tested
  • Uses Express for web-framework
  • Uses Sequelize for ORM
  • Uses Handlebars for view engine
  • Uses Bootstrap for css framework

The usual workflow when developing an MVC project involves first to focus on a specific feature, then to work iteratively on relevant controller, view and test files. It requires a lot of back and forth between these files. However, many MVC frameworks organize their files functionally, i.e all view, controller and test files are located in view, controller and test folders. As the project gets bigger and bigger, those seemingly innocuous switching efforts between functional folders ends up adding a lot of time and mental overhead.

To solve this problem, I have created this MVC framework, where the first unit of organization is the module (think feature). Inside each module are controllers, views and tests, optionally grouped by user-permissions level.

Getting Started

  1. Create a project folder
mkdir yourproject
cd yourproject
  1. Create mysql database
mysql -u[YOUR ROOT_USER] -p[YOUR ROOT_PASSWORD]
mysql> CREATE DATABASE [YOUR DB_NAME]
  1. Clone the repo & install dependencies
git clone https://github.com/jklepatch/kangaroojs.git
npm install
  1. Setup env variables in project folder Rename .env-sample to .env
mv .env-sample .env

Replace placeholders in .env with your own configuration .env

NODE_ENV=[development|test|staging|production]
DB_HOST=[YOUR DB_HOST]
DB_NAME=[YOUR DB_NAME]
DB_USERNAME=[YOUR DB_USERNAME]
DB_PASSWORD=[YOUR DB_PASSWORD]
  1. Setup environment-specific configurations
| -- /config
     | -- default.js
     | -- development.js
     | -- test.js
     | -- staging.js
     | -- production.js

Prerequisites

Folders Organisation

Overview

| -- /apps
     | -- /web 
          | -- /modules  
          | -- /models
| -- /db
| -- /config
| -- .env.sample

Apps

| -- /apps
     | -- /web 
          | -- /modules   
          | -- /models

Each subfolder of /apps represents one process of your app. By default there is one process, web. Other can be added, like cron for example. For /modules and /models folders, please see their respective sections below.

Modules

| -- /modules
     | -- user
          | -- routes.js          -> loads routes of this module
          | -- /admin             -> admin-specific routes, views and tests
               | -- routes.js
               | ------view-edit.js
               | ------view-delete.js
               | ------test-routes.js
          | ----public/           -> not logged-in routes, views and tests
               | -- view-index.js
               | -- routes.js
               | -- test-routes.js

Inside the /apps/web/modules folder live your modules. Modules are Views and Controllers (~routes)(The VC of MVC). Models are outside of modules because very often they need to be shared between modules. Inside each module, files are optionally grouped by permission levels. This allows to keep the focus on features and users. At a glance, you can see that such user can do such and such actions in a specific modules. And it helps to keep routes.js files slim.

Models

| -- /models
     | -- index.js             -> loads all models
     | -- user.js              -> model `user`
     | -- test-user.js         -> test the model `user`

Db

| -- /db 

Migration and seed files. Check sequelize docs migrations and the sequelize CLI for more information. There is little official documentation for seeds, so check out the examples given in this repo.

Configuration

| -- /config      -> environment-specific config files
| -- .env-sample  -> environment variables for sensitive config (ex: database). Need to be renamed to .env

Tests

To run the tests, type at the root of the project:

npm run test

It will trigger unit tests and integration tests. It uses mocha, chai, and chai-http.

Unlike other frameworks, tests live next to the files they test:

  • Unit tests: inside the models folder
  • Integration tests: Inside each modules folder

Deployment

@TODO: explain how to set it up with pm2.

Built With

License

This project is licensed under the MIT License

kangaroojs's People

Contributors

jklepatch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.