Skip to content

Commit ff3a411

Browse files
Copilotjbtronics
andcommitted
Add comprehensive Copilot instructions for Part-DB
Co-authored-by: jbtronics <[email protected]>
1 parent 6ca44b8 commit ff3a411

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

.github/copilot-instructions.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Copilot Instructions for Part-DB
2+
3+
Part-DB is an Open-Source inventory management system for electronic components built with Symfony 6 and modern web technologies.
4+
5+
## Technology Stack
6+
7+
- **Backend**: PHP 8.2+, Symfony 7.4, Doctrine ORM
8+
- **Frontend**: Bootstrap 5, Hotwire Stimulus/Turbo, TypeScript, Webpack Encore
9+
- **Database**: MySQL 5.7+/MariaDB 10.4+/PostgreSQL 10+/SQLite
10+
- **Testing**: PHPUnit with DAMA Doctrine Test Bundle
11+
- **Code Quality**: Easy Coding Standard (ECS), PHPStan (level 5)
12+
13+
## Project Structure
14+
15+
- `src/`: PHP application code organized by purpose (Controller, Entity, Service, Form, etc.)
16+
- `assets/`: Frontend TypeScript/JavaScript and CSS files
17+
- `templates/`: Twig templates for views
18+
- `tests/`: PHPUnit tests mirroring the `src/` structure
19+
- `config/`: Symfony configuration files
20+
- `public/`: Web-accessible files
21+
- `translations/`: Translation files for multi-language support
22+
23+
## Coding Standards
24+
25+
### PHP Code
26+
27+
- Follow [PSR-12](https://www.php-fig.org/psr/psr-12/) and [Symfony coding standards](https://symfony.com/doc/current/contributing/code/standards.html)
28+
- Use type hints for all parameters and return types
29+
- Always declare strict types: `declare(strict_types=1);` at the top of PHP files
30+
- Use PHPDoc blocks for complex logic or when type information is needed
31+
- Check code style with: `vendor/bin/ecs check src/` or `vendor/bin/ecs check tests/`
32+
- Fix violations with: `vendor/bin/ecs check src/ --fix`
33+
34+
### TypeScript/JavaScript
35+
36+
- Use TypeScript for new frontend code
37+
- Follow existing Stimulus controller patterns in `assets/controllers/`
38+
- Use Bootstrap 5 components and utilities
39+
- Leverage Hotwire Turbo for dynamic page updates
40+
41+
### Naming Conventions
42+
43+
- Entities: Use descriptive names that reflect database models (e.g., `Part`, `StorageLocation`)
44+
- Controllers: Suffix with `Controller` (e.g., `PartController`)
45+
- Services: Descriptive names reflecting their purpose (e.g., `PartService`, `LabelGenerator`)
46+
- Tests: Match the class being tested with `Test` suffix (e.g., `PartTest`, `PartControllerTest`)
47+
48+
## Development Workflow
49+
50+
### Dependencies
51+
52+
- Install PHP dependencies: `composer install`
53+
- Install JS dependencies: `yarn install`
54+
- Build frontend assets: `yarn build` (production) or `yarn watch` (development)
55+
56+
### Database
57+
58+
- Create database: `php bin/console doctrine:database:create --env=dev`
59+
- Run migrations: `php bin/console doctrine:migrations:migrate --env=dev`
60+
- Load fixtures: `php bin/console partdb:fixtures:load --env=dev`
61+
62+
Or use Makefile shortcuts:
63+
- `make dev-setup`: Complete development environment setup
64+
- `make dev-reset`: Reset development environment (cache clear + migrate)
65+
66+
### Testing
67+
68+
- Set up test environment: `make test-setup`
69+
- Run all tests: `php bin/phpunit`
70+
- Run specific test: `php bin/phpunit tests/Path/To/SpecificTest.php`
71+
- Run tests with coverage: `php bin/phpunit --coverage-html var/coverage`
72+
- Test environment uses SQLite by default for speed
73+
74+
### Static Analysis
75+
76+
- Run PHPStan: `composer phpstan` or `COMPOSER_MEMORY_LIMIT=-1 php -d memory_limit=1G vendor/bin/phpstan analyse src --level 5`
77+
- PHPStan configuration is in `phpstan.dist.neon`
78+
79+
### Running the Application
80+
81+
- Development server: `symfony serve` (requires Symfony CLI)
82+
- Or configure Apache/nginx to serve from `public/` directory
83+
- Set `APP_ENV=dev` in `.env.local` for development mode
84+
85+
## Best Practices
86+
87+
### Security
88+
89+
- Always sanitize user input
90+
- Use Symfony's security component for authentication/authorization
91+
- Check permissions using the permission system before allowing actions
92+
- Never expose sensitive data in logs or error messages
93+
- Use parameterized queries (Doctrine handles this automatically)
94+
95+
### Performance
96+
97+
- Use Doctrine query builder for complex queries instead of DQL when possible
98+
- Lazy load relationships to avoid N+1 queries
99+
- Cache results when appropriate using Symfony's cache component
100+
- Use pagination for large result sets (DataTables integration available)
101+
102+
### Database
103+
104+
- Always create migrations for schema changes: `php bin/console make:migration`
105+
- Review migration files before running them
106+
- Use Doctrine annotations or attributes for entity mapping
107+
- Follow existing entity patterns for relationships and lifecycle callbacks
108+
109+
### Frontend
110+
111+
- Use Stimulus controllers for interactive components
112+
- Leverage Turbo for dynamic page updates without full page reloads
113+
- Use Bootstrap 5 classes for styling
114+
- Keep JavaScript modular and organized in controllers
115+
- Use the translation system for user-facing strings
116+
117+
### Translations
118+
119+
- Use translation keys, not hardcoded strings: `{{ 'part.info.title'|trans }}`
120+
- Add new translation keys to `translations/` files
121+
- Primary language is English (en)
122+
- Translations are managed via Crowdin, but can be edited locally if needed
123+
124+
### Testing
125+
126+
- Write unit tests for services and helpers
127+
- Write functional tests for controllers
128+
- Use fixtures for test data
129+
- Tests should be isolated and not depend on execution order
130+
- Mock external dependencies when appropriate
131+
- Follow existing test patterns in the repository
132+
133+
## Common Patterns
134+
135+
### Creating an Entity
136+
137+
1. Create entity class in `src/Entity/` with Doctrine attributes
138+
2. Generate migration: `php bin/console make:migration`
139+
3. Review and run migration: `php bin/console doctrine:migrations:migrate`
140+
4. Create repository if needed in `src/Repository/`
141+
5. Add fixtures in `src/DataFixtures/` for testing
142+
143+
### Adding a Form
144+
145+
1. Create form type in `src/Form/`
146+
2. Extend `AbstractType` and implement `buildForm()` and `configureOptions()`
147+
3. Use in controller and render in Twig template
148+
4. Follow existing form patterns for consistency
149+
150+
### Creating a Controller Action
151+
152+
1. Add method to appropriate controller in `src/Controller/`
153+
2. Use route attributes for routing
154+
3. Check permissions using security voters
155+
4. Return Response or render Twig template
156+
5. Add corresponding template in `templates/`
157+
158+
### Adding a Service
159+
160+
1. Create service class in `src/Services/`
161+
2. Use dependency injection via constructor
162+
3. Tag service in `config/services.yaml` if needed
163+
4. Services are autowired by default
164+
165+
## Important Notes
166+
167+
- Part-DB uses fine-grained permissions - always check user permissions before actions
168+
- Multi-language support is critical - use translation keys everywhere
169+
- The application supports multiple database backends - write portable code
170+
- Responsive design is important - test on mobile/tablet viewports
171+
- Event system is used for logging changes - emit events when appropriate
172+
- API Platform is integrated for REST API endpoints
173+
174+
## Multi-tenancy Considerations
175+
176+
- Part-DB is designed as a single-tenant application with multiple users
177+
- User groups have different permission levels
178+
- Always scope queries to respect user permissions
179+
- Use the security context to get current user information
180+
181+
## Resources
182+
183+
- [Documentation](https://docs.part-db.de/)
184+
- [Contributing Guide](CONTRIBUTING.md)
185+
- [Symfony Documentation](https://symfony.com/doc/current/index.html)
186+
- [Doctrine Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/current/)
187+
- [Bootstrap 5 Documentation](https://getbootstrap.com/docs/5.1/)
188+
- [Hotwire Documentation](https://hotwired.dev/)

0 commit comments

Comments
 (0)