Account
Users/Clients
|
v
+-------------------------------+
| API Endpoints |
+-------------------------------+
|
v
+-------------------------------+
| Fetch Account Details |----> Get Account Details from DB
| (GET /accounts/:id) | |
+-------------------------------+ |
| v
v +---------------------+
+----> Accounts Table | Accounts Table |
| | +---------------------+
| v |
| Fetch Transactions from DB |
| | |
| v v
| Transactions Table Fetch Last Audit Log (Optional)
| | |
| v v
| Return Account Details Audit Logs Table
v
+-------------------------------+
| Fetch Category Names |----> Fetch Categories from DB
| (GET /categories) | |
+-------------------------------+ v
| +---------------------+
+----> Categories Table | Categories Table |
| +---------------------+
v |
+----> Return Category Names |
v
+-------------------------------+
| Create Transaction |----> Insert Transaction into DB
| (POST /transactions) | |
+-------------------------------+ v
| +---------------------+
+----> Transactions Table | Transactions Table |
| | +---------------------+
| v |
| Log Audit Change |
| | |
| v v
| Audit Logs Table Log Audit Changes
v
+-------------------------------+
| Bulk Create Transactions |----> Insert Transactions into DB
| (POST /transactions/bulk-create) |
+-------------------------------+ v
| +---------------------+
+----> Transactions Table | Transactions Table |
| | +---------------------+
| v |
| Log Audit Changes |
| | |
| v v
| Audit Logs Table Log Audit Changes
v
+-------------------------------+
| Delete Transaction |----> Delete Transaction from DB
| (DELETE /transactions/:id) | |
+-------------------------------+ v
| +---------------------+
+----> Transactions Table | Transactions Table |
| | +---------------------+
| v |
| Log Audit Change |
| | |
| v v
| Audit Logs Table Log Audit Change
v
+-------------------------------+
| Bulk Delete Transactions |----> Delete Transactions from DB
| (POST /transactions/bulk-delete) |
+-------------------------------+ v
| +---------------------+
+----> Transactions Table | Transactions Table |
| | +---------------------+
| v |
| Log Audit Changes |
| | |
| v v
| Audit Logs Table Log Audit Changes
v
+-------------------------------+
| Update Transaction |----> Retrieve Current Transaction from DB
| (PATCH /transactions/:id) | |
+-------------------------------+ v
| +---------------------+
+----> Transactions Table | Transactions Table |
| | +---------------------+
| v |
| Update Transaction in DB |
| | |
| v v
| Log Audit Change |
| | |
| v v
| Audit Logs Table Log Audit Change
v
+-------------------------------+
| Fetch Proof of Payments |----> Get Payments from DB
| (GET /payments) | |
+-------------------------------+ v
| +---------------------+
+----> Payments Table | Payments Table |
| | +---------------------+
| v |
+----> Return Payments |
v
+-------------------------------+
| Process Proof of Payment |----> Update Payment Status in DB
| (PATCH /payments/:id) | |
+-------------------------------+ v
| +---------------------+
+----> Payments Table | Payments Table |
| | +---------------------+
| v |
| Log Audit Change |
| | |
| v v
+----> Audit Logs Table Log Audit Change
v
+-------------------------------+
| Resolve Proof of Payment |----> Update Payment Status in DB
| (PATCH /payments/:id/resolve) | |
+-------------------------------+ v
| +---------------------+
+----> Payments Table | Payments Table |
| | +---------------------+
| v |
| Log Audit Change |
| | |
| v v
+----> Audit Logs Table Log Audit Change
Table of Contents
- Overview
- API Endpoints
- Database Models
- Relational Flow Diagram
- Implementation Details
- Error Handling
- Conclusion
Overview
The system provides functionalities to manage account details and transactions, including:
- Fetching account details and related transactions.
- Filtering and sorting transactions by various criteria.
- Handling user interactions and displaying transaction summaries.
API Endpoints
Get Account Details
- Purpose: Retrieve details of an account, including its transactions and metadata.
- Endpoint:
GET /accounts/:id - Parameters: Account ID.
- Response:
{ "id": "string", "plaidId": "string", "name": "string", "userId": "string", "transactions": [ { "id": "string", "date": "date", "amount": "number", "description": "string", "category": "string", "categoryType": "string" } ], "lastUpdatedBy": "string", "lastUpdatedAt": "date" }
Get Category Names
- Purpose: Retrieve a list of all category names.
- Endpoint:
GET /categories - Response:
["category1", "category2", "category3"]
Database Models
The primary database models involved in this system are:
- Accounts: Stores account information.
- Transactions: Records details of financial transactions.
- Categories: Defines transaction categories.
- Audit Logs: Tracks changes for auditing purposes.
Relational Flow Diagram
Here is an ASCII representation of the relational flow diagram:
+---------------------+
| Users/Clients |
+----------+----------+
|
v
+----------+----------+
| API Endpoints |
+----------+----------+
|
v
+----------------------+ +----------------------+
| Get Account Details| | Get Category Names |
| (GET /accounts/:id)| | (GET /categories)|
+----------+----------+ +----------+----------+
| |
v v
+----------+----------+ +-----------+-----------+
| Fetch Account | | Fetch Categories |
| Details from DB | | from DB |
+----------+----------+ +-----------+-----------+
| |
v v
+----------+----------+ +-----------+-----------+
| Accounts Table | | Categories Table |
+---------------------+ +-----------------------+
|
v
+----------+----------+
| Fetch Transactions |
| from DB |
+----------+----------+
|
v
+---------------------+
| Transactions Table |
+---------------------+
|
v
+----------+----------+
| Fetch Last Audit |
| Log from DB |
+----------+----------+
|
v
+---------------------+
| Audit Logs Table |
+---------------------+
Implementation Details
Account Management
- Fetching Account Details: The system retrieves account details, including metadata such as the last update information. If an account is not found, it fetches details based on the category.
- Fetching Transactions: Transactions related to the account are retrieved from the database, including details like date, amount, description, and category.
- Fetching Audit Logs: The system retrieves the last audit log entry for the account to provide information about the last update.
Filtering and Sorting Transactions
Filter and Calculate Transactions
|
+---> Get Account Details (API Call)
|
+---> Fetch Account Data
| |
| +---> Accounts Table
| +---> Transactions Table
| +---> Categories Table
| +---> Audit Logs Table
|
+---> Process Account Data
|
+---> Filter Transactions
| |
| +---> Filter by Type
| | |
| | +---> Income
| | +---> Expense
| |
| +---> Filter by Category
| | |
| | +---> Category A
| | +---> Category B
| |
| +---> Filter by Date Range
| | |
| | +---> From Date
| | +---> To Date
| |
| +---> Filter by Search Term
| |
| +---> Description Contains
| |
| +---> Search Term
|
+---> Calculate Totals
|
+---> Total Income
| |
| +---> Sum of Income Transactions
|
+---> Total Expenses
| |
| +---> Sum of Expense Transactions
|
+---> Remaining Balance
|
+---> Total Income - Total Expenses
|
+---> By Category
|
+---> Category A
| |
| +---> Sum of Transactions in Category A
|
+---> Category B
|
+---> Sum of Transactions in Category B
- Filter and Calculate Transactions: The main process that handles filtering transactions and calculating totals.
- Get Account Details (API Call): Initiates the retrieval of account details from the database.
- Fetch Account Data: Interacts with various database tables to get account and transaction details.
- Process Account Data: Processes the fetched data to apply various filters and perform calculations.
- Filter Transactions: Applies different types of filters to the transactions.
- Filter by Type: Filters transactions by type (income or expense).
- Filter by Category: Filters transactions by category.
- Filter by Date Range: Filters transactions within a specified date range.
- Filter by Search Term: Filters transactions where the description contains the search term.
- Filter Transactions: Applies different types of filters to the transactions.
- Calculate Totals: Calculates the totals for filtered transactions.
- Total Income: Calculates the total income by summing income transactions.
- Total Expenses: Calculates the total expenses by summing expense transactions.
- Remaining Balance: Calculates the remaining balance by subtracting total expenses from total income.
- By Category: Calculates totals for each category by summing transactions within each category.
Error Handling
The system includes robust error handling mechanisms to ensure smooth operation:
- Unauthorized Access: Ensures only authenticated users can access or modify data.
- Missing Data: Handles cases where required data is missing or invalid.
- Database Errors: Catches and logs database errors for troubleshooting.
- User Feedback: Provides clear feedback to users on the success or failure of their actions.