# Source Architecture From Code

> Synchronize architecture document with codebase changes. Usage /groundwork:source-architecture-from-code

- **Type:** Skill
- **Install:** `agentstack add skill-etr-groundwork-source-architecture-from-code`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [etr](https://agentstack.voostack.com/s/etr)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [etr](https://github.com/etr)
- **Source:** https://github.com/etr/groundwork/tree/main/skills/source-architecture-from-code

## Install

```sh
agentstack add skill-etr-groundwork-source-architecture-from-code
```

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

## About

# Sync Architecture Skill

Keeps `{{specs_dir}}/architecture.md` synchronized with actual implementation decisions.

## Pre-flight: Model Recommendation

**Your current effort level is `{{effort_level}}`.**

Skip this step silently if effort is `high`, `xhigh`, or `max` (the scale is `low`  "You're working from `` (inside **[cwd-project]**), but the selected Groundwork project is **[selected-project]** (`[selected-project-path]/`). What would you like to do?"
     > - "Switch to [cwd-project]"
     > - "Stay with [selected-project]"
     If the user switches, invoke `Skill(skill="groundwork:select-project")`.
   - If CWD doesn't match any project → proceed without warning (shared directory).
3. Proceed with the resolved project context. All `{{specs_dir}}/` paths will resolve to the correct location.

## File Locations

- **Target:** Architecture document (may be single file or directory)
  - Single file: `{{specs_dir}}/architecture.md`
  - Directory: `{{specs_dir}}/architecture/` (content split across files)
- **Context:** Current session history, codebase changes

**Detection:** Check for single file first (takes precedence), then directory.

## When to Trigger

This skill should activate when:
- User explicitly invokes `/groundwork:source-architecture-from-code`
- Session involved architectural decisions (new tech choices, pattern changes)
- Implementation deviated from documented architecture
- New components or integrations were added

## Workflow Overview

1. **Analyze Session** - Review what happened this session
2. **Detect Changes** - Identify architectural implications
3. **Propose Updates** - Draft specific changes to architecture doc
4. **Apply Changes** - Update document with user approval

## Step 1: Analyze Session

Review the current session for:

**Explicit Decisions:**
- "Let's use X instead of Y"
- "We should add a cache layer"
- "This needs to be async"

**Implicit Decisions (from implementation):**
- New dependencies added (package.json, requirements.txt)
- New services/components created
- New integrations configured
- Database schema changes

**Deviations:**
- Implementation differs from architecture doc
- Workarounds that changed the design
- Scope changes affecting architecture

## Step 2: Detect Change Categories

| Category | Signal | Single file section | Directory mode file |
|----------|--------|---------------------|---------------------|
| New component | New service/module created | §4 Component Details | `04-components/.md` (new file) |
| Tech change | Different library/framework used | §3 System Overview, relevant DR | `03-system-overview.md` or `11-decisions/DR-NNN.md` |
| Data change | Schema migration, new store | §5 Data Architecture | `05-data.md` |
| Integration | New external service | §6 Integration Architecture | `06-integration.md` |
| Security | Auth/encryption changes | §7 Security Architecture | `07-security.md` |
| Infra | New environment, deployment change | §8 Infrastructure | `08-infrastructure.md` |
| Decision | Explicit "let's do X" statement | §11 Decision Records | `11-decisions/DR-NNN.md` (new file) |

## Step 3: Propose Updates

For each detected change, propose a specific update:

```markdown
## Proposed Architecture Updates

### 1. New Decision Record

**Trigger:** You decided to use Redis for session caching instead of DynamoDB.

**Proposed addition to §11 Decision Records:**

### DR-00X: Session Cache Technology

**Status:** Accepted
**Date:** [today]
**Context:** [extracted from session]

**Options Considered:**
1. **DynamoDB** - Originally planned
   - Pros: AWS native, no new service
   - Cons: Overkill for simple key-value, higher latency
2. **Redis (ElastiCache)** - New choice
   - Pros: Sub-millisecond latency, built for sessions
   - Cons: Additional service to manage

**Decision:** Redis via ElastiCache

**Rationale:** [from session discussion]

---

### 2. Component Update

**Trigger:** Added new `NotificationService` module.

**Proposed addition to §4 Component Details:**

### 4.X Notification Service

**Responsibility:** Send transactional emails and push notifications

**Technology:** AWS SES + SNS

**Interfaces:**
- Exposes: Internal event handlers
- Consumes: EventBridge events

**Related Requirements:** PRD-XXX-REQ-NNN

---

Approve these updates? (yes/no/modify)
```

## Step 4: Apply Changes

On approval:

1. **Detect spec format** - Check if architecture is single file or directory
2. **Read current content:**
   - Single file: Read `{{specs_dir}}/architecture.md`
   - Directory: Aggregate all `.md` files from `{{specs_dir}}/architecture/`
3. **Route updates to appropriate files:**
   - **Single file mode:** Edit `{{specs_dir}}/architecture.md` directly
   - **Directory mode:** Route each update:
     - Decision records (DR-NNN) → Find or create in `{{specs_dir}}/architecture/11-decisions/.md`
     - Components → `{{specs_dir}}/architecture/04-components/.md`
     - Data architecture → `{{specs_dir}}/architecture/05-data.md`
     - Security → `{{specs_dir}}/architecture/07-security.md`
     - Updates to existing content → Find the file containing that content
4. Update "Last updated" timestamp
5. Add entry to change log if present

**Important:** Preserve existing content. Add to sections, don't replace unless explicitly correcting an error.

## Step 4a: Auto-Split Check (single file mode only)

**Skip this step if the architecture doc is already in directory mode.**

After applying changes to the single-file architecture doc, check whether it should be split:

1. Count lines: `wc -l {{specs_dir}}/architecture.md`
2. Count decision records: number of `### DR-\d+` headings in the file

If **lines >= 500** OR **decision records >= 10**:
- Invoke `Skill(skill="groundwork:split-architecture")` — this runs automatically with no user input needed.
- After the split completes, include in the session summary: "The architecture doc was automatically split into directory format at `{{specs_dir}}/architecture/`."

If neither threshold is crossed, continue silently.

## Change Detection Heuristics

**Strong signals (likely architectural):**
- New infrastructure resources (Terraform, CDK changes)
- New service directories created
- Database migrations
- New external API integrations
- Changes to authentication/authorization
- New environment variables for services

**Weak signals (maybe architectural):**
- New utility functions
- Refactoring within existing components
- Bug fixes
- Test additions
- Documentation updates

Focus on strong signals. Ask about weak signals only if they seem significant.

## Session Summary Format

At session end, provide summary:

```markdown
## Architecture Sync Summary

**Session Date:** [date]

### Changes Detected:
1. [Change 1] → Proposed DR-00X
2. [Change 2] → Updated §4.3
3. [Change 3] → No architecture impact (implementation detail)

### Architecture Document:
- [X] Updated with approved changes
- [ ] No changes needed
- [ ] Changes pending user review

### Open Items:
- [Any unresolved architectural questions from session]
```

## Source & license

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

- **Author:** [etr](https://github.com/etr)
- **Source:** [etr/groundwork](https://github.com/etr/groundwork)
- **License:** MIT

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:** no
- **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-etr-groundwork-source-architecture-from-code
- Seller: https://agentstack.voostack.com/s/etr
- 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%.
