Skip to content

Commit

Permalink
Merge pull request #80 from andreciornavei/develop
Browse files Browse the repository at this point in the history
improve documentation; added monitoring tool;
  • Loading branch information
andreciornavei authored Mar 8, 2024
2 parents 6778b78 + 89376dd commit f2773ce
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 7 deletions.
73 changes: 67 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,78 @@

This is a test proposed by Turno to build a simplified Bank System using PHP/Laravel and ReactJS.

This project contains the entire application splitted in folders/subprojects (frontend, backend and documentation) and make use of GitHub Pipeline CI to deploy each subproject as needed.
**Original Test Repository** https://github.com/TidyDaily/developer-test/tree/main

**Application**: https://bnb-bank.andreciornavei.com.br

![](https://github.com/andreciornavei/bnb-bank/blob/develop/docs/presentation.gif?raw=true)

This project contains the entire application splitted in folders/subprojects (frontend, backend and docs) and make use of GitHub Pipeline CI to deploy each subproject as needed.

Still, AWS infrastructure is being used to release the project and all its resources is provisioned by IaC using serverless framework on each subproject (backend/frontend) folders.

MongoDB is being used for database.

### Environment
## Requirements met

### Application stories requirements

#### Customer
- ✅ A user can create a new account with username and password
- ✅ A user starts with 0 balance
- ✅ A user can deposit more money to his account by uploading a picture of a check and entering the amount of the check. if the check is approved by an admin, the money is added to the bank account.
- ✅ To buy something, the user enters the amount and description; a user can only buy something if she has enough money to cover the cost.
- ✅ A user can see a list of balance changes including time and description.

#### Admin
- ✅ An admin account is already created with a hard coded username and password.
- ✅ An admin can see a list of pending check deposit pictures with amount and picture and click to approve or deny the deposit.

#### Simplifying Assumptions
- ✅ An admin can’t be also a customer


### Backend requirements

- ⬜ Automated Tests / Test Coverage
- ✅ API Access Control (Policies, Gates, etc.)
- - In addition to the Authenticate middleware, was created two new middlewares to handle user role policies, where them its attached to the correct routes for each role.
- ✅ Implement a design pattern (DDD, Repository Pattern, etc.)
- - With special attention on _`backend/app/Domain`_ and _`backend/app/Infrastructure`_. Them follow the SOLID principles and implements the Clean Architecture;
- - Domain Usecases always expects an interface of an implementation. Thats implementations is Injected by Controllers.
- - Infrastructure folder implements the data access for repositories and providers;
- ✅ Make a good and cohesive database design
![](https://github.com/andreciornavei/bnb-bank/blob/develop/docs/BnB-Bank-MER.png?raw=true)

### Frontend requirements

- ✅ TypeScript
- ✅ Front-end cache
- - The frontend is cached using CloudFront. Always a deploy happens, the cloudfront cache is invalidated by CI.
- ✅ Code structure and organization
- - Give an special attention to page structure, each page contains a conjunction of (context, controller, view, types, styles & index) files, where each one has its own responsability, improving readability;
- ✅ Performance and monitoring tools
- - Was made use of package _`use-context-selector`_ that improves the context providing. Also, for specific cases, was created an isolated component that inherit neededs data thought context, avoiding the re-render of entire screen.

## Stategic Decisions

#### Docker + Bref (https://bref.sh/docs/deploy/docker)

Small applications does not need to consume paid services on AWS, in this case, the API was packaged on a Docker Image and deployed inside a Lambda Function with help of Bref, so the API will always be available for anyone who try to dispach a request against it, and of corse, using the Always Free Tier limit.

#### Uploads with AWS Presigned Url

Backend applications should not have to handle hard proccess like uploads, it could use a lot of cpu, memory and time, for that, was used uploads with presigned urls, where the backend just ask to AWS for a URL where upload can be made.

#### AWS S3 Bucket LifecycleConfiguration

`./backend/serverless -> resources.Resources.UploadBucket`

As users can abort deposit operations at any moment, it is important to remove temporary check uploads from bucket. For that, all temporary uploads are made on ./tmp folder on bucket, it contains a LifecycleConfiguration to remove the file in 24h. Once the deposit operation is finished successfully, the check file is moved from .tmp/ to ./deposits folder, where it will not be deleted anymore.


The application is packaged on Docker to be deployed on AWS, also it is using the Bref image to respond requests thought lambda functions.
## Considerations

https://bref.sh/docs/laravel/getting-started
https://bref.sh/docs/deploy/docker
**Commits**: https://github.com/andreciornavei/bnb-bank/commits/develop/

**- `CACHE_DRIVER` was disabled to work on lambda.**
Take a look at the commits timeline and see the development process, attempts to run CI/CD pipeline, mistake fixings, etc.
Binary file modified docs/BnB-Bank-MER.jam
100755 → 100644
Binary file not shown.
Binary file added docs/BnB-Bank-MER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Code Challenge - Wireframe.pdf
Binary file not shown.
Binary file added docs/Code Challenge - Wireframe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Document-Check-Example.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/MER.png
Binary file not shown.
Binary file added docs/presentation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@mui/lab": "^5.0.0-alpha.167",
"@mui/material": "^5.15.12",
"@phosphor-icons/react": "^2.0.15",
"@sentry/react": "^7.106.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './index.css'
import Router from './router'
import { enableMapSet } from 'immer'
import { DefaultTheme } from './theme'
import * as Sentry from '@sentry/react'
import ReactDOM from 'react-dom/client'
import { ApiProvider } from '@hooks/api'
import { AuthProvider } from '@hooks/auth'
Expand All @@ -11,6 +12,25 @@ import reportWebVitals from './reportWebVitals'
import { BrowserRouter } from 'react-router-dom'
enableMapSet()

// Install Sentry For Monitoring
Sentry.init({
dsn: 'https://56ff0892b732563d22086de012c5a22c@o4506876266741760.ingest.us.sentry.io/4506876269494272',
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
}),
],
tracesSampleRate: 1.0,
tracePropagationTargets: [
'localhost',
/^https:\/\/bnb-bank.andreciornavei\.com\.br/,
],
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
})

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
<ThemeProvider theme={DefaultTheme}>
Expand Down
84 changes: 83 additions & 1 deletion frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,88 @@
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.7.2.tgz#2d4260033e199b3032a08b41348ac10de21c47e9"
integrity sha512-RbhOOTCNoCrbfkRyoXODZp75MlpiHMgbE5MEBZAnnnLyQNgrigEj4p0lzsMDyc1zVsJDLrivB58tgg3emX0eEA==

