Skip to content
Skills Library
Programming · Planning

bundle-organization

/bundle-organization

Use when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).

Licence
MIT
Last repository change
25.07.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.07.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).

Original author description

Use when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).

How it works

  1. Modern Symfony apps are NOT bundles
  2. Service configuration
  3. Where does a class go?
  4. Parameters and environment
  5. When you DO write a bundle
  6. Gotchas
Original SKILL.md headings · 127 lines, 575 words
SKILL.md preview
---
name: bundle-organization
description: >
  Use when structuring a Symfony project's src/ directory, organizing code into modules,
  configuring services, or deciding where a class belongs. Covers the modular monolith
  layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).
---

# Project / Bundle Organization (Symfony 7)

## Modern Symfony apps are NOT bundles

Since Symfony 4, application code lives in `src/` under the `App\` namespace — **not** in a custom bundle. Create a bundle only for **reusable library code shared across projects**. For an application, organize `src/` by **feature/module**, not by technical type.

```
src/
├── Kernel.php
├── Sales/                       # bounded context / module
│   ├── Domain/
│   ├── Application/
│   ├── Infrastructure/
│   └── UI/                      # controllers, console commands, CLI
├── Billing/
│   └── ...
└── Shared/                      # cross-cutting kernel: base value objects, bus, ids
```

```
config/
├── packages/                    # per-bundle config (doctrine.yaml, security.yaml, ...)
│   └── prod/ · dev/ · test/     # env overrides
├── routes/                      # route imports
├── services.yaml                # app service wiring
└── bundles.php                  # registered bundles
```

### ❌ Don't organize purely by technical layer at the top level

```
src/
├── Controller/        # ❌ for a large app, everything-in-one-folder doesn't scale
├── Entity/
├── Repository/
└── Service/
```

This is fine for a tiny app, but in a domain of any size it scatters one feature across five folders. Group by **module first**, then layer inside.

## Service configuration

Rely on Symfony's defaults — **autowiring** + **autoconfiguration** + **resource autodiscovery**:

```yaml
# config/services.yaml
services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/'
        exclude:
            - '../src/Kernel.php'
            - '../src/**/Domain/**/{Entity,ValueObject}'   # plain objects, not services
```

- Bind an interface to an implementation only when there's a choice to make:

```yaml
    App\Sales\Domain\OrderRepository: '@App\Sales\Infrastructure\Doctrine\DoctrineOrderRepository'
```

- Inject scalar config with `#[Autowire]` at the point of use — don't sprinkle `%env()%` reads:

```php
public function __construct(
    #[Autowire('%env(int:ORDER_TTL_SECONDS)%')] private readonly int $orderTtl,
    #[Autowire(service: 'app.payment.http_client')] private readonly HttpClientInterface $client,
) {}
```

- Tag-based collection injection with `#[AutowireIterator]` / `#[TaggedIterator]` for strategy sets:

```php
public function __construct(
    #[AutowireIterator('app.payment_gateway')] private readonly iterable $gateways,
) {}
```

## Where does a class go?

| Class | Location |
|---|---|
| Doctrine entity / aggregate | `src/<Module>/Domain/` (or `Domain/Model/`) |
| Repository interface (port) | `src/<Module>/Domain/` |
| Repository Doctrine impl | `src/<Module>/Infrastructure/Doctrine/` |
| Application service / handler | `src/<Module>/Application/` |
| Controller | `src/<Module>/UI/Http/` (or top-level `Controller/` in small apps) |
| Console command | `src/<Module>/UI/Cli/` |
| DTO (request/response) | `src/<Module>/UI/Http/Dto/` |
| Value object | `src/<Module>/Domain/` |
| Custom Doctrine type | `src/Shared/Infrastructure/Doctrine/Type/` |

## Parameters and environment

- Secrets via Symfony's encrypted secrets vault (`secrets:set`) or `.env.local` — never commit real secrets.
- Type-cast env vars: `%env(int:…)%`, `%env(bool:…)%`, `%env(json:…)%`.
- Don't read `$_ENV` / `getenv()` in app code — inject the value.

## When you DO write a bundle

Only for shareable libraries. Modern bundles use `AbstractBundle`:

```php
final class AcmePaymentBundle extends AbstractBundle
{
    public function configure(DefinitionConfigurator $definition): void { /* config tree */ }

    public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import('../config/services.yaml');
    }
}
```

## Gotchas

- Agent generates a custom `AppBundle` for application code — modern apps use `src/` under `App\`, no app bundle.
- Agent dumps everything into top-level `Controller/`, `Entity/`, `Service/` for a large domain — organize by module first.
- Agent registers every service manually in `services.yaml` — rely on autowiring + autodiscovery; configure only the exceptions.
- Agent calls `getenv()` / reads `$_ENV` inside a service — inject the value via `#[Autowire('%env(...)%')]`.
- Agent puts entities/value objects into the service container — exclude `Domain` plain objects from autoregistration.
- Agent commits secrets in `.env` — use the secrets vault or `.env.local`.

Versions

The database has no other skills named bundle-organization.

Database snapshot: 13.11.2026 · package version ffb370a7f911 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90symfony-backend
    Use this skill when building Symfony backend applications — bundles, Doctrine ORM, Twig templates, Flex recipes, Messenger component. This skill enforces: service container autowiring, proper bundle structure, Doctrine mapping conventions, Flex-driven configuration. Do NOT use…
  • 90testing-symfony
    Stratégie de Tests Symfony 8.1 / PHP 8.5. Use when writing tests, reviewing test coverage, or setting up testing.
  • 100symfony
    Symfony 7+ framework guardrails, patterns, and best practices for AI-assisted development. Use when working with Symfony projects, or when the user mentions Symfony. Provides Doctrine ORM, Twig templates, bundles, services, and security guidelines.
  • 100implementing-symfony-applications
    Guides implementation and review of Symfony 5.4–8.x applications as a senior Symfony specialist: detects the project's Symfony version and uses only what exists in it, and justifies every framework feature it reaches for — services and DI, configuration, events, routing and…
  • 100modular-monolith-generator
    Structure a .NET app as a modular monolith — independent modules with enforced boundaries, public contracts, and in-process messaging between modules. Use this skill whenever the user wants a modular monolith, module boundaries, to split a monolith into modules,…
  • 100symfony
    Expert Symfony assistance covering PHP HTTP kernel, Twig, Doctrine ORM, services, and MakerBundle. Use when building enterprise PHP applications and web services.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.