Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .devcontainer/devcontainer.json

This file was deleted.

13 changes: 0 additions & 13 deletions .streamlit/config.toml

This file was deleted.

99 changes: 35 additions & 64 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@

## Code Structure

### Main Application (`app.py`)
### API (`src/aca_api/`)

**Key Functions:**
- **`api.py`**: the FastAPI app.
- `/api/calculate-stream`, which the calculator page calls, and `/api/calculate`, its fallback, run current law and the selected scenarios across an income axis for one household.
- `/api/explain` asks Claude for a narrative built from the computed numbers.
- `/api/health` reports that the API is up.
- **`models.py`**: the request and response models.

1. **`calculate_ptc()`** - Core calculation logic
- Builds household situation dictionary
- Applies reform parameters if requested
- Returns PTC and SLCSP values
- County format: "Travis County" → "TRAVIS_COUNTY_TX"
### Calculations (`aca_calc/calculations/`)

2. **`create_chart()`** - Visualization
- Generates income sweep curves
- Shows user's position on curves
- Compares baseline vs reform scenarios
- **`household.py`**: `build_household_situation()` builds the PolicyEngine situation, with an employment income axis for the charts.
- County format: "Travis County" → "TRAVIS_COUNTY_TX".
- **`reforms.py`**: each scenario as a PolicyEngine reform.

3. **`main()`** - Streamlit UI
- Handles user inputs
- Displays results
- Manages session state
### Frontend

- **`app/`**: the Next.js entry.
- **`src/App.jsx`**: the Overview, Explore Households and Calculator pages.
- **`src/components/`**: the charts, tables and the calculator.
- **`src/data/households/`**: precomputed results that the Overview and Explore pages read. `precompute_households.py` and `precompute_cliff_household.py` regenerate them.

### Data Files

- **`counties.json`**: 3,143 counties across all 50 states + DC
- **`process_counties.py`**: Updates county data from PolicyEngine
- **`counties.json`**: 3,143 counties across all 50 states + DC.
- **`process_counties.py`**: updates county data from PolicyEngine.

## Testing

```bash
# Quick verification test
python tests/test_reform_verification.py

# Comprehensive tests
python tests/test_app_comprehensive.py

# State-specific tests
python tests/test_texas.py
python tests/test_nj.py
# Every Python test
make test

# The API tests CI runs, against the Modal image's exact packages: the
# test files listed in .github/workflows/modal-api.yml
uv venv --python 3.11
uv pip install -r modal-requirements.txt
.venv/bin/python -m pytest tests/test_api_explain.py tests/test_smoke_test_api.py
```

