Skip to content

Latest commit

ย 

History

74 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FinanceAI Logo

FinanceAI โ€” AI-Powered Financial Analysis Platform

DEMO

CONTENTS

  1. About This Project
  2. Features
  3. Tech Stack
  4. Project Structure
  5. Architecture
  6. How It Works
  7. Local Installation (without Docker)
  8. Quick Installation with Docker
  9. Usage
  10. User Interface
  11. Known Limitations
  12. Future Improvements
  13. Author

ABOUT THIS PROJECT

This project began entirely for my own personal interests, and as it progressed, I kept adding new features with growing enthusiasm until it finally reached a point where I could present it here.

Ever since I can remember, Iโ€™ve been a bit of a tightwad, and as I was thinking, โ€œI wish my banking app had a tab that did some kind of analysis so I could track my spending from there.โ€, then it suddenly occurred to me that I study computer engineering.

I really enjoyed working on this project. Since I started it to meet my own needs, I believe I designed its features entirely from the userโ€™s perspective, and I still enjoy using it today.

FEATURES

  • ๐Ÿ“ˆ View the trend of your annual expenses in a single chart.
  • ๐Ÿ“Š See where you spend the most money based on the automatic categorizations created for you.
  • ๐ŸŽฏ Compare your monthly expenses with those of the previous month and see how you're doing.
  • ๐Ÿ–ฅ๏ธ Let the app track your spending at unfamiliar locations and predict it for you.
  • ๐Ÿค– You can consult the Finance Assistant chatbot โ€”customized with your dataโ€” on any topic, and request any kind of analysis.

TECH STACK

Category Technologies
๐Ÿ Language Python
๐Ÿง  AI Google Gemini API
๐Ÿค– Machine Learning scikit-learn
๐ŸŽจ UI Streamlit
๐Ÿ“Š Data Processing Pandas
๐Ÿ“ˆ Data Visualization Plotly
๐Ÿ“ฆ Database SQLite, SQLAlchemy
๐Ÿ”ง Version Control Git
๐Ÿ‹ Containerization Docker

PROJECT STRUCTURE

src/
โ”œโ”€โ”€ application/      # Business logic and application services
โ”œโ”€โ”€ config/           # Application configuration
โ”œโ”€โ”€ data/             # Source datasets
โ”œโ”€โ”€ domain/           # Entities and interfaces
โ”œโ”€โ”€ infrastructure/
โ”‚   โ”œโ”€โ”€ data/         # Data ingestion pipeline
โ”‚   โ”œโ”€โ”€ database/     # SQLite & SQLAlchemy
โ”‚   โ”œโ”€โ”€ llm/          # Gemini client
โ”‚   โ”œโ”€โ”€ ml/           # ML classifier
โ”‚   โ””โ”€โ”€ nlp/          # Text vectorization
โ””โ”€โ”€ presentation/
    โ”œโ”€โ”€ components/   # Reusable Streamlit components
    โ””โ”€โ”€ views/        # Application pages              

ARCHITECTURE

๐Ÿ•‹ Clean Architecture

flowchart TD

U[User]

P[Presentation Layer]

A[Application Layer]

D[Domain Layer]

I[Infrastructure Layer]

DB[(SQLite)]

AI[Gemini API]

ML[ML Classifier]

U --> P
P --> A
A --> D
D --> I

I --> DB
I --> AI
I --> ML

Loading

HOW IT WORKS

๐Ÿ›ฃ๏ธ Data Pipeline

The data pipeline is responsible for transforming raw bank statements into structured, analyzable data. When a user uploads a .xlsx file, the ExcelReader and DataCleaner components (powered by Pandas) immediately strip away irrelevant header rows, normalize date formats, and handle missing values.

Once the data is cleaned, it is passed through the Categorizer class and then the ML Categorization model to assign appropriate expense tags. Finally, the DataBaseMigrator securely saves the processed records into a local SQLite database using SQLAlchemy, ensuring that all user data remains private and local.

flowchart TD

migrator[Database Migrator] -.-> reader
file[.xlsx File] --> reader[ExcelReader]
reader -.-> cleaner[DataCleaner]
cleaner --> |Cleaned Data| reader
reader --> |Raw Transaction List| migrator

migrator -.-> categorizer[Categorizer]
categorizer --> |Categorized List| migrator

migrator -.-> predictor[Predictor] 
predictor --> |List with Unknown Categories Predicted| migrator

migrator --> |Add Transaction List| repo[SQLiteTransactionRepository]
repo -.- |uses| session[Database Session]
repo -.- |maps to| sqlalchemy[SQLAlchemyTransaction]

repo ===>|Saves to| db[(finance_app.db / SQLite)]
Loading

๐Ÿค– AI Assistant Flow

The AI Assistant acts as a bridge between natural language and SQL data, powered by the Gemini 3.6 Flash model. Instead of relying on static prompts, it uses Function Calling. When a user asks a question (e.g., "How much did I spend on food last month?"), the AI decides which internal Python tool to trigger from the tools.json configuration.

The backend executes the corresponding query via financial_service.py, retrieves the exact metrics from the SQLite database, and feeds the factual data back to Gemini. The model then synthesizes this raw data into a clear, conversational Markdown response.

