Before diving into the backend development, let's overview the simple architecture for our backend app. Here's a breakdown of how the components will interact and function:
Frontend Application (Shareholder)
Makes HTTP requests to the backend app.
Backend Services
Shareholder Service: An Express router that will handle REST calls related to shareholders.
Company Service: An Express router that responds to REST calls regarding company data.
Equity Service: This is the core business logic of our application. It will respond to four events:
Capitalization
Initial Shares Release
Shares Update
Share Split
Database
MongoDB: Simple database to store shareholder and company data. We will have two main collections:
Shareholder: Consisting of fields - ID, name, email, and company shares.
Company: Consisting of fields - ID, name, the number of shareholders, capitalizations, and the amount of available shares.
To proceed with development, we need to add MongoDB as a dependency to our service. We have two ways to run MongoDB:
Locally: Good for testing purposes.
Using Docker: Preferred for simplicity and scalability.
We will use Docker to run MongoDB. Here's a step-by-step guide to setting it up:
Create a Docker Compose File:
We will use GitHub Copilot to help create our Docker compose files.
Configuration Details:
Environment Variables: Set up username and password for MongoDB.
Ports and Images: Default ports and MongoDB image will be specified.
Run Docker Compose:
Command to create a Docker network and container for MongoDB.
Verify if the container is running correctly for MongoDB.
Additional Setup:
Add identification commands to run MongoDB as an authorized user.
Volume setup to store MongoDB data locally within the application.
To run the MongoDB container:
Execute the docker-compose up
command.
Ensure Docker Compose creates the necessary network and containers.
Verify the container status using docker ps
.
By following these steps, we now have a Docker setup for a MongoDB instance ready to support the backend services. This setup ensures our backend app can handle business logic efficiently while maintaining data integrity and persistence.