# bharatbalajid/streamlit_expense_tracker architecture

> Architecture diagram of the GitHub repository bharatbalajid/streamlit_expense_tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bharatbalajid/streamlit_expense_tracker
- Repository: https://github.com/bharatbalajid/streamlit_expense_tracker

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application (“Personal Expense Tracker”) built in Python.
- It uses Streamlit for the UI, MongoDB for data storage, and Plotly for data visualization.
- Purpose: allow users to add, view, analyze, and manage personal expenses, with extra admin controls (bulk delete, CSV export).

##### File structure
- Top-level files only:
– app.py: entry point that defines the Streamlit front-end, business logic, and DB access.
– requirements.txt: declares dependencies (streamlit, pymongo, plotly, etc.).
– README.md: high-level project description.
- No separate “frontend” or “backend” directories—everything lives in a single monolithic script.

##### README for additional insights
- Confirms key flows:
– Add Expense (category, friend, amount, notes)
– View Expenses
– Analytics (category/friend breakdown via interactive charts)
– Delete (single/bulk)
– Admin login (extra controls: delete-all, export CSV)
- Technology stack spelled out: Streamlit, MongoDB, Plotly.

##### Main components
a. Streamlit UI layer
b. Application logic layer (in-app Python functions: validate input, enforce admin auth, invoke DB operations, generate charts)
c. Data access layer (PyMongo client, CRUD operations on MongoDB)
d. MongoDB database (collections: expenses, users/admins)
e. Plotly library (invoked by application logic to render charts in the UI)
f. External CSV export module (could be shown as a utility or service)

##### Relationships and interactions
- User interacts with Streamlit UI → UI calls application logic functions.
- Application logic → reads/writes to MongoDB via PyMongo.
- Application logic → passes data to Plotly to render charts in the UI.
- Admin login flow → application logic verifies credentials against the users/admins collection in MongoDB.
- CSV export → application logic fetches data, generates a CSV, and streams/downloads back to the user.

##### Architectural patterns and design principles
- Monolithic architecture (single process handling UI, business, and data logic).
- Layered separation (Presentation → Business Logic → Data Access).
- External service integration (MongoDB as an external NoSQL store; Plotly as embedded charting library).
- Simple role-based access control (user vs. admin flows).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Browser
    User["User Browser"]:::external

    %% Streamlit Server
    subgraph "Streamlit Server"
        direction TB
        UI["Streamlit UI"]:::server
        BL["Business Logic"]:::server
        CSV["CSV Export Service"]:::server
        DA["Data Access Layer<br/>PyMongo Client & CRUD"]:::server
    end

    %% External Services
    Plotly["Plotly Library"]:::library
    DB["MongoDB Database"]:::db

    %% Documentation
    subgraph "Project Docs"
        README["README.md"]:::external
        Requirements["requirements.txt"]:::external
    end

    %% Data Flows
    User --> UI
    UI --> BL
    BL --> DA
    DA --> DB
    BL --> Plotly
    Plotly --> UI
    BL --> CSV
    CSV --> User

    %% Click Events
    click UI "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click BL "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click CSV "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click DA "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click DB "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click Plotly "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/app.py"
    click README "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/README.md"
    click Requirements "https://github.com/bharatbalajid/streamlit_expense_tracker/blob/master/requirements.txt"

    %% Styles
    classDef server fill:#D6EAF8,stroke:#21618C;
    classDef db fill:#A9DFBF,stroke:#196F3D;
    classDef library fill:#FCF3CF,stroke:#B7950B;
    classDef external fill:#F5B7B1,stroke:#C0392B;
```
