# Project cleanup summary

This document records the rigorous cleanup performed on the Boundary Commission / PLAGIS project.

## What was removed

### 1. Duplicate " copy" files and folders
- **38+ files** with ` copy` in the name (e.g. `aumentum_api copy.py`, `requirements copy.txt`, `Dilas copy/`, `browser_extension copy/`, `Details Document..._files copy/`) were deleted.
- These were redundant copies; the canonical versions remain (e.g. `aumentum_api.py`, `requirements.txt`, `Dilas/`, `browser_extension/`).

### 2. Log files (runtime artifacts)
- `api.log`, `server.log` (project root)
- `scripts/server.log`
- These are now in `.gitignore`; new logs go to `logs/` or `/var/log/plagis/` on the server.

### 3. Redundant scripts at project root
- Scripts that duplicate `scripts/` were removed from the **root** so there is a single canonical location under `scripts/`:
  - `build_complete_mapping.sh`, `check_remaining_issues.sh`, `check_pl11089_current_state.sh`, `comprehensive_audit_2015.sh`, `clear_cache_and_test.sh`, `analyze_chain_via_api.sh`, `search_pl11089.sh`
  - `test_all_endpoints.sh`, `test_all_pl11089_types.sh`, `test_complete_flow.sh`, `test_fix_pl_mismatch.sh`, `test_order_by_fix.sh`, `test_redirect_fix.sh`, `test_sorting_theory.sh`
  - `verify_pl12321.sh`, `verify_pl6204.sh`, `start_server.sh`, `run_investigation.sh`, `open_verification_pdfs.sh`, `mount_lrs.sh`, `identify_all_issues.sh`, `get_node_associations.sh`, `find_missing_nodes.sh`, `find_correct_files_by_timestamp.sh`, `debug_bp102_mapping.sh`, `setup_odbc_macos.sh`
  - `TEST_FINAL_FIX.sh`, `STOP_API.sh`, `QUICK_DEPLOY_LINUX.sh`, `FINAL_TEST_ALL_DOCUMENTS.sh`
- **Kept at root:** `START_API.sh`, `restart_api.sh`, `import_all_data.sh`, `populate_database.sh`, `setup_independent_system.sh` (convenience entry points or used by docs).

### 4. Backup / cruft in scripts
- `scripts/plagis-nextjs.service.bak` removed.

### 5. Unused root scripts (second pass)
- **Removed** one-off / investigation Python and JS scripts from project root (not referenced by app, README, or PROJECT_STRUCTURE):
  - `capture_web_access_api.py`, `check_3_candidates.py`, `check_directory.py`, `check_documents_exist.py`, `check_file_type.py`, `check_march9_transaction_numbers.py`
  - `convert_script_db.py`, `convert_script.py`, `dump_all_tables.py`
  - `expanded_pl11089_search.py`, `filesystem_based_discovery.py`, `final_comprehensive_46page_search.py`
  - `find_46_page_property_file.py`, `find_all_nodes.py`, `find_all_pages.py`, `find_any_46page_document.py`, `find_files_by_transaction.py`, `findrelated_images.py`
  - `fix_document_image_matching.py`, `get_all_pages_via_transaction.py`, `get_pl11089_transaction_number.py`
  - `map_correct_associations.py`, `match_by_timestamp_python.py`, `match_by_url_dates.py`, `match_pl11089_by_transaction_narrow.py`
  - `reverse_engineer_web_access.js`, `reverse_lookup.py`, `understand_schema.py`, `update_database_schema.py`, `run_database_investigation.py`
  - `verify_and_fix_associations.py`, `verify_pl11089_candidates.py`, `pdf_viewer.js`
- **Kept at root:** `aumentum_api.py`, `aumentum_browser_service.py`, `boundary_document_service.py` (stubs), `auth_service.py`, `create_admin_user.py`, `create_roles.py`, `assign_role_to_user.py`, `check_document.py`, `START_API.sh`, `restart_api.sh`, `restart_api_venv.sh`, `restart_all_services.sh`, `setup_independent_system.sh`, `import_all_data.sh`, `populate_database.sh`, `deploy_windows.bat`.

## Frontend: API base URL at runtime
- **dashboardHelpers.ts:** Removed the build-time `API_BASE_URL` constant. `apiRequest()` now calls `getApiBaseUrl()` on each request so production (e.g. `http://207.154.217.161`) uses `/api` instead of `http://localhost:8001`, fixing dictionary and other API calls in production.
- **DocumentModal.tsx:** Switched to `getApiBaseUrl()` for log messages.

## .gitignore updates

- `*.log`, `api.log`, `server.log`, `logs/`
- `.env.local`, `.env.*.local`
- `__pycache__/`, `.DS_Store`, `Thumbs.db`
- `plagis-nextjs/.next/`, `plagis-nextjs/out/`, `node_modules/`

## What to use going forward

| Need | Use |
|------|-----|
| Start API (local) | `./START_API.sh` or `scripts/START_API.sh` |
| Stop API | `scripts/STOP_API.sh` |
| Deploy / tests / verification | Run from `scripts/` (e.g. `./scripts/verify_deployment.sh`) |
| Logs | `logs/auth.log`, `logs/api.log` (or `/var/log/plagis/` on server) |
| Config | `.env` (from `.env.example`), never commit `.env` |

## What was not removed

- **docs/** – Many markdown files; kept for reference. Consider archiving or consolidating later.
- **database_dump/** – Kept; contains migration dumps and samples. Old backups under `database_dump/backup_*` can be pruned if disk space is needed.
- **attachments/** – PDFs/vsdx; kept as reference.
- **web_frontend/**, **loading_detail_doc/**, **Details Document..._files/** – Legacy UI assets; kept unless you confirm they are unused.

## Optional next steps

1. **docs/** – Merge or archive overlapping guides (e.g. multiple DEPLOYMENT_*.md, QUICKSTART_*.md) into a single deployment and quickstart doc.
2. **database_dump/backup_*** – Remove old backup folders if you rely only on the main full dump and samples.
