acc-psr-autoloading-knowledge

PSR-4 autoloading standard knowledge base for PHP 8.5 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.

16 stars

Best use case

acc-psr-autoloading-knowledge is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

PSR-4 autoloading standard knowledge base for PHP 8.5 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.

Teams using acc-psr-autoloading-knowledge should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/acc-psr-autoloading-knowledge/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/acc-psr-autoloading-knowledge/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/acc-psr-autoloading-knowledge/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How acc-psr-autoloading-knowledge Compares

Feature / Agentacc-psr-autoloading-knowledgeStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

PSR-4 autoloading standard knowledge base for PHP 8.5 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# PSR-4 Autoloading Knowledge

## Quick Reference

| Concept | Description |
|---------|-------------|
| **Namespace Prefix** | Maps to a base directory |
| **FQCN** | Fully Qualified Class Name |
| **Path Mapping** | Namespace → Directory → File |

## Core Concept

PSR-4 defines how to autoload classes from file paths based on their fully qualified class name.

```
Namespace Prefix    → Base Directory
Acme\Log\           → ./src/

FQCN                → File Path
Acme\Log\Writer\FileWriter → ./src/Writer/FileWriter.php
```

## Namespace to Path Mapping

### The Formula

```
File Path = Base Directory + (FQCN - Namespace Prefix) + .php

Where:
- Namespace separators (\) → Directory separators (/)
- Class name → File name with .php extension
```

### Examples

