| name | acc-architecture-doc-template |
| description | Generates ARCHITECTURE.md files for PHP projects. Creates layer documentation, component descriptions, and architectural diagrams. |
Architecture Documentation Template Generator
Generate comprehensive architecture documentation for PHP projects.
Document Structure
# Architecture
## Overview
{high-level description}
## Directory Structure
{annotated project tree}
## System Context
{C4 context diagram}
## Architecture Layers
{layer descriptions}
## Components
{component descriptions}
## Data Flow
{sequence diagrams}
## Technology Stack
{technology decisions}
## Architecture Decisions
{link to ADRs}
## Deployment
{deployment diagram}
Section Templates
Directory Structure Section
## Directory Structure
project/
โโโ src/ # Source code
โ โโโ Domain/ # Domain Layer (DDD)
โ โ โโโ Entity/ # Domain entities
โ โ โโโ ValueObject/ # Value objects
โ โ โโโ Repository/ # Repository interfaces
โ โ โโโ Service/ # Domain services
โ โ โโโ Event/ # Domain events
โ โโโ Application/ # Application Layer
โ โ โโโ UseCase/ # Use cases / Commands / Queries
โ โ โโโ DTO/ # Data Transfer Objects
โ โ โโโ Service/ # Application services
โ โโโ Infrastructure/ # Infrastructure Layer
โ โ โโโ Persistence/ # Repository implementations
โ โ โโโ Http/ # HTTP clients
โ โ โโโ Messaging/ # Queue adapters
โ โ โโโ Cache/ # Cache adapters
โ โโโ Presentation/ # Presentation Layer
โ โโโ Api/ # REST API (Actions, Requests, Responses)
โ โโโ Web/ # Web controllers
โ โโโ Console/ # CLI commands
โโโ tests/ # Test suite
โ โโโ Unit/ # Unit tests (mirrors src/)
โ โโโ Integration/ # Integration tests
โ โโโ Functional/ # E2E / Functional tests
โโโ config/ # Configuration files
โโโ public/ # Web root
โโโ docker/ # Docker configuration
โโโ docs/ # Documentation
โโโ architecture/ # Architecture docs
โโโ adr/ # Architecture Decision Records
โโโ api/ # API documentation
### Generation Command
```bash
tree -L 3 -I 'vendor|node_modules|.git|var|cache' --dirsfirst
Annotation Rules
| Rule | Description |
|---|
| Layer name | Add DDD layer in comment |
| Purpose | Describe directory purpose |
| Depth | Max 3 levels in main docs |
| Details | Link to subdirectory READMEs |
### Overview Section
```markdown
## Overview
{Project Name} follows {Architecture Style} (e.g., Clean Architecture, DDD, Hexagonal).
### Key Principles
- **Separation of Concerns** โ Each layer has distinct responsibility
- **Dependency Rule** โ Dependencies point inward (Domain is center)
- **Testability** โ Business logic isolated from infrastructure
- **Framework Independence** โ Core logic doesn't depend on frameworks
### High-Level Structure
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ
โ (Actions, Responders) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Application Layer โ
โ (UseCases, Services) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Domain Layer โ
โ (Entities, Value Objects, Events) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Infrastructure Layer โ
โ (Repositories, Adapters, DB) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
System Context Section
## System Context
```mermaid
flowchart TB
subgraph boundary["{System Name}"]
S[("{System}\n{Brief Description}")]
end
U1[("๐ค {Actor 1}")]
U2[("๐ค {Actor 2}")]
ES1[("๐ฆ {External System 1}")]
ES2[("๐ฆ {External System 2}")]
U1 -->|"{interaction}"| S
U2 -->|"{interaction}"| S
S -->|"{integration}"| ES1
S -->|"{integration}"| ES2
Actors
| Actor | Description |
|---|
| {Actor 1} | {Description} |
| {Actor 2} | {Description} |
External Systems
| System | Purpose | Integration |
|---|
| {System 1} | {Purpose} | {Protocol/API} |
| {System 2} | {Purpose} | {Protocol/API} |
### Architecture Layers Section
```markdown
## Architecture Layers
### Presentation Layer
**Responsibility:** Handle HTTP requests and responses
**Components:**
- `Api/` โ REST API endpoints (Actions + Responders)
- `Web/` โ Web interface (Actions + Responders)
- `Console/` โ CLI commands
**Rules:**
- No business logic
- Validate input
- Call Application layer
- Format output
### Application Layer
**Responsibility:** Orchestrate business operations
**Components:**
- `UseCase/` โ Application-specific business rules
- `Service/` โ Cross-cutting application services
- `DTO/` โ Data transfer objects
**Rules:**
- Orchestrate Domain objects
- Handle transactions
- No infrastructure concerns
### Domain Layer
**Responsibility:** Core business logic
**Components:**
- `Entity/` โ Business objects with identity
- `ValueObject/` โ Immutable value concepts
- `Event/` โ Domain events
- `Repository/` โ Repository interfaces
- `Service/` โ Domain services
**Rules:**
- No external dependencies
- Pure business logic
- Self-validating objects
### Infrastructure Layer
**Responsibility:** Technical implementations
**Components:**
- `Persistence/` โ Repository implementations
- `Adapter/` โ External service adapters
- `Cache/` โ Caching implementations
- `Queue/` โ Queue implementations
**Rules:**
- Implement Domain interfaces
- Handle technical concerns
- No business logic
Components Section
## Components
```mermaid
flowchart TB
subgraph presentation[Presentation Layer]
AC[Action]
RS[Responder]
end
subgraph application[Application Layer]
UC[UseCase]
AS[AppService]
end
subgraph domain[Domain Layer]
EN[Entity]
VO[ValueObject]
DE[DomainEvent]
RI[Repository<br/>Interface]
end
subgraph infrastructure[Infrastructure Layer]
RP[Repository<br/>Impl]
AD[Adapter]
CA[Cache]
end
AC --> UC
UC --> EN
UC --> RI
RP -.-> RI
RP --> CA
Component Descriptions
| Component | Layer | Responsibility |
|---|
| Action | Presentation | HTTP request handling |
| Responder | Presentation | HTTP response building |
| UseCase | Application | Business operation orchestration |
| Entity | Domain | Business object with identity |
| ValueObject | Domain | Immutable value concept |
| Repository | Infrastructure | Data persistence |
### Data Flow Section
```markdown
## Data Flow
### {Operation Name} Flow
```mermaid
sequenceDiagram
participant C as Client
participant A as Action
participant U as UseCase
participant E as Entity
participant R as Repository
participant D as Database
C->>A: {Request}
A->>A: Validate & Map to DTO
A->>U: Execute(dto)
U->>R: find(id)
R->>D: SELECT
D-->>R: row
R-->>U: entity
U->>E: {operation}()
E-->>U: result
U->>R: save(entity)
R->>D: UPDATE
D-->>R: ok
U-->>A: Result
A->>A: Build Response
A-->>C: {Response}
### Technology Stack Section
```markdown
## Technology Stack
| Layer | Technology | Purpose |
|-------|------------|---------|
| Language | PHP 8.5 | Type safety, modern features |
| Framework | Symfony 7.x | HTTP, DI, Console |
| ORM | Doctrine 3.x | Database abstraction |
| Database | PostgreSQL 16 | Primary storage |
| Cache | Redis 7.x | Session, cache |
| Queue | RabbitMQ 3.x | Async processing |
| API | OpenAPI 3.1 | API specification |
### Technology Decisions
| Decision | Rationale |
|----------|-----------|
| PostgreSQL over MySQL | JSONB support, better type system |
| Symfony over Laravel | More explicit, better DI |
| Redis over Memcached | Data structures, persistence |
ADR Link Section
## Architecture Decisions
Key decisions are documented as ADRs:
| ADR | Status | Title |
|-----|--------|-------|
| [ADR-001](docs/adr/001-use-ddd.md) | Accepted | Use DDD Architecture |
| [ADR-002](docs/adr/002-cqrs.md) | Accepted | Implement CQRS |
| [ADR-003](docs/adr/003-event-sourcing.md) | Proposed | Consider Event Sourcing |
Complete Example
# Architecture
## Overview
Order Management System follows Domain-Driven Design with Clean Architecture principles.
### Key Principles
- **Domain-Centric** โ Business logic in Domain layer
- **Dependency Inversion** โ Abstractions over implementations
- **Bounded Contexts** โ Order, Inventory, Shipping
## Directory Structure
order-management/
โโโ src/
โ โโโ Order/ # Order Bounded Context
โ โ โโโ Domain/ # Domain Layer
โ โ โโโ Application/ # Application Layer
โ โ โโโ Infrastructure/ # Infrastructure Layer
โ โ โโโ Presentation/ # Presentation Layer
โ โโโ Inventory/ # Inventory Bounded Context
โ โโโ Shipping/ # Shipping Bounded Context
โโโ tests/
โโโ config/
โโโ docs/
## System Context
```mermaid
flowchart TB
subgraph boundary["Order Management System"]
S[("๐ฆ OMS\nManages orders lifecycle")]
end
Customer[("๐ค Customer")]
Admin[("๐ค Admin")]
Payment[("๐ณ Payment Gateway")]
Shipping[("๐ Shipping Provider")]
Customer -->|"Place orders"| S
Admin -->|"Manage orders"| S
S -->|"Process payments"| Payment
S -->|"Ship orders"| Shipping
Architecture Layers
[... layer descriptions ...]
Technology Stack
| Layer | Technology | Purpose |
|---|
| Language | PHP 8.5 | Type safety |
| Framework | Symfony 7.2 | HTTP, DI |
| Database | PostgreSQL 16 | Storage |
| Cache | Redis 7.4 | Performance |
| Queue | RabbitMQ 3.13 | Async |
Architecture Decisions
## Generation Instructions
When generating ARCHITECTURE.md:
1. **Analyze** project structure for layer organization
2. **Identify** architectural style (DDD, Clean, Hexagonal)
3. **Map** components to layers
4. **Create** context diagram with actors/systems
5. **Generate** component diagram
6. **List** technology stack from `composer.json`
7. **Link** existing ADRs if present