A comprehensive visualization tool for the Qualified Business Income Deduction (Section 199A) calculation in PolicyEngine US.
- Complete Input-to-Output Flow Visualization: Shows all input variables flowing through to the final QBI deduction
- Dynamic GitHub Integration: Automatically pulls latest PolicyEngine US code from master branch
- Parameter Visibility: Displays all parameters used in formulas with direct links to YAML files
- Interactive Dependency Graph: Click any variable to see its formula, dependencies, and references
- Legal References: Direct links to USC statutes, IRS forms, and publications
- TAXSIM Comparison: Compare PolicyEngine calculations against TAXSIM (optional)
- GitHub Manager: Clones and syncs policyengine-us from GitHub
- Code Extractor: Dynamically parses Python variables using AST
- Parameter Extractor: Extracts parameter values from YAML files
- Calculator: Runs actual PolicyEngine calculations with intermediate steps
- API: REST endpoints for variables, parameters, calculations, and comparisons
- Flow Visualization: Interactive computation graph showing inputs → outputs
- Variable Details Panel: Shows formulas, dependencies, parameters, and references
- Input Controller: Set scenario inputs and run calculations
- Comparison View: Side-by-side PolicyEngine vs TAXSIM results
- Python 3.10+
- Node.js 18+
- Git
cd backend
pip install -e .cd frontend
npm installTerminal 1 - Backend:
cd backend
uvicorn app.main:app --reload --port 8000Terminal 2 - Frontend:
cd frontend
npm run devCreate backend/.env:
# GitHub Configuration
GITHUB_REPO=https://github.com/PolicyEngine/policyengine-us.git
GITHUB_BRANCH=master
AUTO_SYNC_MINUTES=30
# Local Paths
REPOS_DIR=./data/repos
CACHE_DIR=./data/cache
# TAXSIM Integration (Optional)
TAXSIM_PATH=/path/to/taxsim
TAXSIM_EXECUTABLE=taxsim35- View Complete Flow: See all QBI inputs → final deduction with parameters
- Click Variables: View source code, formulas, and GitHub links
- Click Parameters: See YAML files, values, and legal references
- Run Calculations: Enter scenario inputs and see step-by-step results
- Compare with TAXSIM: Run same scenario through both systems
- 6 income sources (self-employment, partnership, rental, farm ops, farm rent, estate)
- 6 qualification flags (would_be_qualified for each income source)
- 3 QBI deductions (SE tax, health insurance, pension)
- 2 business properties (W-2 wages, property basis)
- 2 business type flags (is_sstb, is_qualified)
- 3 tax unit inputs (taxable income, filing status, capital gains)
- Income and deduction definition lists
- 4 rates (base 20%, wage 50%, alt wage 25%, property 2.5%)
- 2 phase-out parameters (start threshold, length)
- 2 deduction floor parameters (in_effect, amount)
- Final qualified_business_income_deduction at tax-unit level
qbi-visualizer/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI app
│ │ ├── config.py # Configuration
│ │ ├── api/ # API endpoints
│ │ │ ├── variables.py
│ │ │ ├── parameters.py
│ │ │ ├── calculate.py
│ │ │ └── compare.py
│ │ ├── services/ # Core services
│ │ │ ├── github_manager.py
│ │ │ ├── code_extractor.py
│ │ │ ├── parameter_extractor.py
│ │ │ ├── calculator.py
│ │ │ └── cache_manager.py
│ │ ├── models/ # Pydantic models
│ │ └── utils/ # Utilities
│ ├── scripts/ # One-time scripts
│ ├── data/ # Git repos, cache
│ └── tests/
├── frontend/
│ ├── src/
│ │ ├── pages/ # Main views
│ │ │ ├── FlowView.tsx
│ │ │ ├── TableView.tsx
│ │ │ └── ComparisonView.tsx
│ │ ├── components/ # UI components
│ │ │ ├── FlowGraph.tsx
│ │ │ ├── VariableDetail.tsx
│ │ │ ├── InputPanel.tsx
│ │ │ └── ParameterDisplay.tsx
│ │ ├── hooks/ # React hooks
│ │ └── types/ # TypeScript types
│ └── public/
└── docs/
The system automatically detects new QBI-related variables when syncing from GitHub.
Parameter values are extracted dynamically from YAML files in the policyengine-us repo.
Edit frontend/src/components/FlowGraph.tsx to change the flow diagram layout.
- 26 USC § 199A: Qualified Business Income Deduction
- IRS Publication 535: Business Expenses (Worksheet 12-A)
- Form 8995: Qualified Business Income Deduction Simplified Computation
- Form 8995-A: Qualified Business Income Deduction (detailed)
This is a visualization and analysis tool. To contribute to the underlying PolicyEngine US calculations, see PolicyEngine/policyengine-us.
MIT License - See LICENSE file for details
Built to visualize and understand the QBI deduction implementation in PolicyEngine US.