# Post-ERG Development Guide Complete guide for developing the Post-ERG thesis management system. ## ๐Ÿš€ Quick Start ### 1. Setup (One Time) ```bash # Clone php-live-reload and setup directories just setup ``` ### 2. Start Development Server ```bash just serve ``` This starts **one unified server** at: - **Public site:** http://localhost:8000 - **Admin panel:** http://localhost:8000/admin/ โœจ **Live reload enabled** - your browser auto-refreshes when you save files! ### 3. Edit & Watch Edit any PHP file and watch your browser automatically refresh! ๐ŸŽ‰ --- ## ๐Ÿ“ Project Structure ``` posterg-website/ โ”œโ”€โ”€ index.php # Public homepage โ”œโ”€โ”€ memoire.php # Thesis detail page โ”œโ”€โ”€ search.php # Search page โ”œโ”€โ”€ *.php # Other public pages โ”‚ โ”œโ”€โ”€ admin/ # Admin panel โ”‚ โ”œโ”€โ”€ index.php # Admin dashboard โ”‚ โ”œโ”€โ”€ list.php # Thesis list โ”‚ โ”œโ”€โ”€ edit.php # Edit thesis โ”‚ โ””โ”€โ”€ formulaire.php # Add thesis โ”‚ โ”œโ”€โ”€ lib/ # Shared libraries โ”‚ โ”œโ”€โ”€ Database.php # Database class โ”‚ โ”œโ”€โ”€ RateLimit.php # Rate limiting โ”‚ โ””โ”€โ”€ config.php # Configuration โ”‚ โ”œโ”€โ”€ inc/ # Page templates โ”‚ โ”œโ”€โ”€ header.php # Site header โ”‚ โ””โ”€โ”€ footer.php # Site footer โ”‚ โ”œโ”€โ”€ assets/ # Static files โ”‚ โ”œโ”€โ”€ posterg.css # Main CSS โ”‚ โ””โ”€โ”€ fonts/ # Custom fonts โ”‚ โ”œโ”€โ”€ database/ # Database โ”‚ โ”œโ”€โ”€ schema.sql # Schema definition โ”‚ โ”œโ”€โ”€ test.db # Test database โ”‚ โ””โ”€โ”€ fixtures/ # Sample data โ”‚ โ”œโ”€โ”€ tests/ # Test suite โ”‚ โ”œโ”€โ”€ Unit/ # Unit tests โ”‚ โ”œโ”€โ”€ Integration/ # Integration tests โ”‚ โ””โ”€โ”€ Security/ # Security tests โ”‚ โ””โ”€โ”€ vendor/ # Third-party (gitignored) โ””โ”€โ”€ php-live-reload/ ``` --- ## ๐Ÿ› ๏ธ Development Workflow ### Starting Development ```bash # Start the development server just serve # In your browser: # - Public site: http://localhost:8000 # - Admin panel: http://localhost:8000/admin/ ``` ### Making Changes 1. **Edit PHP files** - Auto-refreshes browser 2. **Edit CSS** - Auto-refreshes browser 3. **Test changes** - See them instantly! ### Running Tests ```bash # Run all tests just test # Run specific test suites just test-unit # Unit tests just test-integration # Integration tests just test-security # Security tests ``` ### Database Operations ```bash # View database stats just stats # Open SQLite shell just query # Show specific thesis just show 42 # Reset database just reset-db # Create with sample data just fixtures ``` --- ## ๐Ÿ“ Common Tasks ### Create a New Page 1. Create `newpage.php` in root 2. Add `require_once __DIR__ . '/src/Database.php';` 3. Include header: `include 'inc/header.php';` 4. Add your content 5. Include footer: `include 'inc/footer.php';` Example: ```php

My New Page

Content here...

