How pallavi-sinha-12/expense-tracker-chatbot works
Project Type and Purpose
• This is a full-stack conversational AI expense-tracker.
• It uses Rasa (NLU + dialogue management), custom Python actions for DB I/O, a Streamlit front-end chat interface, and an optional static website that embeds the chatbot via an iframe.
• It supports two database backends (PostgreSQL or Azure SQL) and can produce both on-screen visualizations and downloadable CSVs.
Main Components
a. Presentation Layer
• Streamlit App (Expense-Tracker-Chatbot.py, runs on port 8501) – the primary chat UI.
b. Conversational Engine
• Rasa Core & NLU Server (rasa run --enable-api → port 5005)
– config.yml (pipeline & policy definitions)
– data/nlu.yml, data/rules.yml, data/stories.yml (training data)
– domain.yml (intents, entities, actions, responses)
– endpoints.yml (action endpoint configuration)
• Rasa Actions Server (rasa run actions → port 5055 by default) – hosts actions/actions.py
c. Application/Service Layer
• Custom Actions (actions/actions.py) – handles expense-entry workflows, chart requests, date parsing, confirmation dialogs.
• Data Exporter (data_exporter/CSVFile.py) – exports chart data to CSV when requested.
d. Data Access Layer
• DatabaseFactory (database/DatabaseFactory.py) – Factory pattern to instantiate connector + query objects based on the chosen DB type.
• Abstract Base Classes
– DatabaseConnector (database/DatabaseConnector.py)
– VisualisationQuery (database/VisualisationQuery.py)
• Concrete Implementations
– PostgreSQL
· PostgresSQLDatabaseConfig.py (connection params)
· PostgresSQLDatabaseConnector.py (psycopg2‐based CRUD)
· PostgresVisualisationQuery.py (SQL for charts)
· setup_script.sql (schema creation)
– Azure SQL
· AzureKeyVault.py (fetches secret via Azure SDK)
· AzureSQLDatabaseConfig.py
· AzureSQLDatabaseConnector.py (pyodbc‐based CRUD)
· AzureSQLVisualisationQuery.py
• Configuration File (database/database_config.yaml) – generated by create_database_config.py
e. Data Storage & External Services
• Azure SQL Database (+ Azure Key Vault for secrets)
• PostgreSQL (optional)
• ODBC driver or psycopg2 driver
Relationships & Interactions
• The user (browser) → interacts with Streamlit App (or via static website iframe).
• Streamlit forwards user messages via HTTP to the Rasa Core Server (5005).
• Rasa Core processes intent/entity → if a custom action is needed, it calls the Rasa Actions Server.
• The action code uses DatabaseFactory → instantiates a connector & query object → performs CRUD or fetches visualization data from the chosen Database.
• Visualization data returns to Streamlit, which renders an interactive bar chart or triggers CSV export via data_exporter.
Architectural Patterns & Design Principles
• Layered Architecture (Presentation → Application → Data Access → Persistence)
• Factory Pattern (DatabaseFactory) for pluggable DB providers
• Dependency Inversion: actions depend on abstract connectors & queries
• Process Separation:
• Streamlit App (UI)
• Rasa Core + NLU
• Rasa Actions
• Static Web Server
• Extensibility Points: add new DB by subclassing DatabaseConnector + VisualisationQuery
Essential Elements
• Ports & protocols on connectors (e.g., HTTP 5005, psycopg2)
• Factory Pattern call from Actions to DatabaseFactory → Connector + Query