# Architect Init

> Reverse-engineer architecture from an existing codebase to create ADRs documenting discovered decisions. Use when bootstrapping architecture documentation for brownfield projects.

- **Type:** Skill
- **Install:** `agentstack add skill-tikalk-adlc-team-skills-architect-init`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [tikalk](https://agentstack.voostack.com/s/tikalk)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [tikalk](https://github.com/tikalk)
- **Source:** https://github.com/tikalk/adlc-team-skills/tree/main/skills/architect/architect-init
- **Website:** https://github.com/tikalk/agentic-sdlc-12-factors

## Install

```sh
agentstack add skill-tikalk-adlc-team-skills-architect-init
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# architect-init

## What this skill does

Reverse-engineer architecture from an **existing codebase** (brownfield) to create Architecture Decision Records (ADRs) documenting discovered decisions, then **validate the findings** by running `/architect-clarify` manually.

You act as an **Architecture Archaeologist** uncovering implicit architectural decisions from code by scanning the codebase for technology choices and patterns, inferring architectural decisions from code structure, documenting discovered patterns as ADRs, and identifying gaps where decisions are unclear.

**Output**:

1. **ADRs** documenting inferred architectural decisions in `{REPO_ROOT}/.adlc/drafts/adr/ADR-{NNN}.md` (individual file format)
2. **Auto-generated index** at `{REPO_ROOT}/.adlc/drafts/adr/adr.md`
3. **Validate Findings**: Run `/architect-clarify` to validate discovered decisions

**Key Difference from `/architect-specify`**:

- `/architect-init` (this skill) = **Discovers** what's already implemented in code
- `/architect-specify` = **Explores** new possibilities for greenfield projects

This skill focuses on **current state analysis** - what IS, not what SHOULD BE.

## When to use

- **Brownfield projects**: Existing code without architecture docs
- **Legacy modernization**: Understanding current state before changes
- **Team onboarding**: Quickly documenting implicit decisions
- **Technical debt assessment**: Identifying undocumented patterns

### When NOT to use

- **Greenfield projects**: Use `/architect-specify` for new projects
- **Architecture exists**: If `AD.md` exists, use `/architect-clarify` to refine
- **Feature-level**: Feature architecture (if Spec Kit extension is also installed)

## Process

### User Input

```text
$ARGUMENTS
```

You **MUST** consider the user input before proceeding (if not empty).

**Examples of User Input**:

- `"Django monolith with PostgreSQL, React frontend, AWS deployment"`
- `"Node.js microservices with MongoDB and RabbitMQ"`
- `"Legacy Java application, focus on understanding data layer"`
- Empty input: Scan entire codebase and infer architecture

When users provide context, use it to focus the reverse-engineering effort.

### Flags

- `--adr-heuristic HEURISTIC`: ADR generation strategy
  - `surprising` (default): Skip obvious ecosystem defaults, document only surprising/risky decisions
  - `all`: Document all discovered decisions
  - `minimal`: Only high-risk decisions

- `--no-decompose`: Disable automatic sub-system detection from code structure (default: auto-detect if multiple modules detected)

### Role & Context

You are acting as an **Architecture Archaeologist** uncovering implicit architectural decisions from code. Your role involves:

- **Scanning** codebase for technology choices and patterns
- **Inferring** architectural decisions from code structure
- **Documenting** discovered patterns as ADRs
- **Identifying** gaps where decisions are unclear

#### Brownfield vs Greenfield

| Scenario | Command | Input | Output |
|----------|---------|-------|--------|
| **Brownfield** (existing code) | `/architect-init` | Codebase scan | Inferred ADRs |
| **Greenfield** (new project) | `/architect-specify` | PRD/requirements | Discussed ADRs |

#### Rozanski & Woods Alignment

When discovering ADRs from brownfield code, map findings to R&W viewpoints:

| Discovery Area | Primary Viewpoint | What to Look For |
|---------------|-------------------|------------------|
| Service structure | **Functional** | Component boundaries, responsibilities |
| Database schemas | Information | Data entities, relationships |
| Process/thread code | Concurrency | Runtime units, coordination |
| Directory structure | Development | Module organization, dependencies |
| Deployment configs | Deployment | Infrastructure, environments |
| Monitoring/alerting | Operational | Operations support |

**Functional-as-Cornerstone for Brownfield**:
Even in brownfield discovery, the **Functional structure is foundational**:

1. **Discover Functional first**: Identify components, services, modules
2. **Map other discoveries**: Relate data, deployment, operations to functional elements
3. **Document dependencies**: Note which ADRs affect the Functional view

**Priority order for ADR discovery**:
1. Architecture Style ADRs (monolith/microservices) → **Functional cornerstone**
2. Component/Service ADRs → Functional view
3. Database/Data ADRs → Information view
4. Infrastructure ADRs → Deployment view
5. Communication/Async ADRs → Concurrency view
6. Development/CI ADRs → Development view
7. Operations ADRs → Operational view

### Outline

1. **Sub-System Detection** (Phase 0): Identify sub-systems from code structure (auto-detect)
2. **Codebase Scan**: Analyze project structure and detect technologies (per sub-system if decomposed)
3. **Documentation Deduplication**: Scan existing docs (README, AGENTS.md, {TEAM_AI_DIRECTIVES}/AGENTS.md if configured, etc.) to avoid repeating
4. **Pattern Detection**: Identify architectural patterns in use
5. **ADR Generation**: Create ADRs for discovered decisions (marked "Discovered"), organized by sub-system
6. **Gap Analysis**: Identify areas where decisions are unclear
7. **Output**: Write ADRs to `{REPO_ROOT}/.adlc/drafts/adr/ADR-{NNN}.md` (NO AD.md creation)
   - After writing all ADRs, the setup script auto-generates `adr.md` index
8. **Validate Findings**: Run `/architect-clarify` to validate brownfield findings

### Execution Steps

#### Phase 0: Sub-System Detection (Brownfield)

**Objective**: Identify sub-systems from existing code structure automatically

**When**: This phase runs automatically when the codebase is detected as having multiple distinct modules/packages. Use `--no-decompose` to skip.

**Detection Source Reconciliation** (CRITICAL):
The setup script may report "No distinct sub-systems detected from directory structure" while your AI analysis identifies sub-systems through code patterns (import relationships, technology boundaries, domain logic). When this occurs:
- **TRUST your AI analysis** over the script output
- **ALWAYS execute Step 4** with your identified sub-systems
- **NEVER default to monolithic analysis** when you've identified sub-systems through ANY method
- The threshold logic applies to ALL detected sub-systems, regardless of detection source

##### Step 1: Directory Structure Analysis

Analyze the codebase for distinct sub-systems based on directory structure:

| Pattern | Likely Sub-System |
|---------|------------------|
| `src/auth/` | Authentication sub-system |
| `src/users/` | User management sub-system |
| `services/payment/` | Payment sub-system |
| `modules/inventory/` | Inventory sub-system |
| `apps/api/`, `apps/web/` | Monorepo with separate apps |
| `lib/core/`, `lib/shared/` | Shared libraries (not a sub-system) |

##### Step 2: Package/Module Detection

Detect sub-systems from package/module structures:

| Pattern | Detection Method | Sub-System Evidence |
|---------|------------------|-------------------|
| **Node.js workspaces** | package.json workspaces | Multiple packages = multiple sub-systems |
| **Python namespaces** | `__init__.py` hierarchy | Multiple top-level packages |
| **Go modules** | go.mod + directories | Multiple directories under cmd/ |
| **Maven/Gradle** | pom.xml modules | Multiple modules in multi-module project |
| **Docker services** | docker-compose services | Each service = sub-system |

##### Step 3: Database Schema Analysis

If database is accessible, detect sub-systems from schema:

| Pattern | Evidence |
|---------|----------|
| Table prefixes | `auth_`, `user_`, `payment_` tables = separate domains |
| PostgreSQL schemas | `auth.`, `payments.` schema separation |
| Separate databases | Multiple databases in docker-compose |

##### Step 4: Sub-System Proposal (Interactive) - MANDATORY if sub-systems identified

Present detected sub-systems to user for confirmation:

```markdown
## Detected Sub-Systems

I've identified the following sub-systems from your codebase:

| # | Sub-System | Detection Method | Evidence |
|---|------------|-----------------|----------|
| 1 | **auth** | Directory + Module | src/auth/, auth/ package |
| 2 | **users** | Directory | src/users/, services/user/ |
| 3 | **payments** | Directory + Docker | services/payment/, payment service in docker-compose |
| 4 | **inventory** | Directory | src/inventory/, modules/stock/ |

### Questions for Confirmation:

1. **Are these sub-systems correct?** [Y/n]
2. **Should any sub-systems be merged?** (e.g., auth + users → identity)
3. **Should any sub-systems be split?** (e.g., payments → billing + subscriptions)
4. **Any missing sub-systems?** (e.g., analytics, reporting)

**Reply** with:
- `Y` to confirm and proceed
- `n` to disable decomposition (generate monolithic ADRs)
- Specific changes (e.g., "merge 1+2", "split 3", "add Notifications")
```

**CRITICAL**: If you have identified ANY sub-systems through ANY method (script detection, AI analysis of code patterns, or user input), you **MUST** execute this step.
- Do **NOT** proceed to Phase 1 as "monolithic" if sub-systems exist
- Do **NOT** ignore sub-systems detected through AI analysis just because the script reported "none detected"
- You **MUST** get user confirmation when 4+ sub-systems are identified

Failure to follow this step invalidates the entire ADR discovery process.

##### Step 5: Decomposition Decision

Based on user response:

| Response | Action |
|----------|--------|
| `Y` / Enter | Proceed with detected sub-systems |
| `n` | Skip decomposition, generate monolithic ADRs |
| Modifications | Adjust sub-systems, then proceed |
| Empty/Default | Auto-proceed if ≤3 sub-systems, ask if >3 |

**Threshold Logic Enforcement** (MANDATORY - applies to ALL detected sub-systems, regardless of source):

| Sub-System Count | Required Action | Can Skip User Confirmation? |
|-----------------|-----------------|---------------------------|
| **0** | Proceed as monolithic (no decomposition) | Yes |
| **1-3** | Show summary, auto-approve allowed | Yes |
| **4-6** | **MUST show summary and ask user confirmation** | **NO** |
| **>6** | **MUST suggest grouping and MUST ask confirmation** | **NO** |

**Enforcement Rules**:
1. If you identified sub-systems through AI analysis but the script reported "none detected" → Apply threshold logic to YOUR identified sub-systems
2. If threshold is 4+ → You **MUST NOT** proceed without user confirmation
3. If you skip this logic → The ADR generation is invalid and may produce incorrect architecture
4. **Self-check before Phase 1**: Did I present Step 4? Did I apply threshold logic? If 4+ sub-systems, did I get confirmation?

##### Step 6: Output

After confirmation, output structured sub-system data:

```json
{
  "decomposition": "enabled",
  "subsystems": [
    {"id": "auth", "name": "Auth", "detection_method": "directory", "evidence": "src/auth/"},
    {"id": "users", "name": "Users", "detection_method": "directory", "evidence": "src/users/"},
    {"id": "payments", "name": "Payments", "detection_method": "docker", "evidence": "payment service in docker-compose"}
  ],
  "next_phase": "Codebase Analysis (per sub-system)"
}
```

**If decomposition disabled**:

```json
{
  "decomposition": "disabled",
  "reason": "user_requested",
  "next_phase": "Codebase Analysis (monolithic)"
}
```

---

#### Phase 1: Codebase Analysis

**Objective**: Discover what technologies and patterns are in use

**Note**: If sub-system decomposition is enabled (Phase 0), analyze each sub-system **separately** to provide focused insights.

1. **Run Setup Script**:
   - Execute `scripts/bash/setup-architect.sh` to initialize architecture files
   - Script scans codebase and outputs structured findings
   - Pass `--no-decompose` if decomposition was disabled
   - **If decomposed**: Script outputs sub-system breakdown for targeted analysis

2. **Technology Detection (Per Sub-System)**:

   | Indicator | Technology Category | Files to Check |
   |-----------|---------------------|----------------|
   | `package.json` | Node.js ecosystem | Dependencies, scripts |
   | `requirements.txt` / `pyproject.toml` | Python ecosystem | Dependencies |
   | `pom.xml` / `build.gradle` | JVM ecosystem | Dependencies |
   | `Cargo.toml` | Rust | Dependencies |
   | `go.mod` | Go | Dependencies |
   | `Dockerfile` | Containerization | Base images, stages |
   | `docker-compose.yml` | Container orchestration | Services, networks |
   | `*.tf` / `*.tfvars` | Terraform/IaC | Infrastructure |
   | `kubernetes/*.yaml` | Kubernetes | Deployment configs |
   | `.github/workflows/*` | GitHub Actions | CI/CD |

3. **Framework Detection**:

   | Pattern | Framework | Evidence |
   |---------|-----------|----------|
   | `from django` imports | Django | Python web |
   | `@SpringBoot` | Spring Boot | Java web |
   | `import express` | Express.js | Node.js web |
   | `import { Component }` | React/Angular/Vue | Frontend |
   | `from fastapi` | FastAPI | Python API |

4. **Database Detection**:

   | Evidence | Database Type |
   |----------|---------------|
   | PostgreSQL connection strings | PostgreSQL |
   | MongoDB/mongoose imports | MongoDB |
   | Redis client imports | Redis cache |
   | ORM migrations | Relational DB |
   | DynamoDB SDK usage | AWS DynamoDB |

#### Phase 2: Pattern Recognition

**Objective**: Identify architectural patterns from code structure

##### Architecture Style Detection

| Pattern | Evidence | ADR Topic |
|---------|----------|-----------|
| **Monolith** | Single deployable, shared database | ADR: System Architecture Style |
| **Microservices** | Multiple services, service discovery | ADR: System Architecture Style |
| **Modular Monolith** | Single deploy, module boundaries | ADR: System Architecture Style |
| **Event-Driven** | Message queue usage, event handlers | ADR: Communication Pattern |
| **Serverless** | Lambda functions, managed services | ADR: Deployment Model |

##### Code Organization Detection

| Pattern | Evidence |
|---------|----------|
| **Layered** | `controllers/`, `services/`, `repositories/` |
| **Feature-Based** | `features/`, `modules/` per domain |
| **Clean Architecture** | `domain/`, `application/`, `infrastructure/` |
| **Hexagonal** | `ports/`, `adapters/` |

##### API Style Detection

| Pattern | Evidence |
|---------|----------|
| **REST** | Route decorators, HTTP verbs, resource URLs |
| **GraphQL** | Schema files, resolvers, `gql` imports |
| **gRPC** | `.proto` files, gRPC client/server setup |
| **WebSocket** | Socket.io, WebSocket handlers |

#### Phase 3: Documentation Deduplication

**Objective**: Scan existing docs to avoid repeating documented information

**Scan for**:

- `AGENTS.md` - Project context, overview
- `{TEAM_AI_DIRECTIVES}/AGENTS.md` - Team-wide agent usage instructions (if configured)
- `README.md` - Tech stack, project description
- `CONTRIBUTING.md` - Development guidelines
- `AD.md` or `docs/architecture.md` - Existing architecture
- `LICENSE` - Legal context

**Deduplication Rules**:

| Finding | Action |
|---------|--------|
| Tech stack in README | Reference README in ADR, don't duplicate |
| Architecture exists | Auto-merge or offer update vs. create new |
| Guidelines in CONTRIBUTING | Reference in Development View |
| Context in AGENTS.md | Link from Context View |
| Team directives AGENTS.md | Reference for team-wide agent instructions |

**Process**:

1. Run `scripts/bash/setup-architect.sh` which calls `scan_existing_docs()`
2. Parse findings from JSON output
3. For each finding, determine: Skip ADR / Reference existing / Document new
4. Report: "X decisions covered by existing docs, Y new ADRs created"

#### Phase 4: ADR Generation

**Objective**: Document discovered decisions as ADRs

For each discovered architectural decision:

1. **Identify the Decision**:
   - What technology/pattern was chosen?
   - What alternatives were available when this was built?
   - What forces likely drove this dec

…

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [tikalk](https://github.com/tikalk)
- **Source:** [tikalk/adlc-team-skills](https://github.com/tikalk/adlc-team-skills)
- **License:** MIT
- **Homepage:** https://github.com/tikalk/agentic-sdlc-12-factors

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-tikalk-adlc-team-skills-architect-init
- Seller: https://agentstack.voostack.com/s/tikalk
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
