# Insertr Development Guide ## Quick Start ### Full-Stack Development (Recommended) 1. **Install dependencies**: ```bash npm install # Root project dependencies cd lib && npm install # Library dependencies ``` 2. **Start hot reload development**: ```bash cd insertr-cli && air # Starts server with library hot reload ``` - Watches both Go CLI changes AND JavaScript library changes - Automatically rebuilds library → CLI → serves enhanced content - Visit http://localhost:3000 to see results ### Library-Only Development ```bash cd lib && npm run watch # Just develop the JavaScript library ``` ### Legacy Frontend Development ```bash npm run dev # Legacy live-server (demo-site only) ``` ## Development Workflow ### Hot Reload Development (Current Phase) **🔥 NEW**: Full-stack hot reload with Air integration! - **Library Source**: `lib/src/` - Independent JavaScript library - **CLI Integration**: `insertr-cli/` - Go CLI with embedded library - **Demo Site**: `demo-site/` - Test website for enhancement - **Automatic Rebuilds**: Changes to JS library trigger full rebuild cycle #### How Hot Reload Works: 1. Edit JavaScript in `lib/src/` 2. Air detects changes → Rebuilds library → Copies to CLI → Rebuilds CLI 3. Enhanced development server serves updated content 4. Manual browser refresh shows changes ### Legacy Frontend Development - **Demo Site**: `demo-site/` contains the prototype website - **Core Library**: `demo-site/insertr/insertr.js` - the old prototype library - **Mock API**: `demo-site/mock-api/content.json` - sample backend data structure ### Testing the Three User Types 1. **Customer View**: Open the site normally - clean, no edit interface 2. **Client View**: Click "Login as Client" then "Edit Mode: On" - see edit buttons 3. **Developer View**: Look at the HTML source to see simple integration ### Making Changes #### Modern Development (lib/ + insertr-cli/) - **Library Changes**: Edit `lib/src/**/*.js` → Air automatically rebuilds everything - **CLI Changes**: Edit Go files in `insertr-cli/` → Air rebuilds and restarts server - **Demo Content**: Edit `demo-site/*.html` → Air serves enhanced versions - **Hot Reload**: Changes trigger full rebuild cycle (library → CLI → enhanced content) #### Legacy Development (demo-site/) - **Live Reload**: The server automatically refreshes when you save changes - **JavaScript**: Edit `demo-site/insertr/insertr.js` for prototype functionality - **Content**: Edit HTML files to test different content structures ### Adding New Features 1. **Content Types**: Extend the `createEditForm()` method in insertr.js 2. **UI Components**: Add new CSS classes and corresponding JavaScript 3. **Authentication**: Modify the mock auth system in `toggleAuthentication()` ## Project Structure ``` insertr/ ├── DEVELOPMENT.md # This file ├── LIBRARY.md # Library architecture documentation ├── package.json # Root project configuration │ ├── lib/ # 🆕 Independent JavaScript Library │ ├── src/ │ │ ├── core/ │ │ │ ├── insertr.js # Core library functionality │ │ │ ├── editor.js # Visual editing interface │ │ │ └── api-client.js # Content API client │ │ └── index.js # Library entry point │ ├── dist/ │ │ ├── insertr.js # Built library (development) │ │ └── insertr.min.js # Built library (production) │ ├── package.json # Library dependencies │ └── rollup.config.js # Build configuration │ ├── insertr-cli/ # 🆕 Go CLI with Embedded Library │ ├── pkg/content/ │ │ ├── assets/ # Embedded library files (auto-copied) │ │ ├── library.go # Go embed declarations │ │ ├── enhancer.go # HTML enhancement orchestrator │ │ ├── injector.go # Content injection logic │ │ └── ... │ ├── scripts/ │ │ └── rebuild-library.sh # Air helper script │ ├── .air.toml # Hot reload configuration │ └── insertr # Built CLI executable │ ├── demo-site/ # Test website for enhancement │ ├── index.html # Demo homepage │ ├── about.html # Demo about page │ └── assets/style.css # Demo site styling │ └── scripts/ └── build.js # Integrated build script ``` ## Development Scripts ### Root Scripts - `npm run build` - Build library + CLI with embedded assets - `npm run dev` - Legacy live-server (demo-site only) ### Library Scripts (cd lib/) - `npm run build` - Build library to dist/ - `npm run watch` - Watch and rebuild library on changes ### CLI Scripts (cd insertr-cli/) - `air` - 🔥 Hot reload server (library + CLI + enhanced content) - `go build -o insertr` - Manual CLI build - `./insertr enhance