``` ### Add a Database Function 1. Edit `src/Database.php` 2. Add your method to the `Database` class 3. Write a test in `tests/Unit/DatabaseTest.php` 4. Run tests: `just test-unit` ### Update CSS 1. Edit `assets/posterg.css` 2. Browser auto-refreshes! 3. (Optional) Increment version in `inc/header.php`: `posterg.css?v=3` ### Add a Test 1. Choose location: - `tests/Unit/` - For testing classes/functions - `tests/Integration/` - For testing workflows - `tests/Security/` - For testing security 2. Create test file (e.g., `tests/Unit/MyTest.php`) 3. Follow the template in `tests/README.md` 4. Add to `tests/run-tests.php` 5. Run: `just test` --- ## ๐Ÿงช Testing ### Test Database Development uses `storage/test.db` (gitignored). **Create test database:** ```bash just init-db ``` **Populate with sample data:** ```bash just fixtures ``` **Deploy test database to server:** ```bash just deploy-test-db ``` **Reset everything:** ```bash just reset-db ``` ### Writing Tests See `tests/README.md` for complete testing guide. **Quick example:** ```php getMessage() . "\n"; return false; } ``` --- ## ๐Ÿš€ Deployment ### Deploy Everything ```bash just deploy ``` This deploys: - Public site (root PHP files) - Admin panel (`admin/`) - Shared libraries (`src/`) **Note:** `vendor/` is automatically excluded from deployment. ### Deploy Selectively ```bash # Deploy only the code just deploy # Deploy test database just deploy-test-db # Deploy nginx config just deploy-nginx # Deploy admin tools just deploy-admin-tools ``` --- ## ๐Ÿ”ง Justfile Commands ### Development | Command | Description | |---------|-------------| | `just setup` | Setup development environment (one-time) | | `just serve` | Start development server with live reload | | `just stop` | Stop development server | | `just logs` | View development logs | ### Testing | Command | Description | |---------|-------------| | `just test` | Run all tests | | `just test-unit` | Run unit tests | | `just test-integration` | Run integration tests | | `just test-security` | Run security tests | | `just syntax` | Check PHP syntax | ### Database | Command | Description | |---------|-------------| | `just init-db` | Create test database | | `just reset-db` | Reset test database | | `just query` | Open SQLite shell | | `just show ` | Show thesis by ID | | `just backup` | Backup database | | `just fixtures` | Create sample data | | `just deploy-test-db` | Deploy test database to server | ### Statistics | Command | Description | |---------|-------------| | `just stats` | Show database statistics | | `just recent` | Show recent theses | ### Deployment | Command | Description | |---------|-------------| | `just deploy` | Deploy complete site | | `just deploy-nginx` | Deploy nginx configuration | | `just deploy-admin-tools` | Deploy admin user management | ### Server | Command | Description | |---------|-------------| | `just server-logs` | View server logs | | `just server-status` | Check server status | ### Utilities | Command | Description | |---------|-------------| | `just clean` | Clean up dev files | | `just setup-dirs` | Create data directories | --- ## ๐Ÿ’ก Tips & Tricks ### Live Reload The `just serve` command uses php-live-reload to automatically refresh your browser when you save files. **What triggers refresh:** - Saving any `.php` file - Saving any file in the project **How it works:** - WebSocket connection monitors file changes - Browser receives reload signal - Page refreshes automatically **No browser extension needed!** ### Multiple Browser Windows Open multiple browser windows/tabs - they all get live reload! ``` http://localhost:8000/ # Public site http://localhost:8000/admin/ # Admin panel http://localhost:8000/memoire.php?id=13 # Specific thesis ``` All will auto-refresh when you save files! โœจ ### Using a Real Test Database The test database (`storage/test.db`) is gitignored. To share test data: ```bash # Create fixtures just fixtures # Commit the fixtures generator git add database/fixtures/ git commit -m "Update test fixtures" ``` Others can recreate with: `just fixtures` ### Debugging **Check error logs:** ```bash just logs ``` **Or directly:** ```bash tail -f error.log ``` **PHP errors in browser:** Edit your PHP file temporarily: ```php ini_set('display_errors', 1); error_reporting(E_ALL); ``` **Database issues:** ```bash # Check database exists ls -lh database/test.db # Open database shell just query # Check tables sqlite> .tables # Show schema sqlite> .schema theses ``` --- ## ๐Ÿ” Troubleshooting ### Server won't start **Port already in use:** ```bash just stop # Or manually: pkill -f "php -S 127.0.0.1:8000" ``` **php-live-reload missing:** ```bash just setup ``` ### Live reload not working **Check vendor directory:** ```bash ls -la vendor/php-live-reload/ ``` **Reinstall:** ```bash rm -rf vendor/php-live-reload just setup ``` ### Database errors **Database not found:** ```bash just init-db ``` **Permissions error:** ```bash chmod 644 database/test.db ``` **Schema errors:** ```bash just reset-db ``` ### Tests failing **Run individual test:** ```bash php tests/Unit/DatabaseTest.php ``` **Check database:** ```bash just stats ``` **Reset database:** ```bash just reset-db just fixtures just test ``` --- ## ๐Ÿ“š Further Reading - [Test Documentation](../tests/README.md) - [Database Specification](../storage/DATABASE_SPECIFICATION.md) - [Migration Guide](../MIGRATION_GUIDE.md) - [Deployment Guide](../nginx/DEPLOYMENT_COMPLETE.md) --- ## โœจ Quick Reference **Start developing:** ```bash just setup # One time just serve # Start server ``` **Test your changes:** ```bash just test # Run tests just stats # Check database ``` **Deploy to production:** ```bash just deploy ``` That's it! Happy coding! ๐Ÿš€