Calculate the tax the user needs to pay based on the profit or losses of a stock market investment
- Why Python: Because is the programming lenguage that I used daily and I have more experience, is easy to mantain and for the purpose of the app it can be undestood very easly.
- I used the Singleton Design Pattern: The clases ReadJson and CapitalGains classes to ensure that only one instance of each is created during execution
- ReadJson is responsible for parsing the input string into JSON object, and having a single instance avoids redundant parsing logic across modules.
- CapitalGains centralizes the tax calculation logic, ensuring consistency.
- I didn't use a database: The app does not require a database connection, as it doesn’t need to persist any information.
- Architecture: This is a script-style app designed to be used from the console. The user can run the script, provide a JSON string, and receive tax calculations as output.
- Python 3.13.0 (local development)
- All the libraries used by the app are in "requirements.txt"
Pytest: library used for creating tests for the app.
- Install the dependecies:
pip install -r requirements.txt
- Run the following command:
python main.py -j '[{"operation":"buy","unit-cost":10.0,"quantity":100},{"operation":"sell","unit-cost":15.0,"quantity":50},{"operation":"sell","unit-cost":15.0,"quantity":50}]'
- Create the build
docker build -t capital-gains .
- Run the container, this will create a new instance of the container
docker run -it capital-gains
- It will enter to the console, you will see:
root@cb8dbed4c114:/app#
- To run the app, use the command:
python main.py -j '[{"operation":"buy","unit-cost":10.0,"quantity":100},{"operation":"sell","unit-cost":15.0,"quantity":50},{"operation":"sell","unit-cost":15.0,"quantity":50}]'
- These commands can be used locally or inside the docker container
- Run the following command for running unit and integration tests:
pytest tests/
- Run the following command for integration tests:
pytest tests/integration/
- Run the following command for running unit tests:
pytest tests/unit/


