This repository powers the backend for Leafy Bank, a demo banking application designed to showcase modern financial services technology. It handles digital payments and account transfers, utilizing MongoDB to ensure secure and efficient transaction processing. The backend provides APIs for seamless integration, illustrating the capabilities of cutting-edge banking infrastructure.
MongoDB excels in managing complex operational data, making it an ideal choice for financial services that require robust transaction processing.
-
Easy: MongoDB's document model aligns naturally with object-oriented programming, using BSON documents similar to JSON. This design simplifies managing complex data structures such as users, accounts, transactions and notifications, facilitating feature implementation with greater ease.
-
Fast: By adhering to the principle of "Data that is accessed together should be stored together," MongoDB optimizes query performance. This principle ensures that related data can be quickly retrieved in unison, enhancing overall service speed—an essential factor for financial applications demanding rapid access to operational data.
-
Flexible: MongoDB's schema flexibility allows data models to evolve effortlessly alongside changing business requirements. This adaptability enables financial services to update operational data models—such as transaction and account structures—without expensive, time-consuming schema migrations, thus avoiding costly downtimes typically associated with schema changes.
-
Versatile: The document model in MongoDB seamlessly handles diverse data types, including strings, numbers, booleans, arrays, objects, and even vectors! This versatility supports a wide range of operational use cases, enabling comprehensive management of users, accounts, transactions, and notifications seamlessly within your application.
MongoDB offers robust support for multi-document ACID transactions, a critical feature for maintaining data integrity and consistency across multiple collections. This capability ensures that complex operations, such as account transfers or digital payments, are executed reliably, handling updates across users, accounts, transactions, and notifications collections with precision.
These attributes highlight MongoDB's strength as a powerful choice for developing scalable, efficient, and reliable solutions for transaction-related operations within the financial industry.
- MongoDB Atlas for the database
- FastAPI for the backend framework
- Pydantic for documenting FastAPI Swagger schemas
- Poetry for dependency management
- Docker for containerization
Before you begin, ensure you have met the following requirements:
- MongoDB Atlas account, you can create one here. Free tier is sufficient for this project.
- Python 3.10 or higher (but less than 3.11)
- Poetry (install via Poetry's official documentation)
- Log in to MongoDB Atlas and create a new database named
leafy_bank
. You can use another name if you prefer, but make sure to update all database name references in the code and environment variables. - Inside this database, create a 4 (four) empty collections:
users
accounts
transactions
notifications
- Create a new MongoDB user with read and write access to the
leafy_bank
database. You can follow the official MongoDB documentation to create a new user. You can find the instructions here.
- Access your cluster.
- Under the
Security
tab, click onDatabase Access
. - Click on
Add New Database User or User Group
. - Fill in the user details and set the password.
- Under
Database User Privileges
->Add Specific Privileges
, selectreadWrite
for theleafy_bank
database, and you can select*
for all collections. - Click on
Add User
.
Note: Don't forget to save the username and password. You will need them to connect to the database.
Note: Create a
.env
file within the/backend
directory.
MONGODB_URI = "mongodb+srv://<REPLACE_USERNAME>:<REPLACE_PASSWORD>@<REPLACE_CLUSTER_NAME>.mongodb.net/<REPLACE_DATABASE_NAME>"
ORIGINS=http://localhost:3000
- (Optional) Set your project description and author information in the
pyproject.toml
file:description = "Your Description" authors = ["Your Name <[email protected]>"]
- Open the project in your preferred IDE.
- Open a Terminal window.
- Ensure you are in the root project directory where the
makefile
is located. - Execute the following commands:
- Poetry start
make poetry_start
- Poetry install
make poetry_install
- Verify that the
.venv
folder has been generated within the/backend
directory.
- To run the backend, execute the following command:
poetry run uvicorn main:app --host 0.0.0.0 --port 8001
Note: Notice that the backend is running on port
8001
. You can change this port by modifying the--port
flag.
Make sure to run this on the root directory.
- To run with Docker use the following command:
make build
- To delete the container and image run:
make clean
You can access the API documentation by visiting the following URL:
http://localhost:<PORT_NUMBER>/docs
E.g. http://localhost:8001/docs
Note: Make sure to replace
<PORT_NUMBER>
with the port number you are using and ensure the backend is running.
- Check that you've created an
.env
file that contains theMONGODB_URI
andORIGINS
variables.
- Add tests
- Evaluate SonarQube for code quality
- Automate the deployment process using GitHub Actions or CodePipeline
- Improve Pydantic usage for API Request and Response models