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

APP="${1:-myapp_v2}"
DOCS="$APP/docs"

echo "Installing FULL documentation suite into: $DOCS"
mkdir -p "$DOCS"

########################################
# README.md
########################################
cat > "$DOCS/README.md" << 'EOF'
# MyApp v2 — Full System Overview

MyApp v2 is a complete, production‑ready application template designed for repeatable deployment across multiple projects. It includes:

- PHP backend API (role‑based, token‑aware)
- Python worker system (queue + direct write)
- Frontend dashboard (status, items, user info)
- CLI suite (app, worker, admin, tests)
- Admin toolkit (DB inspector, logs, config validator, dashboard)
- SQLite database with schema + migrations
- Unified configuration via `.env`
- Full documentation set
- Manifest describing all system paths

This project follows the Golden Rule:
**Modular, layered, documented, repeatable, single‑installer deployment.**
EOF

########################################
# overview.md
########################################
cat > "$DOCS/overview.md" << 'EOF'
# Overview

MyApp v2 provides a unified, modular system for building dashboards, automation tools, diagnostics platforms, and lightweight applications.

## System Highlights
- Modular backend API
- Worker automation
- Frontend dashboard
- Admin toolkit
- CLI suite
- Full documentation
- SQLite portability
EOF

########################################
# ARCHITECTURE.md
########################################
cat > "$DOCS/ARCHITECTURE.md" << 'EOF'
# Architecture — Version 2

MyApp v2 is built on a strict modular architecture:

## Backend (PHP)
- REST API
- Role‑based access control
- Token authentication
- Shared libraries:
  - Env loader
  - DB connector
  - Logger
  - Auth
  - Response wrapper

## Worker (Python)
- Direct item writer
- Queue processor
- CLI worker runner

## Frontend (HTML/CSS/JS)
- Dashboard UI
- Status panel
- Items panel
- User panel
- Item creation

## CLI Tools
- app.sh
- worker.sh
- admin.sh
- test.sh

## Admin Toolkit
- DB inspector
- Log viewer
- Config validator
- Admin dashboard

## Database (SQLite)
Tables:
- users
- tokens
- items
- logs

## Config
- `.env`
- manifest.json
EOF

########################################
# INSTALL.md
########################################
cat > "$DOCS/INSTALL.md" << 'EOF'
# Installation Guide — Version 2

## 1. Install Core System
```bash
./install_core_v2.sh myapp_v2

