Recently, I added a simple chatbot to my Finovara app that answers users’ finance-related questions.
No AI, no NLP libraries — just clean architecture, enums, and text files.
It works surprisingly well for the limited scope we need. Here’s how it’s built.
The Idea
The chatbot works like this:
- A user asks a question.
- The system normalizes the input.
- It maps the question to a predefined entry.
- The entry corresponds to a SmartReportType enum.
- The enum is handled by a handler class.
- The handler generates the actual response.
This makes the system:
- Predictable
- Easy to extend
- Fast and lightweight
Core Architecture
The main entry point is:
public String generateResponse(String email, String userQuestion) {
User user = userManagerService.getUserByEmailOrThrow(email);
SmartReportType type = smartReportQuestionService.getTypeFromQuestion(userQuestion);
if (type == null)
return "I’m not smart enough to answer this question. Please ask a question from the question book!";
SmartReportHandler handler = handlers.get(type);
if (handler == null) {
return "Report type not supported";
}
return handler.generate(user.getId());
}
Here’s what’s happening:
The question is mapped to a SmartReportType enum.
Each enum has its own handler.
The handler generates a response based on templates and user data.
This is basically a Strategy Pattern in action.
Mapping Questions to Enums
Instead of hardcoding questions in Java, they are stored in TXT files:
MONTH_SPENDING | how much did i spend this month
MONTH_SPENDING | monthly expenses
AVERAGE_DAY_SPENDING | average daily spending
EXPENSE_RATE | what percentage of my income is spent
SAVINGS_RATE | how much did i save
Loader Service:
questionMap.put(question, SmartReportType.valueOf(enumName));
Normalization:
private String normalize(String text) {
return text.toLowerCase()
.trim()
.replace("?", "");
}
Thanks to this:
- “How much did I spend?”
- “how much did i spend”
- “HOW MUCH DID I SPEND??”
all map to the same key.
Handlers: Business Logic
Each enum type has its own handler:
public interface SmartReportHandler {
SmartReportType getType();
String generate(Long userId);
}
Handlers are responsible for fetching user data and generating responses.
Example: Expense Rate
BigDecimal total = sumExpenses.multiply(BigDecimal.valueOf(100))
.divide(sumRevenue, 2, RoundingMode.HALF_UP);
String template = templateService.getRandomResponse(SmartReportType.EXPENSE_RATE);
return template.replace("{amount}", total.toString());
Dynamic Responses (Templates)
Responses are stored in text files instead of being hardcoded:
You spent {amount} this month.
Your total expenses are {amount}.
Your savings rate is {amount}%.
Randomization makes replies feel less repetitive:
return responses.get(random.nextInt(responses.size()));
*Thanks for reading! *
If you’re curious to see the full project or try it yourself, check out the code on GitHub:
M4rc1nek
/
finovara-backend
Backend service for a personal finance management application
Finovara
Finovara is a financial management platform designed to help users effectively track analyze, and optimize their income, expenses, and savings The application provides a secure, bank-like experience focused on transparency, financial awareness, and long-term money planning.
🎯 Purpose of the Application
Finovara aims to support users in making better financial decisions by offering clear insights into their financial activity and helping them maintain control over their budgets and savings.
The platform focuses on:
- organizing income and expenses in a structured way
- visualizing financial data through charts and statistics
- supporting saving goals and spending limits
- providing a virtual wallet concept for daily financial management
🚀 Key Features
- Secure user authentication and authorization
- Income and expense tracking
- Categorization of financial operations
- Interactive charts and financial statistics
- Reports summarizing spending and income trends
- Virtual wallet management
- Savings goals (e.g. piggy banks)
- Spending limits and budget control
- Scalable architecture prepared for future financial…
Top comments (0)