Magenta bank. Simulates a bank account control system, processing deposit requests, withdraws and payments. It also has the ability to monetize the current account balance from one day to another.
General project overview:
- Responsive app (works on mobile)
- Uses AdonisJS for backend
- Uses NuxtJS for frontend (VueJS)
- Uses MySQL as database for storage information
- Backend tests running under Japa
- Deploy/production architecture is done using heroku (front and backend)
The backend was built using AdonisJS, a NodeJS framework very similar to Laravel, Rails and also Django. All the application logic is placed here. Transactions, wallet balance, authentication, users, etc.
Some of the backend app highlights:
- Typescript
- MVC model
- ORM pattern
- Service Layer responsible for handling info (it could has a repository pattern but it would be an overhead)
- Development env uses Docker/docker-compose
Route | Method | Handler | Middleware |
---|---|---|---|
/api/auth/signup | POST | AuthController.signUp |
|
/api/auth/signin | POST | AuthController.signIn |
|
/api/auth/signout | POST | AuthController.signOut |
|
/api/transactions/history | GET | TransactionController.getWalletHistory |
auth |
/api/transactions/payment | POST | TransactionController.payment |
auth |
/api/transactions/deposit | POST | TransactionController.deposit |
auth |
/api/transactions/transfer | POST | TransactionController.transfer |
auth |
/api/transactions/withdraw | POST | TransactionController.withdraw |
auth |
/api/users/me | GET | UserController.me |
auth |
/api/wallets | GET | WalletController.getUserWallet |
auth |
Follow the steps below and get this API running locally:
$ cd backend
$ cp .env.example .env
$ docker-compose up -d
> Builds images and get containers running in background$ docker-compose exec warren-api sh
> Enter in docker api container$ node ace migration:run
> Inside container, run migrations (create db tables)
At this point the API is running on localhost:3333/api and MySQL8 is running on localhost:3306.
After get running local, to run tests simple do:
$ docker-compose exec warren-api sh
> Enter in docker api container$ mkdir tmp && touch tmp/db.sqlite3
> Create sqlite3 database for testing$ npm run tests
> check console output
Since adonisjs uses typescript and runs from build directory (which contains all compiled javascript files), some build problems can occur. If this happens, try rebuilding the app and running up server again. You can also read the Adonisjs docs.
$ docker-compose exec warren-api sh
$ npm run build
You can also face problems using docker. If this happens, try to remove all containers and rebuild again:
$ docker-compose rm -v
$ docker-compose build --no-cache --force-rm
$ docker-compose up --remove-orphans
The frontend app was built under NuxtJS using Typescript for most part of application. It is as dummy as possible, meaning is only responsible for sending/getting backend info. It doesn't calculate anything.
Some of the front app highlights:
- Vue under the hood
- Vuex modules to handle app state
- API layer to connect to backend
- Built-in Nuxt auth module
- Nuxt transiction to add a nice loading state
- Uses LESS to handle styles (and categories colors)
- Uses vue-ant-design as design system (components)
Follow the steps below and get the frontend running locally on port 3000.
$ cd frontend
$ cp .env.example .env
$ npm i
- Change .env API_URL and API_URL_BROWSER to http://localhost:3333/api (or backend URL above)
$ npm run dev
> Frontend running on localhost:3000
At this point frontend running on localhost:3000.
Backend comes with a builtin command that monetizes all wallet balances daily. It is not a problem run twice or more a day because command prevents duplication monetization. Must be run inside docker-container.
$ cd backend
$ docker-compose exec warren-api sh
$ node ace monetize:balance:daily
> Runs commands/MonetizeBalanceDaily.ts
Current deployment process relies on Heroku. Since we have both frontend and backend applications running at the same git repository, different master branches had to be added to each project as described here. To deploy you must go to project directory and run the deploy:heroku
command, like so:
$ cd backend or frontend
$ npm run deploy:heroku
> For backend only, tests will be run before.
This process only deploys a new version if current branch has changes. You also must be logged and have permissions inside Heroku in order to get this done.
Since this is a MVP version, both backend and frontend can has improvements. Here are some examples.
- Tests: add testing layer to ensure actions are working well
- Known issue: input currency does not work on Safari
- Encrypt all user data on database
- Implement 2-fac authentication
- Throw exceptions on service methods instead of returning false
- Create a schedule/cron job that runs command to monetize balance every day
- CI: Attach a set of steps to ensure everything is fine with the application build on deployment process;
- CD: Deploy backend automatically when a push/merge occurs on specific git branch - I would do this but I lack permissions on this repository