Architecture of the app & Dockerising the app

Backend Development Architecture and Setup

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:

Architecture

  1. Frontend Application (Shareholder)

    • Makes HTTP requests to the backend app.
  2. 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
  3. 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.

Setting Up MongoDB

To proceed with development, we need to add MongoDB as a dependency to our service. We have two ways to run MongoDB:

  1. Locally: Good for testing purposes.
  2. Using Docker: Preferred for simplicity and scalability.

Using Docker

We will use Docker to run MongoDB. Here's a step-by-step guide to setting it up:

  1. Create a Docker Compose File:

    • We will use GitHub Copilot to help create our Docker compose files.
  2. Configuration Details:

    • Environment Variables: Set up username and password for MongoDB.
    • Ports and Images: Default ports and MongoDB image will be specified.
  3. Run Docker Compose:

    • Command to create a Docker network and container for MongoDB.
    • Verify if the container is running correctly for MongoDB.
  4. Additional Setup:

    • Add identification commands to run MongoDB as an authorized user.
    • Volume setup to store MongoDB data locally within the application.

Running MongoDB with Docker

To run the MongoDB container:

  1. Execute the docker-compose up command.
  2. Ensure Docker Compose creates the necessary network and containers.
  3. Verify the container status using docker ps.

Conclusion

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.