## PolicyEngine Integration
Expand All @@ -60,11 +60,11 @@ situation = {

### Reform Parameters

IRA enhancements modify these PolicyEngine parameters:
```python
"gov.aca.ptc_phase_out_rate[0-6].amount" # Contribution percentages
"gov.aca.ptc_income_eligibility[2].amount" # Remove 400% FPL cap
```
The scenarios change these policyengine-us parameters:
- `gov.aca.required_contribution_percentage.threshold`, `.initial` and `.final`: the contribution schedule, three lists replaced together.
- `gov.aca.ptc_income_eligibility[2]`: the 400% FPL limit.

Other scenarios use policyengine-us's contributed reforms (`policyengine_us.reforms.aca`).

### County Format

Expand All @@ -80,39 +80,10 @@ PolicyEngine expects: `COUNTY_NAME_STATE`
- Verify state has marketplace data
- Try without county (uses state default)

### Reform Not Applied
- Ensure `use_reform=True` parameter
- Check Reform.from_dict() imports correctly
- Verify date format: "2026-01-01.2100-12-31"

### Calculations Don't Match Notebook
- Check PolicyEngine version
- Verify household structure matches
- Confirm income is split correctly for couples

## Adding Features

### New State-Specific Logic
1. Add to `calculate_ptc()` function
2. Test with multiple counties in that state
3. Compare against PolicyEngine web app

### UI Changes
1. Modify `main()` function
2. Update session state handling
3. Test with various household types

### New Visualizations
1. Add to or modify `create_chart()`
2. Use Plotly for consistency
3. Include hover tooltips

## Performance Tips

- Use `@st.cache_data` for expensive operations
- Load counties.json once at startup
- Minimize redundant PolicyEngine simulations
### A Scenario Fails
- A reform that names a parameter policyengine-us no longer has fails the request. The API reports the error, and the page shows it, rather than zero credits.
- Check the reform's parameter paths against the installed policyengine-us.

## Questions?

Check PolicyEngine docs: https://policyengine.github.io/policyengine-us/
Check PolicyEngine docs: https://policyengine.github.io/policyengine-us/
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install test format debug clean dev api frontend build stop
.PHONY: install test format clean dev api frontend build stop

install:
pip install -e ".[dev]"
Expand All @@ -11,9 +11,6 @@ format:
black . -l 79
@echo "Formatting complete"

debug:
uv run streamlit run app.py

clean:
rm -rf __pycache__ .pytest_cache .coverage htmlcov
find . -type d -name "*.egg-info" -exec rm -rf {} +
Expand Down
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ Visit **[https://policyengine.org/us/aca-calc](https://policyengine.org/us/aca-c
### Run Locally

```bash
# Install dependencies
pip install -r requirements.txt
# The frontend, at http://localhost:3000/us/aca-calc
bun install
bun run dev

# Run the app
streamlit run app.py
# The API, at http://localhost:5001, which the calculator page calls unless
# NEXT_PUBLIC_API_URL names another
uv run --with fastapi --with uvicorn uvicorn src.aca_api.api:app --port 5001
```

The app will open at http://localhost:8501
`make api` runs the API in Docker instead.

## Features

Expand All @@ -51,22 +53,30 @@ The app will open at http://localhost:8501

Built with:
- **[PolicyEngine US](https://policyengine.org)**: Open-source tax-benefit microsimulation
- **[Streamlit](https://streamlit.io)**: Interactive web interface
- **[Plotly](https://plotly.com)**: Data visualization
- **[Next.js](https://nextjs.org)** and **[Recharts](https://recharts.org)**: the frontend, on Vercel
- **[FastAPI](https://fastapi.tiangolo.com)**: the calculator's API, on Modal

County data sourced from PolicyEngine's ACA rating areas database.

## Project Structure

```
.
├── app.py # Main Streamlit application
├── counties.json # County data for all states
├── process_counties.py # County data processor
├── requirements.txt # Python dependencies
├── tests/ # Test files
├── notebooks/ # Analysis notebooks
└── archive/ # Historical files
├── app/ # Next.js entry (layout and page)
├── src/
│ ├── App.jsx # The Overview, Explore Households and Calculator pages
│ ├── components/ # Charts, tables and the calculator
│ ├── data/households/ # Precomputed results the Overview and Explore pages read
│ └── aca_api/ # The FastAPI backend (api.py, models.py)
├── aca_calc/calculations/ # The household builder and the scenarios' reforms
├── modal_app.py # The API's Modal deployment
├── modal-requirements.txt # The API image's exact package versions
├── precompute_*.py # Regenerate the precomputed household results
├── scripts/ # The post-deploy smoke test
├── counties.json # County lists for the calculator form
├── process_counties.py # Regenerates counties.json
├── tests/ # Python tests
└── notebooks/ # Analysis notebooks
```

## Development
Expand All @@ -81,8 +91,8 @@ uv run --locked --with fastapi pytest tests/test_api_explain.py -v
```

```bash
# Run tests
python tests/test_reform_verification.py
# Run the Python tests
make test

# Update county data
python process_counties.py
Expand Down
126 changes: 0 additions & 126 deletions aca_calc/calculations/charts.py

This file was deleted.

Loading
Loading