flowchart TD

U[User] --> UI[AI Assistant]
    UI --> AI[AI Service]

    AI --> LLM[Gemini API]

    LLM -->|Function Call| F{Select Function}

    F --> FS[Financial Service]

    FS --> TS[Transaction Service]
    TS --> R[Transaction Repository]
    R --> DB[(SQLite Database)]

    DB --> R
    R --> TS
    TS --> FS
    FS --> F

    FS -->|Function Result| LLM

    LLM -->|Final Response| AI
    AI --> UI
    UI --> U
Loading

๐Ÿ“Š Data Visualization & Chart Analysis

The ๐Ÿ“Š Chart Analysis module provides interactive financial insights through a clean, decoupled architecture. Instead of generating charts directly within the presentation layer, the system delegates this responsibility to the FinancialVisualizer component. When the UI requests a specific view, the visualizer leverages Pandas to aggregate, group, and filter the raw SQLite data. It then uses Plotly Express to render interactive figures (such as spending trends, category breakdowns) and seamlessly returns them to the frontend. This modular approach ensures the UI remains lightweight while delivering highly responsive, zoomable, and interactive visual data to the user.

flowchart TD
    ui[Chart Analysis Page] -->|1. Requests Specific Chart| vis[FinancialVisualizer]
    
    subgraph components/charts.py
        vis -.->|2. Filters & Aggregates Data| pd[Pandas]
        pd -.->|3. Processed DataFrame| px[Plotly Express]
        px -.->|4. Generates Interactive Figure| vis
    end
    
    vis ===>|5. Returns Rendered Figure| ui
    
Loading

๐Ÿ•น๏ธ State Management & Dynamic UI

The application utilizes Streamlit's st.session_state to deliver a highly dynamic and secure user experience. The interface intelligently adapts to the user's current setup:

  • Empty Database Guard: Upon launch, the system checks the SQLite repository. If no transactions are found, it dynamically restricts the navigation menu using st.navigation, hiding the AI and Analysis pages and guiding the user directly to the ๐Ÿ“ Data Management tab.

  • Secure API Key Handling: If the app is deployed via Docker or the .env file is missing, the system intercepts the AI initialization. It presents a secure st.text_input field to collect the Gemini API Key on the fly. Using st.stop() and st.rerun(), the app pauses execution until a valid key is provided, instantly unlocking the AI features without ever exposing or hardcoding credentials.

LOCAL INSTALLATION (WITHOUT DOCKER)

๐ŸŽŸ๏ธ Prerequisites

  • Python 3.9 or higher
  • Git

Step 1: ๐Ÿ‘ฏ Clone the Repository

Open your terminal and run the following commands to clone the project and navigate into the directory:

git clone https://github.com/iremnaz-d/FinanceAI.git
cd FinanceAI

Step 2: ๐Ÿ•๏ธ Create and activate a virtual environment (Recommended)

It is highly recommended to use a virtual environment to avoid conflicts with other packages.

For Windows

python -m venv venv
venv\Scripts\activate

For macOS/Linux

python3 -m venv venv
source venv/bin/activate

Step 3: โฌ†๏ธ Install Dependencies

Install the required Python packages using pip:

pip install -r requirements.txt

Step 4: ๐Ÿƒ๐Ÿปโ€โ™‚๏ธ Run the Application ๐Ÿƒ๐Ÿผโ€โ™€๏ธโ€โžก๏ธ

Start the Streamlit server by running the main application file:

streamlit run src/presentation/run_app.py

QUICK INSTALLATION WITH DOCKER

You can use Docker to run the project on your local machine in an isolated environment without dealing with any Python dependencies.

Step 1: ๐Ÿ‘ฅ Clone the Project

git clone https://github.com/iremnaz-d/FinanceAI.git
cd FinanceAI

Step 2: ๐Ÿ—๏ธ Build The Docker Image

