#!/usr/bin/env bash
set -e

APP_DIR="${1:-rss-app}"

echo "Installing RSS app into: $APP_DIR"

mkdir -p "$APP_DIR"/{backend/api/routes,backend/lib,backend/db,worker,public/{css,js/components},config,docs}

# ... (all the code I gave you earlier for schema, PHP, Python, frontend) ...

#####################################
# 8) Docs
#####################################
cat > "$APP_DIR/docs/README.md" << 'EOF'
# Curated RSS App

Modular RSS curation platform with:

- PHP backend (REST API)
- Python worker (RSS fetch/cache)
- Responsive HTML/JS frontend
- SQLite storage

Follows the golden rule: modular, layered, documented, single installer.
EOF

cat > "$APP_DIR/docs/ARCHITECTURE.md" << 'EOF'
# Architecture

## Layers

- Backend (PHP): REST API for feeds and articles.
- Worker (Python): Fetches RSS feeds and stores articles.
- Frontend (HTML/JS/CSS): Responsive UI for selecting feeds and topics.
- Database (SQLite): Feeds + articles.
- Config: Environment and future secrets.

## Data flow

1. Worker reads feeds from DB.
2. Worker fetches RSS and writes articles.
3. Frontend calls PHP API for feeds/articles.
4. User selects feeds/topics; UI filters articles.
EOF

cat > "$APP_DIR/docs/INSTALL.md" << 'EOF'
# Install

```bash
chmod +x install_rss_app.sh
./install_rss_app.sh rss-app
cd rss-app
python3 -m pip install feedparser
cd worker && python3 fetch_feeds.py
cd ..
php -S localhost:8000 -t public

