# tphat77923/bank-noti-box architecture

> Architecture diagram of the GitHub repository tphat77923/bank-noti-box, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tphat77923/bank-noti-box
- Repository: https://github.com/tphat77923/bank-noti-box

## Overview

##### Project Overview
- This is a Python-based full-stack monitoring application designed to periodically check SePay’s API for new bank transactions.
- It displays the latest transactions on a self-hosted webpage and produces an audible notification when a new incoming (amount_in > 0) transaction is detected.
- The project is simple in structure, with a single Python entry-point (app.py), HTML templates (in the templates folder), and an audio file (ting.mp3) for notifications.

##### Main Components of the System
a. Backend/Service Layer (app.py)
- This file is the central entry-point of the application.
- It is responsible for:
- Polling the SePay API every 2 seconds to check for new transactions.
- Processing the API responses and filtering for incoming transactions.
- Initiating the sound notification when applicable.
- Passing the transaction data to the web interface.
b. Web Interface (templates/index.html)
- Provides a simple frontend that displays a list of the most recent transactions.
- Likely powered by a Python web framework (e.g., Flask) that renders HTML templates.
c. Notification Service (ting.mp3 combined with external mpv player)
- When a valid transaction is detected (money coming in), the application triggers a sound notification using an external media player (mpv) to play the ting.mp3 file.
d. External Dependencies
- SePay API: The application integrates with this API to fetch transaction data.
- Python libraries as listed in requirements.txt and the externally-installed mpv.

##### Relationships and Interactions
- The app.py serves as the application’s controller that coordinates between components:
- It periodically initiates API calls to SePay.
- When new transactions are detected, data flows from the API fetch layer into the transaction processing logic.
- If an “incoming” transaction is identified, the notification service (mpv + ting.mp3) is triggered.
- Independently or in parallel, the backend continuously updates the web interface data, which is rendered using the HTML template.
- Users access the web interface by connecting to the local host (e.g., http://localhost:3000).

##### Architectural Patterns and Design Principles
- The design is a simple monolithic application. Despite its simplicity, it follows a separation of concerns:
- Polling/processing logic versus presentation (web template).
- External service integration (SePay API) is segregated from UI and notification functions.
- The polling mechanism (every 2 seconds) is an example of a recurring task that could be visualized as a loop or scheduler.
- Use of external tools (mpv for audio) suggests a loosely coupled integration pattern for non-Python dependencies.

##### Final Elements
- Component is clearly labeled (e.g., “Transaction Fetcher”, “Web Interface”, “Audio Notifier”, “SePay API”).
- Data flow from the API to the processor and then to the notifier and web interface.
- Request-response cycle between the Web Browser/Client and the Web Server.
- Backend processing versus frontend elements.
- External dependencies (like the SePay API and mpv) to differentiate them from native Python components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    SAE("SePay API"):::external

    %% Backend Services
    subgraph "Backend Services"
        AP("API Poller & Transaction Processor"):::backend
        EP("External Python Dependencies"):::external
        NS("Notification Service"):::notifier
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        WS("Web Server/Interface"):::frontend
        WB("Web Browser/Client"):::frontend
    end

    %% Data Flow
    SAE -->|"fetches_data"| AP
    EP -->|"libraries"| AP
    AP -->|"trigger"| NS
    AP -->|"update"| WS
    AP -->|"poll(2s)"| AP
    WB -->|"requests"| WS

    %% Click Events
    click AP "https://github.com/tphat77923/bank-noti-box/blob/main/app.py"
    click WS "https://github.com/tphat77923/bank-noti-box/blob/main/templates/index.html"
    click NS "https://github.com/tphat77923/bank-noti-box/blob/main/ting.mp3"
    click EP "https://github.com/tphat77923/bank-noti-box/blob/main/requirements.txt"

    %% Styles
    classDef backend fill:#A2D2FF,stroke:#333,stroke-width:2px;
    classDef frontend fill:#CAF0F8,stroke:#333,stroke-width:2px;
    classDef external fill:#F7A072,stroke:#333,stroke-width:2px;
    classDef notifier fill:#BDE0FE,stroke:#333,stroke-width:2px;
```
