Skip to content

idenisovs/money-saver-backend

Repository files navigation

Money Saver

This web application helps me to manage my everyday expenses.

Getting Started

You need to have installed Node.js.

No database server is required.

To launch the application for the first time, you shall clone it to your PC:

git clone --recurse https://github.com/idenisovs/money-saver.git backend

Then, go inside and run the following commands:

npm run setup
npm start

From now, web application should be accessible by passing the following link: http://localhost:9001

Default user login is user1 with password demo1.

By default it is listening the port 9001. You can change it in Source/config.json file.

The reason of project

Because I wanted to get new skills and gather some more experience with development of web applications by using the technologies like Node.js.

CLI syntax

In the Source directory:

Usage: node daemon.js [options]
-p, --port - select the port to listen;
-b, --database - give a path to the database;
-v, --verbose - run in verbose mode (by default, it will run with INFO loglevel;
-d, --debug - add some verbosity to output by setting loglevel to DEBUG;
-t, --trace - set loglevel to TRACE, extra verbosity;
--testable - run application in testable mode.
-h - show help;

As example:
node daemon.js -vd -p 8000 - will run application in verbose mode with DEBUG loglevel on port 8000;

Note: testable mode means that application will use in-memory SQLite3 database to store the data. Such mode is necessary to run integration tests provided with Money Saver application.

The parts of application

Frontend (client side)

  • Angular.js (1.x.x) and Bootstrap to make UI.
  • chart.js to make beautifull charts.
  • Bower dependency management.
  • Grunt to perform some routine actions, like version management or frontend files minification.

Frontend files located under the following path: money-saver/Source/ui.

Backend (server side)

Backend structure

                     Backend application
                     +------------------------------------+    finance.db
+--------+  REST API |  +-----+      +----+      +-----+  |    +----+
| Client | ----------|->| API | <--> | BL | <--> | DAL |<-|--->| DB |
+--------+           |  +-----+      +----+      +-----+  |    +----+
     |               |                                    |
     |               |  +--------------+                  |
     +---------------|->| Static files |                  |
                     |  +--------------+                  |
                     +------------------------------------+    
  • API layer modules, like intervals or payments process REST API requests, calls BL and makes responses.
  • BL (Business Logic) layer has processing and calculations functions and make calls to DAL.
  • DAL (Data Access Layer) perform database requests.

Modules

Each layer is organized in tree-like structure:

                       +--- ( get-interval-by-id )
                       |
     +---- intervals---+--- ( get-latest-interval )
    /                  |
 api------ payments    +--- ( get-intervals )
    \
     +---- properties

The same is for BL and DAL:

                       +--- ( get-by-id )
                       |
     +---- intervals---+--- ( get-latest )
    /                  |
  bl------ payments    +--- ( get-all )
    \
     +---- properties

So, typically, any API module (like get-interval-by-id) may call any BL function like this:

const bl = require('../../bl');

bl.intervals.getById(id, success, fail);

Database

At the moment (2018-07-17) no database server is required and no database server can be used by application. To store and manage the data it uses the SQLite3 engine.

It's database is located within finance.db file. It can be observerd by SQLite CLI application, SQLite Studio or any modern IDE (wiki), by using appropriate plugins.

REST API reference

REST API reference is available here

Unit Tests

You may launch unit tests by running the following command:

npm test

Used frameworks

  1. Mocha - test framework.
  2. Chai - BDD / TDD assertion library.
  3. sinon - makes standalone test spies, stubs and mocks.
  4. proxyquire - dependency injection for modules under testing.

proxyquire

Some modules, like db (in Source/dal/db) makes some action in the moment, when they are called by require(...) at the first time (it might be system startup, for example).

To avoid such behaviour during testing, use noCallThru option of proxyquire.

Integration Tests

You may launch Integration tests by running the next command:

npm run integration

It will run the whole application in testing mode. Tests will call the different REST API endpoints of application with differnet arguments.

Grunt tasks

  1. build (default) - concat and minify UI source files (JS);

    --local - build the minified version of app for running on local machine;

    --testable - for testing purposes on local machine;

    --cloud - for running in the cloud (see config.prod.json);

    By default (without any params) Grunt will build the minified version for cloud usage;

  2. clean:cleanup - to remove downloaded libs, modules and log files;

License

You have a right to fork it, study it, change it, share it, blame it and use it if you're brave enough.