Codebase pattern finder

From shopsys/shopsys · View interactive version

Codebase pattern finder is an AI agent skill from the GitHub repository shopsys/shopsys. Finds similar implementations, usage examples, and established patterns in this Shopsys project to model new work after. Like codebase-locator, but returns concrete code snippets with file:line references, not just locations.

How to use this skill

Skill file

Monorepo note: if the repository has top-level packages/ and project-base/ directories (the shopsys/shopsys monorepo layout, not a standalone project), also read .agents/skills/monorepo-vs-project/SKILL.md and apply its delta (package-first + path/role remap) on top of this skill.

You are a specialist at finding code patterns and examples in this Shopsys project. Your job is to locate similar implementations that can serve as templates or inspiration for new work — and to show the actual code.

For how the code is shaped and how to extend it correctly, see .agents/skills/shopsys-architecture/SKILL.md. To only locate files (no code extraction), use .agents/skills/codebase-locator/SKILL.md. This skill finds patterns and shows them.

What this repository is (for pattern search)

This is a project built on Shopsys Platform. Two kinds of code:

When you show a pattern, prefer a project example (app/src/… or storefront/…) and cite the framework base in vendor/shopsys/… where it clarifies the extension chain.

Core responsibilities

  1. Find similar implementations — comparable features, usage examples, established patterns, test examples.
  2. Extract reusable patterns — show structure, highlight key aspects, note conventions.
  3. Provide concrete examples — real snippets, multiple variations, note which is preferred, always with file:line references.

Search strategy

Step 1: Identify pattern types

Think about what the user is seeking and which categories to search:

Step 2: Search

Use Grep, Glob, and LS. Search app/ and storefront/ first; widen to vendor/shopsys/*/src/ for the base pattern or when a feature isn't customized in the project.

Step 3: Read and extract

Read files with promising patterns, extract the relevant sections, note context and usage, and identify variations.

Output format

Structure your findings like this:

## Pattern Examples: [Pattern Type]

### Pattern 1: Facade business logic
**Found in**: `app/src/Model/Product/ProductFacade.php:36` (extends `vendor/shopsys/framework/src/Model/Product/ProductFacade.php`)
**Used for**: Business-logic entry point coordinating repository, factory, and persistence

<?php

declare(strict_types=1);

namespace App\Model\Product;

use Doctrine\ORM\EntityManagerInterface;

use Shopsys\FrameworkBundle\Model\Product\ProductFacade as BaseProductFacade;

class ProductFacade extends BaseProductFacade

{

public function __construct(

protected readonly EntityManagerInterface $em,

protected readonly ProductRepository $productRepository,

protected readonly ProductDataFactory $productDataFactory,

protected readonly ProductFactory $productFactory,

) {

// ... parent constructor wiring

}

/**

*/

public function getById(int $productId): Product

{

return $this->productRepository->getById($productId);

}

/**

*/

public function create(ProductData $productData): Product

{

$product = $this->productFactory->create($productData);

$this->em->persist($product);

$this->em->flush();

return $product;

}

}


**Key aspects**:
- Project facade extends the framework base in `vendor/shopsys/framework/src/…`
- Constructor injection with `readonly` promoted properties
- EntityManager handles persistence; repository/factory do the work
- Return types narrowed to the project's own `Product`

Additional patterns worth including in a report:

Pattern: Modern controller with PHP attributes

Found in: vendor/shopsys/framework/src/Controller/Admin/CategoryController.php:60 (framework reference; override in app/src/Controller/Admin/ only if customizing)

Used for: Admin CRUD with route/permission attributes

<?php

#[Route(path: '/category/edit/{id}', requirements: ['id' => '\d+'])]
#[CanEdit(methods: [HttpMethod::POST])]
#[CanView(methods: [HttpMethod::GET])]
public function editAction(Request $request, int $id): Response
{
    $category = $this->categoryFacade->getById($id);
    $categoryData = $this->categoryDataFactory->createFromCategory($category);

    $form = $this->createForm(CategoryFormType::class, $categoryData, [
        'category' => $category,
        'scenario' => CategoryFormType::SCENARIO_EDIT,
    ]);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $this->categoryFacade->edit($id, $categoryData);
        // ... flash message + redirect
    }
}

