# 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__ . '/lib/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 `lib/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 `database/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 (`lib/`)
**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 (`database/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](../database/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! ๐