plugins/nette/skills/nette-architecture/SKILL.md
Invoke before designing presenters, modules, or application structure in web application. Use when asking about directory structure (app/ folder organization), presenter organization (modules, Admin/Front/Api, BasePresenter), domain-driven placement (Core/ vs Model/), component and factory placement, presenter lifecycle (action/render/template), CLI tasks, Accessory placement, project skeleton, or refactoring architecture. Also trigger when starting a new Nette project.
npx skillsauth add nette/claude-code nette-architectureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For new projects, see the project skeleton reference.
For the #[Requires] attribute (HTTP method/AJAX restrictions on actions), see the reference.
Understanding the request flow is essential for placing logic correctly:
startup() – runs first, use for access checks and early redirectsaction<Name>() – processes the request (data writes, redirects). Signals (handle<Name>()) also run in this phase.beforeRender() – runs before every render, use for shared template variablesrender<Name>() – prepares data for the template (read-only, no redirects)The key insight: actions and signals do things (write, redirect), renders prepare views (read). Mixing these responsibilities leads to redirect-after-render bugs and untestable presenters.
The application follows domain-driven organization. The reason: when code is grouped by domain (products, orders, customers), related files are close together and changes to one feature don't scatter across multiple directories.
App\)
Start minimal -> Grow organically -> Refactor when painful
Start with flat structure – create subdirectories only when you have 5+ related files or clear implementation variants. The threshold exists because below 5 files, subdirectories add navigation overhead without improving discoverability.
Don't architect for theoretical future complexity. Address actual complexity when it emerges with clear user needs driving structural decisions.
When refactoring to deeper structure: Move files one domain at a time. Create the new subdirectory, move related presenters/services into it, update namespaces, and verify. Don't reorganize everything at once.
For DI configuration details (service registration, autowiring, parameters), see the nette-configuration skill.
The distinction matters because Core/ code is reusable across projects while Model/ code is specific to your business. This affects testability, replaceability, and team ownership.
Use Core/ for:
Use Model/ for:
app/Model/
├── CatalogService.php ← Main domain services at root
├── CustomerService.php
├── OrderService.php
├── mails/ ← Email templates (specialized assets)
├── Payment/ ← Implementation variants
│ ├── CardOnlinePayment.php
│ ├── BankTransferPayment.php
│ └── CashPayment.php
└── exceptions.php ← Domain exceptions
Naming convention: mails/ is lowercase because it contains non-PHP assets (email templates). Payment/ is uppercase because it contains PHP classes following PSR-4.
Service placement rules:
Modules group presenters by user audience and access requirements. Admin, Front, and Api have different authentication, layouts, and URL patterns – that's why they're separate modules, not just for organization.
app/Presentation/
├── Accessory/ ← UI shared across entire application
│ ├── LatteExtension.php
│ └── TemplateFilters.php
├── Admin/
│ ├── BasePresenter.php ← Admin-specific functionality
│ ├── Auth/ ← Authentication
│ ├── Catalog/ ← Product management
│ │ ├── Brand/
│ │ ├── List/ ← Overview/utility presenters
│ │ └── Product/
│ └── Fulfill/ ← Order processing
└── Front/
├── Customer/
└── Listing/
Keep presenters flat until complexity demands structure:
# Start simple
Dashboard/DashboardPresenter.php
# Grow when needed
Admin/Catalog/Product/ProductPresenter.php
Admin/Catalog/Brand/BrandPresenter.php
Admin/Catalog/List/ListPresenter.php
Create nested structure when:
Each presenter directory contains the presenter class, its templates, and its local components:
Product/
├── ProductPresenter.php
├── default.latte
├── edit.latte
└── ProductFormFactory.php ← Form factory used only by this presenter
For template organization details (layouts, partials, @-prefixed files), see the latte-templates skill.
Create BasePresenter for each major module only when needed:
Admin\BasePresenter – authentication checks, admin-specific setupstartup() checks, beforeRender() template variablesAvoid deep inheritance – prefer composition over inheritance chains deeper than BasePresenter -> SpecificPresenter. Deep chains make it hard to understand which method runs when and create fragile coupling between unrelated presenters.
Where to place components, form factories, Latte extensions, and other shared code follows a proximity principle – keep code close to where it's used:
In the presenter directory – used by one presenter only:
Product/
├── ProductPresenter.php
├── ProductFormFactory.php ← Only ProductPresenter uses this
└── edit.latte
In Module/Accessory/ – shared across presenters within one module:
Admin/
├── Accessory/
│ ├── DataGridFactory.php ← Used by multiple Admin presenters
│ └── AdminFilters.php ← Admin-specific template helpers
├── Product/
└── Order/
In Presentation/Accessory/ – shared across modules:
Presentation/
├── Accessory/
│ ├── LatteExtension.php ← App-wide Latte filters/functions
│ ├── NavigationFactory.php ← Used in Admin and Front
│ └── TemplateFilters.php
Form factories that encapsulate form creation with validation and callbacks are preferred over building forms directly in presenters when the same form appears in multiple places. For form factory implementation patterns, see the nette-forms skill.
Create module when:
Avoid modules for:
app/Tasks/
├── Maintenance/ ← Cleanup, optimization
├── Integration/ ← External data sync
└── Scheduled/ ← Recurring operations
Task responsibility boundaries:
This separation means business logic is testable without CLI context and reusable from presenters or other entry points.
Don't create directories prematurely – a directory with one file is harder to navigate than a flat list. Wait until you have actual complexity (5+ related files), not anticipated complexity.
Don't separate by technical layer – Services/, Repositories/, Controllers/ separation forces you to jump between directories for every feature change. Domain organization keeps related code together.
Don't create deep hierarchies – prefer descriptive names over nested structure (OrderFulfillmentService vs Fulfill/Order/Service). Deep nesting increases cognitive load and makes imports longer without adding clarity.
Don't duplicate Base presenter logic – if two modules need the same functionality, extract it to a trait or a shared service. Copying leads to divergence and bugs when one copy gets updated but not the other.
For detailed information, use WebFetch on these URLs:
tools
CRITICAL: Read BEFORE writing or modifying any PHP file. A PostToolUse hook automatically runs nette/coding-standard (ECS) on every PHP file after each Edit or Write. The fixer removes unused `use` statements - so never add `use` statements in a separate edit before the code that references them. Always include `use` imports in the same edit as the referencing code, or add the code first then `use` statements. This skill should be used whenever creating new PHP files, editing existing PHP code, adding methods, refactoring, or fixing bugs in PHP - even for small one-line changes.
development
Install nette/coding-standard globally for PHP code style checking
tools
Invoke when fetching web pages from localhost, debugging PHP errors, or interpreting Tracy output (BlueScreen, Tracy Bar, dump). Read BEFORE running curl or Chrome to any local development PHP URL – with Tracy >= 2.12 and a detected agent, Tracy mirrors BlueScreen, Tracy Bar and dumps as markdown into the JS console for easy machine reading. For Chrome MCP, call list_console_messages() to read Tracy output. Essential when: 500 error, blank page, PHP exception, slow page, N+1 queries, or inspecting variables with dump().
tools
Provides Nette Utils helper classes. Use when working with Arrays, Strings, Image, Finder, FileSystem, Json, Validators, DateTime, Html element builder, Random, Callback, Type, or SmartObject from nette/utils. Do NOT use for Nette Schema, Nette Forms, Nette Database, Latte filters, or DI configuration.