DailyFinance Web App (Multi-platform)
DailyFinance is a useful tool for keeping daily expenses, all you need is the interest access, any devices can use this tool as long as it is with browsers. User can register accounts by email, will be able to retrieve the password by email if they forget the password. User can create a new expense, update or delete current expenses and browse all expenses, they can delete all expenses and delete the entire account as well. You can use DailyFinance-monitor to view all registered users.
I used express to develop the node server and used mongoose to connect to mongoDB. Passport is handling log in, log out and authenticated for API as well. Emailjs sent email to user to remind the user password. I used my own gmail account as the default email setting so you will received email from my gmail if you forget your password.
Here is the main function of each js file in server/lib folder:
account.jsCRUD operations related to accounts
authentication.jsauthentication based on passportjs
expense.jsCRUD operations related to expenses
index.jsmain server settings
password.jsCRUD operations related to password
I used MVC structure by angularjs to implment the entire front-end. Besides views and controllers, I used several services to make the API calls and initialize the popup modals. Also, there is one directive for navbar which is used in every views. All the css are based on Bootstrap 3.0 and it is compiled by compass.
As you can see I used mongoDB as the main database because it is JSON-like document-oriented database which is very convenient for node js development.
The database has two schema, user and expense. User saved all users’ information including email, password, name and ID. Expenses saved each single expense data with name, price, data, time and ID.
All API built in RESTful. Main operations are CRUD which is create, read, update and delete. Use GET as read and DELETE as delete operations as usual, for create I used POST and update use PUT, which is not necessary to use POST as create, POST can be used as update as well. The main difference between them is POST is not idempotent but PUT is.
Here is the short description of each API operation:
GET expense listsend request to DB to require the data
GET expense detailused cached data, to improve performance, instead of sending DB request, while requesting
GET list, cached the data for later usage.
POST new expensecreate new data
PUT expenseupdate existing data
DELETE expensedelete data
DELETE accountdelete both user and user related expense data as well
DELETE all expensesbatch delete data
POST retrieve passwordafter found the user information, send the user password via email
There is few things to mention when I sent the response http code back from server. Used 201 instead of 200 when new entry got created. Used 404 if there is no data got found and 500 if there is any database error.
Unit test is one of the important step in software development, you cannot develop good software without a good unit test. All unit test are used karma as test runner and jasmine as BDD framework. All unit testing code is in the test folder, spec is where the code is mock is where the mocking code is such as modal and app authentication service.
Use pm2 as deploying process manager. All I need to do is to create a script to start the grunt task and pm2 will start the server as a daemon process running as a backgrund task.
This is my
start.sh script, on amazon ec2 I just do
pm2 start start.sh and the server will start!
Please feel free to play with it and let me know any feedbacks or any new features you like to put into. Thanks!