How thiagofsdata-collab/credit-risk-analysis works
1. Purpose and shape of the repo
This is an end-to-end credit risk analytics pipeline, not a general application. It takes a Kaggle loan default dataset, loads it into PostgreSQL, transforms it into a cleaned analytical layer, runs segment/risk analyses in SQL + Python, and publishes results in Power BI.
2. Primary data flow
The core flow is: external CSV dataset → raw database table → cleaned database table → analytical SQL queries / pandas metrics → exported outputs and dashboard. The repository is organized around this pipeline rather than around a service/API boundary.
3. Ingestion boundary
src/ingestion/load_data.py is the entry point for bringing the raw Kaggle file into the database. This is the boundary between file-based input and the relational model. The README indicates the raw file is not versioned and must be supplied locally, so ingestion depends on external user setup.
4. Database and transformation layer
sql/schema/01_create_tables.sql and sql/schema/02_create_clean_table.sql define the persistent warehouse-like layers:
- loans_raw for imported source data
- loans_clean for standardized, imputed, and feature-engineered data
This is the main architectural separation: raw data is preserved, while downstream work is done from a curated table.
5. Analytical SQL layer
sql/queries/ contains the business logic for the core metrics:
- default rate by segment
- delinquency risk profiling
- portfolio risk concentration
These queries are where segmentation, ranking, and concentration analysis live. The README shows use of CTEs and window functions, so the database is doing much of the heavy analytical work.
6. Python analysis layer
src/analysis/credit_risk_analysis.py likely extracts results from PostgreSQL and computes portfolio metrics or summary tables with pandas and SQLAlchemy. This layer sits between the database and the reporting artifacts, handling analysis that is easier in Python than in pure SQL.
7. Visualization and reporting boundary
src/visualization/dashboard.py supports dashboard-oriented data preparation, while the primary reporting artifact is the Power BI dashboard in outputs/credit_risk_dashboard.pbix. The dashboard connects directly to PostgreSQL, so reporting is database-backed rather than file-backed.
8. Exploratory analysis vs. production analysis
notebooks/exploratory/01_eda_credit_risk.ipynb is separate from the scripted pipeline and serves as exploratory work. That makes the repo split fairly clear: notebooks for discovery, SQL/Python scripts for repeatable analysis, Power BI for presentation.
9. Artifacts and deliverables
The outputs/ folder contains exported analysis results, figures, and the Power BI file. This indicates the repo is designed to produce reusable deliverables rather than only interactive runtime output.
10. Supporting documentation and semantic layer
docs/data_dictionary.md suggests the project defines dataset fields and business meanings explicitly, which is important because the main transformations depend on domain-specific interpretations like delinquency, utilization, and income bands.
11. Runtime and infrastructure assumptions
The architecture depends on:
- PostgreSQL 15 running in Docker
- Python 3.11
- local credentials/config for database access
- a manually supplied Kaggle CSV
Power BI is a separate desktop consumer of the curated database, not part of the Python runtime.
12. How to think about the boundaries in a diagram
A good architecture diagram should show three major zones:
- Source/ingestion zone: Kaggle CSV + loader script
- Data/analytics zone: PostgreSQL raw/clean tables + SQL queries + Python analysis
- Presentation zone: Power BI dashboard and exported figures/reports
The most important boundary is between raw source data and clean analytical data, because that is where the project’s business logic is concentrated.
Main entry points: data_dictionary.md Data Dictionary · load_data.py Load Data · 01_create_tables.sql Raw Schema · 02_create_clean_table.sql Clean Schema
Components 16
Source & Ingestion
External dataset and entry point into PostgreSQL.
- Kaggle CSV · Manually supplied loan default source file.
- Load Data · Imports the raw Kaggle file into PostgreSQL.
src/ingestion/load_data.py
Warehouse Layer
Raw and cleaned database tables plus schema definitions.
- PostgreSQL · Operational analytical database backing the pipeline.
- Raw Schema · Creates the preserved raw loans table.
sql/schema/01_create_tables.sql - Clean Schema · Creates the standardized analytical loans table.
sql/schema/02_create_clean_table.sql - Loans Raw · Imported source data stored without transformation.
- Loans Clean · Cleaned and feature-engineered dataset for analysis.
Analytics Layer
SQL business logic and Python-based analysis.
- Segment Risk · Default rate analysis by borrower segment.
sql/queries/01_default_rate_by_segment.sql - Delinquency Profile · Profiles delinquency and risk behavior.
sql/queries/02_delinquency_risk_profile.sql - Risk Concentration · Measures portfolio concentration and ranking.
sql/queries/03_portfolio_risk_concentration.sql - Credit Analysis · Runs pandas/SQLAlchemy analysis against PostgreSQL.
src/analysis/credit_risk_analysis.py
Reporting Layer
Dashboard preparation and published deliverables.
- Dashboard Prep · Prepares data structures for dashboard consumption.
src/visualization/dashboard.py - Power BI Dashboard · Published interactive dashboard connected to PostgreSQL.
outputs/credit_risk_dashboard.pbix - HTML Export · Static dashboard export for sharing and review.
outputs/figures/credit_risk_dashboard.html
Supporting Assets
Documentation and exploratory analysis.
- EDA Notebook · Exploratory analysis used for discovery and validation.
notebooks/exploratory/01_eda_credit_risk.ipynb - Data Dictionary · Defines dataset fields and business meanings.
docs/data_dictionary.md
Connections 16
- Kaggle CSV → Load Data: input · Local source file is loaded by the ingestion script.
- Load Data → PostgreSQL: write · Loads source data into the database.
- Raw Schema → Loans Raw: creates · Defines the raw landing table.
- Clean Schema → Loans Clean: creates · Defines the curated analytical table.
- Loans Raw → Loans Clean: transform · Raw data is standardized and feature-engineered into the clean layer.
- Loans Clean → Segment Risk: analyze · Clean data feeds default-rate segmentation.
- Loans Clean → Delinquency Profile: analyze · Clean data feeds delinquency profiling.
- Loans Clean → Risk Concentration: analyze · Clean data feeds concentration analysis.
- PostgreSQL → Credit Analysis: read · Python analysis extracts data from the database.
- Credit Analysis → Dashboard Prep: prepare · Analysis outputs are shaped for dashboard use.
- Dashboard Prep → Power BI Dashboard: publish · Prepared outputs support the Power BI report.
- PostgreSQL → Power BI Dashboard: connects to · Dashboard reads curated data directly from PostgreSQL.
- PostgreSQL → HTML Export: source · Exported figures are derived from database-backed analysis.
- EDA Notebook → Loans Clean: explore · Notebook work uses the curated dataset for investigation.
- Data Dictionary → Raw Schema: defines · Semantic definitions inform the database schema.
- Data Dictionary → Clean Schema: defines · Business meanings guide cleaning and feature engineering.