Welcome to the Backend Developer Assessment. This test is designed to evaluate your skills in software development, problem-solving, and software design.
You have been provided with a simple Node.js project: Crypto Currency Transaction Processor, that allows user to create and close cryptocurrency transactions. It uses CryptoCompare API service to get cryptocurrency prices and information.
- Endpoint:
POST /api/create-transaction
- Description: Creates a new cryptocurrency transaction for the given coin symbol and saves the transaction to the database.
- URL:
http://localhost:8085/api/create-transaction
- Method: POST
- Headers:
Content-Type: application/json
- Body:
{ "coin": "ETH", // The symbol of the cryptocurrency (e.g., BTC, ETH). "amount": "10", // The amount of cryptocurrency being transacted. "date": "2024-10-06T11:08:43.641Z" // ISO 8601 format date when the transaction occurs. }
- Status Code: 200 OK
- Body:
{ "transactionId": 1 // The ID of the newly created transaction. }
- Endpoint:
POST /api/close-transaction
- Description: Closes an open cryptocurrency transaction.
- URL:
http://localhost:8085/api/close-transaction
- Method: POST
- Headers:
Content-Type: application/json
- Body:
{ "transactionId": "1" // The ID of the transaction to be closed. }
- Status Code: 200 OK
- Body:
{ "success": true // Confirmation that the transaction has been successfully closed. }
The application uses two main database tables: coin
and userTransaction
. Below is a description of each table and its requirements:
- Description Stores information about different cryptocurrencies fetched from the CryptoCompare API.
- Required The coin info must be populated in order to create a transaction as its id should be used in userTransaction table
- Description: Stores user transaction data related to cryptocurrency purchases for a given coinId.
- Description: This is a background function (
transactionWatcherIfUsdValueBelowOpenRate
) that periodically checks if the current USD price of the coin in a transaction has dropped below the purchase price and automatically closes the transaction.
Your primary objective is to identify and resolve all the issues in the provided codebase. The existing code contains multiple errors, bad practices, and potential bugs. Your task is to analyze the code, pinpoint these issues, and implement solutions to enhance the application's quality and reliability.
-
Identify and Fix Problems:
- Security: Ensure the code is secure against common vulnerabilities.
- DRY Principle: Eliminate repetition by adhering to the "Don't Repeat Yourself" principle.
- Performance: Optimize the code for better performance and efficiency.
- Readability: Improve the clarity and understandability of the code.
- Maintainability: Refactor the code to make it easier to maintain and extend.
- Database & Code Design: Address any flaws in the database schema and overall code architecture.
- Naming Conventions: Use consistent and meaningful names that make sense and adhere to industry standards.
-
Refactor the Code:
- Rewrite portions of the code to address the identified issues.
- Ensure the refactored code adheres to best practices and industry standards.
-
Enable Transaction Watcher:
- The
transactionWatcherIfUsdValueBelowOpenRate
function is currently disabled. Once you have enabled id, address the issues, found in its code, and ensure this function operates correctly.
- The
- Security: Assume that user requests are valid and safe. You do not need to implement authentication or authorization. Treat user IDs as provided.
- Database: use SQLite. Do not switch to a different database system.
- Packages: Utilize only the packages already installed. Do not add new dependencies.
- ORM: No need to implement an Object-Relational Mapping (ORM). Continue using raw SQL queries.
-
Refactored Code:
- Provide the improved and functional code after addressing the issues.
- If the application is not fully functional post-refactoring, ensure the code is clean and free of the identified problems.
-
Issue Report:
- Compile a list of additional potential problems you discovered in the code that were not addressed or implemented in your refactoring.
Your submission will be evaluated based on the following:
- Problem Identification: Ability to accurately identify security vulnerabilities, bad practices, and potential bugs.
- Solution Implementation: Effectiveness of the improvements made to the code.
- Code Quality: Adherence to best practices, readability, and maintainability of the refactored code.
- Performance Optimization: Enhancements that lead to more efficient and performant code.
- Comprehensiveness: Thoroughness in addressing all specified objectives and requirements.
- Setup the Project:
- Install dependencies:
npm install
- Run the application:
npm run dev
- Install dependencies:
- Review the Code:
- Analyze the provided codebase to understand its structure and functionality thoroughly.
- Start Refactoring:
- Identify issues based on the objectives.
- Implement fixes and improvements, ensuring it enhances the application's functionality, maintainability, and performance.
- Thorough Analysis: Carefully review each part of the code to uncover hidden pitfalls and bugs.
- Step-by-Step Approach: Tackle one issue at a time to maintain focus and ensure comprehensive fixes.
- Think Production-Ready: Consider how the application would perform in a real-world production environment.
- Create a List of Identified Issues: As you analyze the code, create a list of all identified issues, including those you plan to address and any additional potential problems. You can submit this list alongside the refactored code for review.
Good luck! 🤗🍀