| FQCN | Namespace Prefix | Base Directory | File Path |
|------|------------------|----------------|-----------|
| `App\Entity\User` | `App\` | `src/` | `src/Entity/User.php` |
| `App\Domain\User\Entity\User` | `App\` | `src/` | `src/Domain/User/Entity/User.php` |
| `Vendor\Package\SubNs\ClassName` | `Vendor\Package\` | `lib/` | `lib/SubNs/ClassName.php` |

## Composer Configuration

### Basic Setup

```json
{
    "autoload": {
        "psr-4": {
            "App\\": "src/",
            "App\\Tests\\": "tests/"
        }
    }
}
```

### Multiple Directories

```json
{
    "autoload": {
        "psr-4": {
            "App\\": ["src/", "lib/"]
        }
    }
}
```

### DDD Project Structure

```json
{
    "autoload": {
        "psr-4": {
            "App\\": "src/",
            "App\\Domain\\": "src/Domain/",
            "App\\Application\\": "src/Application/",
            "App\\Infrastructure\\": "src/Infrastructure/",
            "App\\Presentation\\": "src/Presentation/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    }
}
```

### Symfony Bundle Structure

```json
{
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}
```

### Laravel Package Structure

```json
{
    "autoload": {
        "psr-4": {
            "Vendor\\Package\\": "src/"
        }
    }
}
```

## Directory Structure Examples

### Standard DDD Layout

```
project/
├── composer.json
├── src/
│   ├── Domain/
│   │   └── User/
│   │       ├── Entity/
│   │       │   └── User.php           # App\Domain\User\Entity\User
│   │       ├── ValueObject/
│   │       │   └── Email.php          # App\Domain\User\ValueObject\Email
│   │       ├── Repository/
│   │       │   └── UserRepositoryInterface.php
│   │       └── Event/
│   │           └── UserCreated.php
│   ├── Application/
│   │   └── User/
│   │       ├── Command/
│   │       │   └── CreateUserCommand.php
│   │       └── Handler/
│   │           └── CreateUserHandler.php
│   ├── Infrastructure/
│   │   └── Persistence/
│   │       └── Doctrine/
│   │           └── UserRepository.php
│   └── Presentation/
│       └── Api/
│           └── Controller/
│               └── UserController.php
└── tests/
    └── Unit/
        └── Domain/
            └── User/
                └── Entity/
                    └── UserTest.php   # App\Tests\Unit\Domain\User\Entity\UserTest
```

### Class Examples

```php
// src/Domain/User/Entity/User.php
<?php

declare(strict_types=1);

namespace App\Domain\User\Entity;

use App\Domain\User\ValueObject\Email;
use App\Domain\User\ValueObject\UserId;

final class User
{
    // ...
}
```

```php
// src/Domain/User/ValueObject/Email.php
<?php

declare(strict_types=1);

namespace App\Domain\User\ValueObject;

final readonly class Email
{
    // ...
}
```

## Detection Patterns

### Find Mismatched Namespaces

```bash
# Extract namespace from files and compare with path
for file in $(find src -name "*.php"); do
    namespace=$(grep -m1 "^namespace" "$file" | sed 's/namespace //;s/;//')
    expected_ns="App\\$(dirname ${file#src/} | tr '/' '\\')"
    if [ "$namespace" != "$expected_ns" ]; then
        echo "Mismatch: $file"
        echo "  Found:    $namespace"
        echo "  Expected: $expected_ns"
    fi
done
```

### Find Classes Without Namespace

```bash
# Files with class but no namespace
grep -rL "^namespace" --include="*.php" src/ | \
    xargs grep -l "^class\|^interface\|^trait\|^enum"
```

### Find Incorrect Class Names

```bash
# Class name doesn't match filename
for file in $(find src -name "*.php"); do
    filename=$(basename "$file" .php)
    if ! grep -q "^\(class\|interface\|trait\|enum\) $filename" "$file"; then
        echo "Mismatch: $file (expected class/interface/trait/enum $filename)"
    fi
done
```

### Validate Composer Autoload

```bash
# Dump autoload and check for errors
composer dump-autoload --strict 2>&1 | grep -i "warning\|error"

# Validate composer.json
composer validate --strict
```

## Common Mistakes

### 1. Namespace vs Path Mismatch

```php
// File: src/Domain/User/Entity/User.php
// BAD: Namespace doesn't match path
namespace App\User\Entity;  // Missing "Domain"

// GOOD: Namespace matches path
namespace App\Domain\User\Entity;
```

### 2. Class Name vs Filename Mismatch

```php
// File: src/Domain/UserEntity.php
// BAD: Class name doesn't match filename
class User { }

// GOOD: Class name matches filename
class UserEntity { }
```

### 3. Case Sensitivity Issues

```php
// File: src/Domain/User/Entity/user.php (lowercase)
// BAD: Will fail on case-sensitive filesystems (Linux)
namespace App\Domain\User\Entity;
class User { }

// GOOD: Filename should be User.php (PascalCase)
```

### 4. Missing Trailing Backslash

```json
// BAD: Missing trailing backslash
{
    "autoload": {
        "psr-4": {
            "App": "src/"
        }
    }
}

// GOOD: Include trailing backslash
{
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}
```

### 5. Incorrect Directory Separator

```json
// BAD: Using backslash in path (Windows-only)
{
    "autoload": {
        "psr-4": {
            "App\\": "src\\"
        }
    }
}

// GOOD: Use forward slash (cross-platform)
{
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}
```

## Verification Commands

```bash
# Regenerate autoload files
composer dump-autoload

# Optimize autoload (production)
composer dump-autoload --optimize

# Validate and show issues
composer dump-autoload --strict

# Test class loading
php -r "require 'vendor/autoload.php'; new App\Domain\User\Entity\User();"
```

## PHP-CS-Fixer Rules

```php
<?php

return (new PhpCsFixer\Config())
    ->setRules([
        // PSR-4 related rules
        'single_class_element_per_statement' => true,
        'single_import_per_statement' => true,
        'ordered_imports' => [
            'sort_algorithm' => 'alpha',
        ],
        'no_unused_imports' => true,
        'fully_qualified_strict_types' => true,
    ]);
```

## Integration with DDD Layers

### Layer Mapping

| Layer | Namespace | Directory |
|-------|-----------|-----------|
| Domain | `App\Domain\{Context}\` | `src/Domain/{Context}/` |
| Application | `App\Application\{Context}\` | `src/Application/{Context}/` |
| Infrastructure | `App\Infrastructure\` | `src/Infrastructure/` |
| Presentation | `App\Presentation\` | `src/Presentation/` |

### Component Mapping

| Component | Namespace Pattern | Directory Pattern |
|-----------|-------------------|-------------------|
| Entity | `App\Domain\{Context}\Entity\` | `src/Domain/{Context}/Entity/` |
| Value Object | `App\Domain\{Context}\ValueObject\` | `src/Domain/{Context}/ValueObject/` |
| Repository | `App\Domain\{Context}\Repository\` | `src/Domain/{Context}/Repository/` |
| Service | `App\Domain\{Context}\Service\` | `src/Domain/{Context}/Service/` |
| Command | `App\Application\{Context}\Command\` | `src/Application/{Context}/Command/` |
| Query | `App\Application\{Context}\Query\` | `src/Application/{Context}/Query/` |
| Handler | `App\Application\{Context}\Handler\` | `src/Application/{Context}/Handler/` |

## See Also

- `references/psr-4-standard.md` - Full PSR-4 specification
- `references/composer-integration.md` - Composer autoload configuration
- `references/directory-structure.md` - Project structure examples
- `references/antipatterns.md` - Common mistakes and fixes
- `assets/report-template.md` - Audit report template

Related Skills

acc-layer-arch-knowledge

16
from diegosouzapw/awesome-omni-skill

Layered Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for traditional N-tier/Layered Architecture audits.

acc-clean-arch-knowledge

16
from diegosouzapw/awesome-omni-skill

Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.

acc-claude-code-knowledge

16
from diegosouzapw/awesome-omni-skill

Knowledge base for Claude Code formats and patterns. Use when creating or improving commands, agents, skills, or hooks.

acc-adr-knowledge

16
from diegosouzapw/awesome-omni-skill

Action-Domain-Responder pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for ADR (web-specific MVC alternative) audits.

ant-design-knowledge-base

16
from diegosouzapw/awesome-omni-skill

Provides comprehensive answers about Ant Design components, documentation, and semantic descriptions using local knowledge base files. Use when asked about Ant Design, React UI components, design system, component semantics, or specific component usage.

acc-grasp-knowledge

16
from diegosouzapw/awesome-omni-skill

GRASP principles knowledge base for PHP 8.5 projects. Provides quick reference for 9 responsibility assignment patterns (Information Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Protected Variations). Use for architecture audits and design decisions.

acc-ddd-knowledge

16
from diegosouzapw/awesome-omni-skill

DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.

openai-knowledge

16
from diegosouzapw/awesome-omni-skill

Use when working with the OpenAI API (Responses API) or OpenAI platform features (tools, streaming, Realtime API, auth, models, rate limits, MCP) and you need authoritative, up-to-date documentation (schemas, examples, limits, edge cases). Prefer the OpenAI Developer Documentation MCP server tools when available; otherwise guide the user to enable `openaiDeveloperDocs`.

acc-diagram-knowledge

16
from diegosouzapw/awesome-omni-skill

Diagram knowledge base. Provides Mermaid syntax, C4 model, diagram types, and best practices for technical diagrams.

ac-knowledge-graph

16
from diegosouzapw/awesome-omni-skill

Manage knowledge graph for autonomous coding. Use when storing relationships, querying connected knowledge, building project understanding, or maintaining semantic memory.

adr-knowledge-base

16
from diegosouzapw/awesome-omni-skill

ADR知見の体系的参照・適用。主要ADR抜粋(ADR_010, 013, 016, 019, 020, 021)・ADR検索・参照方法・技術決定パターン集・ADR作成判断基準。Phase C以降の技術決定時に使用。

Knowledge

16
from diegosouzapw/awesome-omni-skill

Personal knowledge management using Graphiti knowledge graph with Neo4j/FalkorDB, supporting remote MCP access with connection profiles and TLS, OSINT/CTI ontology, and investigative search. USE WHEN 'store this', 'remember this', 'add to knowledge', 'search my knowledge', 'what do I know about', 'find in knowledge base', 'save to memory', 'graphiti', 'knowledge graph', 'entity extraction', 'relationship mapping', 'semantic search', 'episode', 'install knowledge', 'setup knowledge system', 'configure knowledge graph', 'remote knowledge server', 'connect to knowledge', 'knowledge profile', knowledge capture, retrieval, synthesis, memory decay, decay scoring, lifecycle state, importance classification, stability classification, health metrics, run maintenance, permanent memory, soft-delete, 'investigate entity', 'find connections', 'graph traversal', 'threat hunting', 'list ontology', 'custom entity types', 'CTI entities', 'OSINT entities', 'import STIX', 'STIX bundle', 'threat intel import'.