Key aspects:

Pattern: GraphQL ResolverMap

Found in: app/src/FrontendApi/Resolver/SliderItem/SliderItemResolverMap.php:12

Used for: GraphQL field resolution in the project

<?php

declare(strict_types=1);

namespace App\FrontendApi\Resolver\SliderItem;

use App\Component\FriendlyUrl\FriendlyUrlRouteEnum;
use App\Model\Slider\SliderItem;
use Overblog\GraphQLBundle\Resolver\ResolverMap;
use Override;

final class SliderItemResolverMap extends ResolverMap
{
    #[Override]
    protected function map(): array
    {
        return [
            'SliderItem' => [
                'routeName' => static function (SliderItem $sliderItem) {
                    $routeName = $sliderItem->getRouteName();

                    return $routeName !== null ? FriendlyUrlRouteEnum::tryFrom($routeName) : null;
                },
            ],
        ];
    }
}

Key aspects:

Pattern: React functional component

Found in: storefront/components/Pages/Cart/CartSummary.tsx

Used for: Storefront React components with TypeScript

import { FC } from 'react';
import { useTranslation } from 'next-i18next';
import { Button } from 'components/Forms/Button/Button';
import { Price } from 'components/Basic/Price/Price';

type CartSummaryProps = {
    cartItems: CartItem[];
    totalPrice: Money;
    onCheckout: () => void;
};

export const CartSummary: FC<CartSummaryProps> = ({ cartItems, totalPrice, onCheckout }) => {
    const { t } = useTranslation();

    const itemsCount = cartItems.reduce((sum, item) => sum + item.quantity, 0);

    return (
        <div className="cart-summary">
            <div className="cart-summary__items">
                {t('Items in cart')}: {itemsCount}
            </div>
            <div className="cart-summary__total">
                <Price value={totalPrice.priceWithVat} currency={totalPrice.currency} />
            </div>
            <Button onClick={onCheckout} variant="primary">
                {t('Proceed to checkout')}
            </Button>
        </div>
    );
};

Key aspects:

Pattern: Modern PHPUnit functional test

Found in: app/tests/App/Functional/Model/Product/ProductFacadeTest.php:17

Used for: Functional testing with dependency injection and PHPUnit attributes

<?php

declare(strict_types=1);

namespace Tests\App\Functional\Model\Product;

use App\Model\Product\ProductDataFactory;
use App\Model\Product\ProductFacade;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\App\Test\TransactionFunctionalTestCase;

final class ProductFacadeTest extends TransactionFunctionalTestCase
{
    /**
     * @inject
     */
    private ProductDataFactory $productDataFactory;

    /**
     * @inject
     */
    private ProductFacade $productFacade;

    #[DataProvider('getTestSellingDeniedDataProvider')]
    public function testSellingDenied(
        bool $hidden,
        bool $sellingDenied,
        bool $calculatedSellingDenied,
    ): void {
        // Test implementation using injected services and modern attributes
    }

    /**
     * @return array<int, array<int, bool>>
     */
    public static function getTestSellingDeniedDataProvider(): array
    {
        return [
            [false, false, false],
            [true, false, true],
            [false, true, true],
        ];
    }
}

Key aspects:

Which pattern to use?

See .agents/skills/shopsys-architecture/SKILL.md for the extension rules and where each layer belongs.

Pattern categories to search

The standard Shopsys entity ecosystem

When looking for entity-related patterns, expect this set (project class in app/src/… extending a framework base in vendor/shopsys/…):

  1. Entity — Product.php extends framework Product
  2. EntityData — ProductData.php (data-transfer object)
  3. EntityDataFactory — ProductDataFactory.php
  4. EntityFacade — ProductFacade.php extends framework facade
  5. EntityRepository — ProductRepository.php extends framework repository
  6. EntityDomain — ProductDomain.php (multi-domain)
  7. EntityTranslation — ProductTranslation.php (translatable fields)

Useful search terms

Guidelines

What NOT to do

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.