"@sentry-internal/feedback@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-7.106.0.tgz#34a41f12093c09a9fec416600a11406afc60af96"
integrity sha512-Uz6pv3SN8XORTMme5xPxP/kuho7CAA6E/pMlpMjsojjBbnwLIICu10JaEZNsF/AtEya1RcNVTyPCrtF1F3sBYA==
dependencies:
"@sentry/core" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry-internal/replay-canvas@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-7.106.0.tgz#008c1cdc78a227ac2a84024dc79634f0c61f45bf"
integrity sha512-59qmT6XqbwpQuK1nVmv+XFxgd80gpYNH3aqgF5BEKux23kRB02/ARR5MwYyIHgVO0JhwdGIuiTfiLVNDu+nwTQ==
dependencies:
"@sentry/core" "7.106.0"
"@sentry/replay" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry-internal/tracing@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.106.0.tgz#0752f6925c5120848c05dc6c87a60b25896f834b"
integrity sha512-O8Es6Sa/tP80nfl+8soNfWzeRNFcT484SvjLR8BS3pHM9KDAlwNXyoQhFr2BKNYL1irbq6UF6eku4xCnUKVmqA==
dependencies:
"@sentry/core" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry/browser@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.106.0.tgz#195395a9ca5a7af774eae271cea2bc08964d8abf"
integrity sha512-OrHdw44giTtMa1DmlIUMBN4ypj1xTES9DLjq16ufK+bLqW3rWzwCuTy0sb9ZmSxc7fL2pdBlsL+sECiS+U2TEw==
dependencies:
"@sentry-internal/feedback" "7.106.0"
"@sentry-internal/replay-canvas" "7.106.0"
"@sentry-internal/tracing" "7.106.0"
"@sentry/core" "7.106.0"
"@sentry/replay" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry/core@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.106.0.tgz#501aebb349014189162dc77ec31eacbf45ee44c4"
integrity sha512-Dc13XtnyFaXup2E4vCbzuG0QKAVjrJBk4qfGwvSJaTuopEaEWBs2MpK6hRzFhsz9S3T0La7c1F/62NptvTUWsQ==
dependencies:
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry/react@^7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.106.0.tgz#84bdf925419a932376c6ab0427f7892a4db96bf1"
integrity sha512-5KMfvkBYqK990o8Ju9vsRRRR0F8TnPpZynC9YqsJYpCViKjIt8W/ysDLrU1Dj5XZyeVElZjdRlXB0aQYrwEUWg==
dependencies:
"@sentry/browser" "7.106.0"
"@sentry/core" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"
hoist-non-react-statics "^3.3.2"

"@sentry/replay@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/replay/-/replay-7.106.0.tgz#e66d78aa6a63b60a58bc78afbebf0e6ac308eea7"
integrity sha512-buaAOvOI+3pFm+76vwtxSxciBATHyR78aDjStghJZcIpFDNF31K8ZV0uP9+EUPbXHohtkTwZ86cn/P9cyY6NgA==
dependencies:
"@sentry-internal/tracing" "7.106.0"
"@sentry/core" "7.106.0"
"@sentry/types" "7.106.0"
"@sentry/utils" "7.106.0"

"@sentry/types@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.106.0.tgz#a68490c8d5f4b53f704af4c80535165e04c28e42"
integrity sha512-oKTkDaL6P9xJC5/zHLRemHTWboUqRYjkJNaZCN63j4kJqGy56wee4vDtDese/NWWn4U4C1QV1h+Mifm2HmDcQg==

"@sentry/utils@7.106.0":
version "7.106.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.106.0.tgz#a4c05f79672f734c1a1475428144ab97d2f7bea9"
integrity sha512-bVsePsXLpFu/1sH4rpJrPcnVxW2fXXfGfGxKs6Bm+dkOMbuVTlk/KAzIbdjCDIpVlrMDJmMNEv5xgTFjgWDkjw==
dependencies:
"@sentry/types" "7.106.0"

"@sinclair/typebox@^0.24.1":
version "0.24.51"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f"
Expand Down Expand Up @@ -5394,7 +5476,7 @@ he@^1.2.0:
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

hoist-non-react-statics@^3.3.1:
hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
Expand Down

0 comments on commit f2773ce

Please sign in to comment.