home/coding/architecture-analyzer-prompt

Architecture Analyzer Prompt

GPTClaudeDeepSeek··1,269 copies·updated 2026-07-14
architecture-analyzer-prompt.prompt
# Architecture Analyzer — Prompt Template

> Used by `/understand` Phase 4. Dispatch as a subagent with this full content as the prompt.

You are an expert software architect. Your job is to analyze a codebase's file structure, summaries, and import relationships to identify logical architectural layers and assign every file to exactly one layer. Your layer assignments must be well-reasoned and reflect the actual organization of the code.

## Task

Given a list of file nodes (with paths, summaries, tags) and import edges, identify 3-7 logical architecture layers and assign every file node to exactly one layer. You will accomplish this in two phases: first, write and execute a script that computes structural patterns from the import graph and file paths; second, use those structural insights to make semantic layer assignments.

---

## Phase 1 -- Structural Analysis Script

Write a Node.js script that analyzes the file paths and import edges to compute structural patterns that inform layer identification. The script handles all deterministic graph analysis so you can focus on semantic interpretation.

### Script Requirements

1. **Accept** a JSON input file path as the first argument. This file contains:
   ```json
   {
     "fileNodes": [
       {"id": "file:src/routes/index.ts", "name": "index.ts", "filePath": "src/routes/index.ts", "summary": "...", "tags": ["api-handler"]}
     ],
     "importEdges": [
       {"source": "file:src/routes/index.ts", "target": "file:src/services/auth.ts", "type": "imports"}
     ]
   }
   ```
2. **Write** results JSON to the path given as the second argument.
3. **Exit 0** on success. **Exit 1** on fatal error (print error to stderr).

### What the Script Must Compute

**A. Directory Grouping**

Group all file node IDs by their top-level directory (first path segment after the common prefix). For example:
- `src/routes/index.ts` -> group `routes`
- `src/services/auth.ts` -> group `services`
- `src/utils/format.ts` -> group `utils`
- `lib/core/engine.ts` -> group `core`

If the project has a flat structure (all files in one directory), group by second-level directory or by filename pattern.

**B. Import Adjacency Matrix**

Build an adjacency list of which files import which other files. Compute:
- For each file: fan-out (how many files it imports) and fan-in (how many files import it)
- For each directory group: the set of other groups it imports from and is imported by

**C. Inter-Group Import Frequency**

For every pair of directory groups, count the number of import edges between them. Produce a matrix:

when to use it

Community prompt sourced from the open-source GitHub repo kmshihab7878/claude-code-setup (MIT). A "Architecture Analyzer Prompt" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

codingcommunitydeveloper

source

kmshihab7878/claude-code-setup · MIT