Build the application's Docker image by running the following command in the project's root directory(where the Dockerfile is located). (This process may take 1-2 minutes depending on your computer's speed)

docker build -t finance_ai .

Step 3: ๐Ÿƒ๐Ÿปโ€โ™€๏ธโ€โžก๏ธ Run App ๐Ÿƒ๐Ÿปโ€โ™‚๏ธ

Use the following command to start the application.

Important Note: When the application runs, the database will be automatically created under the src folder. The -v (volume) parameter in the command below ensures that the database inside Docker is synchronized with your local machine. This way, your data will not be lost even if you stop Docker.

For Mac/Linux/Git Bash

docker run -p 8501:8501 -v "$(pwd)/src:/app/src" finance_ai

For Windows PowerShell

docker run -p 8501:8501 -v "${PWD}/src:/app/src" finance_ai

For Windows CMD

docker run -p 8501:8501 -v "%cd%/src:/app/src" finance_ai

Step 4: ๐Ÿ‘€ Access to UI

Once the container is running successfully, open your web browser and go to the following address:

http://localhost:8501

USAGE

After installing and launching the application as described in the Installation section, the user interface will guide you through the process so you'll know exactly what to do.

But if you'd still like some suggestions:

๐Ÿ—ƒ๏ธ Load & Prepare Your Data (Optional)

The app will open with a sample dataset already loaded (Iโ€™m sharing all the transactions Iโ€™ve made with my Ziraat card with you; whoever is reading this, I trust youโ€™re a good personโ€”please donโ€™t let me down ๐Ÿค).

If you want to upload your own data (I think only data from Ziraat will work), make sure the file is in .xlsx format and doesnโ€™t contain any formatting, such as images. You can upload your file from the ๐Ÿ“ Data Management tab.

๐Ÿ” Explore the Analysis

  • From the ๐Ÿ  Homepage tab, you can select a month and view that month's summary:

    • ๐Ÿ“ˆ A graphical and percentage-based comparison of last month and the month you selected

    • โšฝ5๏ธโƒฃ Top 5 expenses of that month

    • ๐Ÿง  You can view the AI's predictions for uncategorized expenses for that month:

      • ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿซ You can correct predictions you think are wrong with the correct answersโ€”my ML model will be retrained based on your feedback!
      • If you'd like, you can add a new category or delete an existing one.
  • In the ๐Ÿ“Š Chart Analysis tab, you can see the ups and downs of your annual spending and how much youโ€™ve spent in each category; if youโ€™d like, you can have my ML model predict the โ€œOtherโ€ category.

  • On the ๐Ÿ’ณ My Transactions tab, you can view all your transactions, filter them by month and category, and delete a transaction if you wish.

๐Ÿค” Ask Questions

You can go to the ๐Ÿค– AI Assistant tab and ask any questions you like. Here are a few questions you can ask:

  • Where have I been drinking coffee the most over the past 6 months?

  • Final exams ended toward the end of Juneโ€”can you tell from my spending?

  • What do you think were my excessive expenses this past March?

  • Why are you so funny? The developer must be a really nice person.

  • Could you compare my spending this April with my spending before April? I kind of lost track of things back then...

โ— Since you'll be running the project externally, the system will ask you for your own Gemini API key. If you don't have one, don't worryโ€”you'll be redirected to a website where you can get one for free!

USER INTERFACE

๐Ÿ’ก Note on Dynamic Navigation: The application features a smart routing system. If your database is empty (i.e., you haven't uploaded a transaction file yet), only the Homepage and Data Management tabs will be visible to smoothly guide you toward setting up your data first.

๐Ÿ  Homepage

Provides a high-level overview of your financial health with quick summaries and an intuitive dashboard layout.

๐Ÿ’ณ My Transactions

Allows you to see and filter your detailed transaction history extracted directly from your bank statements.

๐Ÿ“Š Chart Analysis

Visualizes your income and spending habits over time through interactive and easy-to-read charts.

๐Ÿค– AI Assistant

Acts as your personal financial advisor, allowing you to ask questions about your spending in natural language.

(Note: When running the app in a local environment or via Docker, this page will securely prompt you to enter your Gemini API Key before unlocking the chat interface.)

๐Ÿ“ Data Management

The dedicated space where you can securely upload your bank statement .xlsx files to initialize or update your local database.

KNOWN LIMITATIONS

  • File Type: Only accepts .xlsx files as datasets. I didnโ€™t expand this restriction because I would need a different dataset to do so. Additionally, due to limitations in the pandas library, the file must not contain any formatting (e.g., images) โ€”it should consist solely of text.

  • Same IDs: Only when sending money to another person, the data that appears in the bank account is in sets of two or three entries (one for the amount sent, the others for the amounts withdrawn to send the money), all under the same IDs. I had trouble importing all of these account transactions with the same IDs into the database. Fortunately, this issue doesnโ€™t cause major problems during data analysis.

FUTURE IMPROVEMENTS

User Authentication (Login System):

Implementing a secure login mechanism. This will allow multiple users to use the application safely on the same environment while keeping their financial records completely private.

Transaction Search Bar:

Adding a dynamic search bar to the "My Transactions" page. This will help users easily find specific past expenses by simply typing keywords from the transaction descriptions.

Budget Limits and Alerts:

Allowing users to set custom monthly spending limits for their overall budget or specific categories. The system will send notifications when the user is getting close to their limit and provide a history of which months they successfully stayed on budget.

Export Reports:

Adding a feature to download the monthly financial summaries and interactive charts as PDF or CSV files for external use or printing.

Support for More File Types:

Expanding the file uploader to accept other common data formats (like .csv), removing the strict limitation of only allowing .xlsx files.

Multi-Bank Compatibility:

Currently, the data cleaning process is specifically tailored for Ziraat Bank's statement format. This limitation exists simply because I don't have access to datasets from other banks.

If you use a different bank and would like it to be supported, feel free to share an anonymized sample of your bank statement with me! (please ๐Ÿฅบ) With the right dataset, adapting the pipeline to work for any bank is a very quick and easy process.

AUTHOR

ฤฐrem Naz Durgut

Computer Engineering Student @ Dokuz Eylรผl University

About

An AI-powered personal finance tracker built with Python and Streamlit. Automatic categorization and prediction of expenses, chatbot customized for financial assistancy, and you can see more on ReadMe

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages