|
| 1 | +# GitHub Copilot Instructions for YASSG |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +YASSG (Yet Another Static Site Generator) is a PHP-based static site generator that combines the power of Twig templating with Symfony Encore for asset management and uses YAML databases for content organization. |
| 6 | + |
| 7 | +## Project Architecture |
| 8 | + |
| 9 | +### Core Components |
| 10 | + |
| 11 | +- **Static Site Generator**: Generates static HTML sites from Twig templates |
| 12 | +- **YAML Database**: Uses YAML files for content and data organization |
| 13 | +- **Asset Pipeline**: Symfony Encore for JavaScript/CSS bundling |
| 14 | +- **CLI Interface**: Console commands for site generation and initialization |
| 15 | +- **Multi-environment**: Supports different build environments (dev, prod) |
| 16 | + |
| 17 | +### Key Directories |
| 18 | + |
| 19 | +- `src/` - Core library code (PSR-4: `Sigwin\YASSG\`) |
| 20 | +- `bin/yassg` - Main CLI entry point |
| 21 | +- `config/` - Symfony configuration files |
| 22 | +- `resources/init/` - Project initialization templates |
| 23 | + - `basic/` - Minimal project setup |
| 24 | + - `demo/` - Full-featured demo site |
| 25 | + - `gitlab/` - GitLab CI/Pages configuration |
| 26 | +- `tests/` - Test suite including functional tests |
| 27 | +- `web/` - Web assets and frontend code |
| 28 | + |
| 29 | +## Development Environment |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +- PHP 8.3+ with ext-zlib |
| 34 | +- Composer for dependency management |
| 35 | +- Docker (for development tools) |
| 36 | +- Make for build automation |
| 37 | + |
| 38 | +### Setup |
| 39 | + |
| 40 | +```bash |
| 41 | +# Install dependencies |
| 42 | +composer install |
| 43 | + |
| 44 | +# Run tests |
| 45 | +make test |
| 46 | + |
| 47 | +# Run code analysis |
| 48 | +make analyze |
| 49 | + |
| 50 | +# Format code |
| 51 | +make cs |
| 52 | + |
| 53 | +# Prepare for distribution (runs all checks - local CI) |
| 54 | +make dist |
| 55 | +``` |
| 56 | + |
| 57 | +### Testing |
| 58 | + |
| 59 | +The project uses PHPUnit with mutation testing via Infection: |
| 60 | +- Unit tests in `tests/unit/` |
| 61 | +- Functional tests in `tests/functional/` |
| 62 | +- Integration tests validate full site generation |
| 63 | + |
| 64 | +### Code Quality |
| 65 | + |
| 66 | +- **PHP-CS-Fixer**: Code formatting (`.php-cs-fixer.dist.php`) |
| 67 | +- **PHPStan**: Static analysis (`phpstan.neon.dist`) |
| 68 | +- **Psalm**: Additional static analysis (`psalm.xml.dist`) |
| 69 | +- **Rector**: Automated refactoring (`rector.php`) |
| 70 | +- **Infection**: Mutation testing (`infection.json.dist`) |
| 71 | + |
| 72 | +## Coding Standards |
| 73 | + |
| 74 | +### PHP Code Style |
| 75 | + |
| 76 | +- PSR-12 coding standard |
| 77 | +- Strict types declaration required: `declare(strict_types=1);` |
| 78 | +- MIT license header in all PHP files |
| 79 | +- Prefer final classes and readonly properties where applicable |
| 80 | +- Use type hints for all parameters and return types |
| 81 | + |
| 82 | +### Naming Conventions |
| 83 | + |
| 84 | +- Classes: PascalCase |
| 85 | +- Methods/Properties: camelCase |
| 86 | +- Constants: UPPER_SNAKE_CASE |
| 87 | +- Namespaces follow PSR-4: `Sigwin\YASSG\` |
| 88 | + |
| 89 | +## Key APIs and Components |
| 90 | + |
| 91 | +### Core Classes |
| 92 | + |
| 93 | +- `Generator`: Main site generation logic |
| 94 | +- `Database`: Collection of content that can point to YAML files via Decoders |
| 95 | +- `Route`: Represents site routes and pages |
| 96 | +- `Storage`: File system abstraction |
| 97 | +- `Bridge\Symfony\*`: Symfony integration layer |
| 98 | + |
| 99 | +### CLI Commands |
| 100 | + |
| 101 | +- `yassg:init`: Initialize new projects |
| 102 | +- `yassg:generate`: Generate static sites |
| 103 | +- `yassg:validate`: Validate YAML database |
| 104 | + |
| 105 | +### Configuration |
| 106 | + |
| 107 | +- `config/services.yaml`: Service container configuration |
| 108 | +- `config/packages/`: Symfony bundle configurations |
| 109 | +- `config/routes/yassg.yaml`: Internal routing |
| 110 | + |
| 111 | +## Build System |
| 112 | + |
| 113 | +### Makefile Targets |
| 114 | + |
| 115 | +- `make test`: Run full test suite with mutation testing |
| 116 | +- `make analyze`: Run static analysis (PHPStan, Psalm) |
| 117 | +- `make dist`: Format code and prepare for distribution |
| 118 | +- `make help`: Show available targets |
| 119 | + |
| 120 | +### Docker Integration |
| 121 | + |
| 122 | +Uses `jakzal/phpqa` for consistent development environment across different platforms. |
| 123 | + |
| 124 | +## Site Generation Workflow |
| 125 | + |
| 126 | +1. **Initialization**: `yassg:init` creates project structure |
| 127 | +2. **Content**: YAML files define pages, routes, and data |
| 128 | +3. **Templates**: Twig templates in `templates/` directory |
| 129 | +4. **Assets**: Frontend assets processed by Encore |
| 130 | +5. **Generation**: `yassg:generate` produces static HTML |
| 131 | +6. **Output**: Generated site in `public/` directory |
| 132 | + |
| 133 | +## Testing Strategy |
| 134 | + |
| 135 | +### Functional Tests |
| 136 | + |
| 137 | +- `tests/functional/init/`: Tests project initialization |
| 138 | +- `tests/functional/site/`: Tests complete site generation |
| 139 | +- Both include fixtures and expected output validation |
| 140 | + |
| 141 | +### Running Specific Tests |
| 142 | + |
| 143 | +```bash |
| 144 | +# Run specific test suite |
| 145 | +vendor/bin/phpunit tests/unit/ |
| 146 | +vendor/bin/phpunit tests/functional/ |
| 147 | + |
| 148 | +# Run with coverage |
| 149 | +make test |
| 150 | +``` |
| 151 | + |
| 152 | +## Common Patterns |
| 153 | + |
| 154 | +### Database Operations |
| 155 | + |
| 156 | +```php |
| 157 | +$database = new MemoryDatabase(); |
| 158 | +$database->set('key', $value); |
| 159 | +$result = $database->get('key'); |
| 160 | +``` |
| 161 | + |
| 162 | +### Route Definition |
| 163 | + |
| 164 | +```php |
| 165 | +$route = new Route('path', $metadata, $content); |
| 166 | +``` |
| 167 | + |
| 168 | +### Storage Operations |
| 169 | + |
| 170 | +```php |
| 171 | +$storage = new Storage($filesystem); |
| 172 | +$storage->write($path, $content); |
| 173 | +``` |
| 174 | + |
| 175 | +## Troubleshooting |
| 176 | + |
| 177 | +### Common Issues |
| 178 | + |
| 179 | +1. **Composer install fails**: Ensure PHP 8.3+ and required extensions |
| 180 | +2. **Docker permission errors**: Check user permissions for Docker |
| 181 | +3. **Build failures**: Verify all dependencies are installed |
| 182 | +4. **Test timeouts**: Increase timeout values in phpunit.xml.dist |
| 183 | + |
| 184 | +### Debug Mode |
| 185 | + |
| 186 | +Set environment variables for debugging: |
| 187 | +- `APP_DEBUG=1`: Enable Symfony debug mode |
| 188 | +- `YASSG_SKIP_BUNDLES`: Skip specific Symfony bundles |
| 189 | + |
| 190 | +## Contributing Guidelines |
| 191 | + |
| 192 | +1. Follow existing code style and conventions |
| 193 | +2. Add tests for new functionality |
| 194 | +3. Run `make dist` before committing |
| 195 | +4. Ensure all CI checks pass |
| 196 | +5. Update documentation for public API changes |
| 197 | + |
| 198 | +## Dependencies |
| 199 | + |
| 200 | +### Core Dependencies |
| 201 | + |
| 202 | +- Symfony Framework Bundle (^6.4 || ^7.0) |
| 203 | +- Twig (via symfony/twig-bundle) |
| 204 | +- League CommonMark (Markdown processing) |
| 205 | +- Embed/Embed (Media embedding) |
| 206 | + |
| 207 | +### Development Dependencies |
| 208 | + |
| 209 | +- PHPUnit (^11.4 || ^12.0) |
| 210 | +- Sigwin Infra (build tools and configuration) |
| 211 | + |
| 212 | +## License |
| 213 | + |
| 214 | +MIT License - see LICENSE file for details. |
0 commit comments