How bharat-panchal15/flask-expense-tracker works
Project type and purpose
• This is a full-stack web application built with Python’s Flask framework.
• Purpose: provide a budgeting and expense-tracking interface (static JS + Jinja templates on the front end, RESTful API and server-rendered routes on the back end, persistent storage via a relational database managed with Alembic migrations).
File structure
Top-level files and directories:
• run.py – application entry point
• config.py – configuration (database URL, secret keys, environment flags)
• requirements.txt – Python dependencies (Flask, Flask-SQLAlchemy, Flask-Migrate, etc.)
• app/ – core application package
– __init__.py – app factory, initialize extensions
– extensions.py – instantiate SQLAlchemy, Migrate, JWT, etc.
– models.py – ORM models (User, Expense, Budget)
– api/ – programmatic API layer for budgets and expenses
• resources.py – defined API resources/endpoints
• budget_utils.py / utils.py – shared business logic
– routes/ – server-rendered (non-API) routes and views
– static/ – JavaScript modules for front-end interactivity (dashboard.js, budgets.js, etc.)
– templates/ – Jinja2 templates for HTML views
• migrations/ – Alembic scripts for database version control
README
• (No content provided, so inference is based on file structure and naming conventions.)
Components
a. Main components
1. Client (Browser): requests HTML pages, makes XHR/fetch calls to API
2. Web Server (Flask app – run.py + app factory)
3. Routing Layer:
• Server-Rendered Routes (app/routes)
• REST API Endpoints (app/api/resources.py)
4. Business Logic Layer (budget_utils.py, utils.py, models.py)
5. Persistence Layer (Relational Database)
6. Migration Service (Alembic via Flask-Migrate)
7. Configuration & Extensions (Flask extensions: SQLAlchemy, Migrate, JWT, etc.)
b. Relationships & Interactions
• Client ↔ Server-Rendered Routes: initial page loads (templates + static assets)
• Client ↔ REST API: JSON payloads for CRUD on budgets/expenses
• Routes & Resources → Business Logic → Models → Database
• Migrations → Database (version control for schema changes)
c. Architectural patterns / design principles
• Application Factory pattern for Flask initialization
• Layered architecture: Presentation (templates + JS), API, Business Logic, Data Access
• Separation of concerns: app/api vs. app/routes vs. app/models vs. app/static vs. app/templates
• DB migrations for schema evolution
d. Key technologies/frameworks
• Flask
• Flask-SQLAlchemy
• Flask-Migrate (Alembic)
• Jinja2 templates
• Vanilla JS modules in app/static