Concurrency Architecture Lens
Cognitive Mode: Physiological
Primary Question: "How does parallelism work?"
Focus: Parallel Execution, Thread Pools, Synchronization, Barriers
When to Use
- Need to understand concurrent execution patterns
- Documenting thread pools and worker management
- Analyzing synchronization and thread safety
- User invokes
/autoskillit:arch-lens-concurrency or /autoskillit:make-arch-diag concurrency
Critical Constraints
NEVER:
- Modify any source code files
- Conflate with general process flow (that's a different lens)
- Ignore thread safety implications
ALWAYS:
- Focus on PARALLEL execution specifically
- Show synchronization barriers and coordination
- Identify thread safety guarantees
- Document the concurrency MODEL used
- BEFORE creating any diagram, LOAD the
/autoskillit:mermaid skill using the Skill tool - this is MANDATORY
Analysis Workflow
Step 1: Launch Parallel Exploration Subagents
Spawn Explore subagents to investigate:
Concurrency Model
- Find the primary concurrency approach
- Is it threading, asyncio, multiprocessing, coroutines?
- Look for: ThreadPoolExecutor, asyncio, ProcessPoolExecutor, async/await, goroutines, threads
Worker Pools
- Find thread/process pool configurations
- Identify max_workers settings
- Look for: Executor, Pool, workers, max_*, thread pool, worker pool
Parallel Operations
- Find what work is parallelized
- Identify parallel patterns (map, submit, gather)
- Look for: executor.submit, asyncio.gather, pool.map, parallel processing
Synchronization Points
- Find barriers and coordination
- Identify how parallel work is collected
- Look for: as_completed, wait, gather, Lock, Semaphore, barriers, sync points
State Access
- Find shared state access
- Identify thread safety mechanisms
- Look for: Lock, RLock, Queue, thread-local, immutable, atomic, mutex
Sequential Boundaries
- Find what MUST run sequentially
- Identify the main thread/process responsibilities
- Look for: main(), single-threaded, atomic updates
Step 2: Map Concurrency Boundaries
Document:
- Main Thread: What runs sequentially
- Worker Pool: What runs in parallel
- Barriers: Where parallel work converges
- Atomic Operations: What requires exclusive access
CRITICAL - Analyze Read/Write Direction:
For EVERY concurrent component and shared resource:
- Reads from shared state: What data do workers READ?
- Writes to shared state: What data do workers WRITE?
- Return values: Do workers return data (read by main thread)?
- Side effects: Do workers write to storage directly?
Identify:
- Read-only access (safe for parallelism)
- Write access (needs synchronization)
- Worker isolation (no shared state during execution)
Step 3: Identify Thread Safety
For each shared resource:
- How is it protected?
- Who can read/write?
- Are there race conditions?
Step 4: Create the Diagram
Use flowchart with:
Direction: TB for spawn-barrier-collect pattern
Subgraphs:
- Main Thread (sequential operations)
- Thread/Process Pool (parallel workers)
- Subprocess/External (if spawned processes)
- Isolation (thread safety guarantees)
Node Styling:
terminal class: Start/end points
phase class: Sequential nodes
newComponent class: Parallel workers (green)
detector class: Spawn and barrier points
handler class: Processing within workers
output class: Atomic state updates
stateNode class: Thread safety mechanisms
Special Elements:
- Show fork/join points clearly
- Use edge labels for conditions
- Group parallel workers visually
Step 5: Write Output
Write the diagram to: temp/arch-lens-concurrency/arch_diag_concurrency_{YYYY-MM-DD_HHMMSS}.md (relative to the current working directory)
After writing the diagram file, emit a structured output line:
diagram_path = {absolute_path_to_diagram_file}
Output Template
# Concurrency Diagram: {System Name}
**Lens:** Concurrency (Physiological)
**Question:** How does parallelism work?
**Date:** {YYYY-MM-DD}
**Scope:** {What was analyzed}
## Concurrency Model
| Aspect | Value | Notes |
|--------|-------|-------|
| Primary Model | {threading/asyncio/multiprocessing} | |
| Worker Pool Type | {ThreadPoolExecutor/etc} | |
| Max Workers | {count} | |
| Parallel Operations | {what is parallelized} | |
## Concurrency Diagram
```mermaid
%%{init: {'flowchart': {'nodeSpacing': 40, 'rankSpacing': 50, 'curve': 'basis'}}}%%
flowchart TB
%% CLASS DEFINITIONS %%
classDef terminal fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;
classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;
classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;
classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;
classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;
subgraph MainThread ["MAIN THREAD (Sequential)"]
direction TB
START([START])
INIT["Initialize<br/>━━━━━━━━━━<br/>Setup state"]
DECISION{"Multiple<br/>items?"}
SEQ["Sequential Path<br/>━━━━━━━━━━<br/>Single thread"]
SPAWN["Spawn Workers<br/>━━━━━━━━━━<br/>Fork point"]
BARRIER["Barrier<br/>━━━━━━━━━━<br/>Wait for all"]
ATOMIC["Atomic Update<br/>━━━━━━━━━━<br/>Main thread only"]
COMPLETE([COMPLETE])
end
subgraph ThreadPool ["THREAD POOL (Parallel)"]
direction TB
W1["Worker 1<br/>━━━━━━━━━━<br/>Task execution"]
W2["Worker 2<br/>━━━━━━━━━━<br/>Task execution"]
WN["Worker N<br/>━━━━━━━━━━<br/>Task execution"]
end
subgraph Isolation ["THREAD SAFETY"]
direction TB
ISO1["Isolated state"]
ISO2["No shared writes"]
ISO3["Return data only"]
end
%% MAIN FLOW %%
START --> INIT
INIT --> DECISION
DECISION -->|"1 item"| SEQ
DECISION -->|"N items"| SPAWN
SEQ --> COMPLETE
%% PARALLEL FLOW %%
SPAWN --> W1
SPAWN --> W2
SPAWN --> WN
W1 --> BARRIER
W2 --> BARRIER
WN --> BARRIER
BARRIER --> ATOMIC
ATOMIC --> COMPLETE
%% ISOLATION %%
W1 -.-> ISO1
W2 -.-> ISO2
WN -.-> ISO3
%% CLASS ASSIGNMENTS %%
class START,COMPLETE terminal;
class INIT,SEQ phase;
class DECISION stateNode;
class SPAWN,BARRIER detector;
class W1,W2,WN newComponent;
class ATOMIC output;
class ISO1,ISO2,ISO3 stateNode;
Color Legend:
| Color |
Category |
Description |
| Dark Blue |
Terminal |
Start and end points |
| Purple |
Sequential |
Single-threaded nodes |
| Green |
Workers |
Parallel workers |
| Red |
Synchronization |
Spawn and barrier points |
| Dark Teal |
Atomic |
Main-thread-only state updates |
| Teal |
Isolation |
Thread safety guarantees |
Concurrency Boundaries
| Component |
Model |
Synchronization |
| {component} |
{single-threaded/parallel} |
{mechanism} |
Thread Safety Guarantees
- Isolation: {how workers are isolated}
- State Access: {who can modify shared state}
- Barrier: {how results are collected}
---
## Pre-Diagram Checklist
Before creating the diagram, verify:
- [ ] LOADED `/autoskillit:mermaid` skill using the Skill tool
- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)
- [ ] Diagram will include a color legend table
---
## Related Skills
- `/autoskillit:make-arch-diag` - Parent skill for lens selection
- `/autoskillit:mermaid` - MUST BE LOADED before creating diagram
- `/autoskillit:arch-lens-process-flow` - For general workflow view
- `/autoskillit:arch-lens-error-resilience` - For parallel failure handling
1---2name: arch-lens-concurrency3description: Create Concurrency architecture diagram showing parallel execution patterns, thread pools, synchronization, and barriers. Physiological lens answering "How does parallelism work?"4---5
6# Concurrency Architecture Lens
7
8**Cognitive Mode:** Physiological
9**Primary Question:** "How does parallelism work?"
10**Focus:** Parallel Execution, Thread Pools, Synchronization, Barriers
11
12## When to Use
13
14- Need to understand concurrent execution patterns
15- Documenting thread pools and worker management
16- Analyzing synchronization and thread safety
17- User invokes `/autoskillit:arch-lens-concurrency` or `/autoskillit:make-arch-diag concurrency`
18
19## Critical Constraints
20
21**NEVER:**
22- Modify any source code files
23- Conflate with general process flow (that's a different lens)
24- Ignore thread safety implications
25
26**ALWAYS:**
27- Focus on PARALLEL execution specifically
28- Show synchronization barriers and coordination
29- Identify thread safety guarantees
30- Document the concurrency MODEL used
31- BEFORE creating any diagram, LOAD the `/autoskillit:mermaid` skill using the Skill tool - this is MANDATORY
32
33---
34
35## Analysis Workflow
36
37### Step 1: Launch Parallel Exploration Subagents
38
39Spawn Explore subagents to investigate:
40
41**Concurrency Model**
42- Find the primary concurrency approach
43- Is it threading, asyncio, multiprocessing, coroutines?
44- Look for: ThreadPoolExecutor, asyncio, ProcessPoolExecutor, async/await, goroutines, threads
45
46**Worker Pools**
47- Find thread/process pool configurations
48- Identify max_workers settings
49- Look for: Executor, Pool, workers, max_*, thread pool, worker pool
50
51**Parallel Operations**
52- Find what work is parallelized
53- Identify parallel patterns (map, submit, gather)
54- Look for: executor.submit, asyncio.gather, pool.map, parallel processing
55
56**Synchronization Points**
57- Find barriers and coordination
58- Identify how parallel work is collected
59- Look for: as_completed, wait, gather, Lock, Semaphore, barriers, sync points
60
61**State Access**
62- Find shared state access
63- Identify thread safety mechanisms
64- Look for: Lock, RLock, Queue, thread-local, immutable, atomic, mutex
65
66**Sequential Boundaries**
67- Find what MUST run sequentially
68- Identify the main thread/process responsibilities
69- Look for: main(), single-threaded, atomic updates
70
71### Step 2: Map Concurrency Boundaries
72
73Document:
74- **Main Thread**: What runs sequentially
75- **Worker Pool**: What runs in parallel
76- **Barriers**: Where parallel work converges
77- **Atomic Operations**: What requires exclusive access
78
79**CRITICAL - Analyze Read/Write Direction:**
80For EVERY concurrent component and shared resource:
81- **Reads from shared state**: What data do workers READ?
82- **Writes to shared state**: What data do workers WRITE?
83- **Return values**: Do workers return data (read by main thread)?
84- **Side effects**: Do workers write to storage directly?
85
86Identify:
87- Read-only access (safe for parallelism)
88- Write access (needs synchronization)
89- Worker isolation (no shared state during execution)
90
91### Step 3: Identify Thread Safety
92
93For each shared resource:
94- How is it protected?
95- Who can read/write?
96- Are there race conditions?
97
98### Step 4: Create the Diagram
99
100Use flowchart with:
101
102**Direction:** `TB` for spawn-barrier-collect pattern
103
104**Subgraphs:**
105- Main Thread (sequential operations)
106- Thread/Process Pool (parallel workers)
107- Subprocess/External (if spawned processes)
108- Isolation (thread safety guarantees)
109
110**Node Styling:**
111- `terminal` class: Start/end points
112- `phase` class: Sequential nodes
113- `newComponent` class: Parallel workers (green)
114- `detector` class: Spawn and barrier points
115- `handler` class: Processing within workers
116- `output` class: Atomic state updates
117- `stateNode` class: Thread safety mechanisms
118
119**Special Elements:**
120- Show fork/join points clearly
121- Use edge labels for conditions
122- Group parallel workers visually
123
124### Step 5: Write Output
125
126Write the diagram to: `temp/arch-lens-concurrency/arch_diag_concurrency_{YYYY-MM-DD_HHMMSS}.md` (relative to the current working directory)
127
128After writing the diagram file, emit a structured output line:
129
130```
131diagram_path = {absolute_path_to_diagram_file}
132```
133
134---
135
136## Output Template
137
138```markdown
139# Concurrency Diagram: {System Name}
140
141**Lens:** Concurrency (Physiological)
142**Question:** How does parallelism work?
143**Date:** {YYYY-MM-DD}
144**Scope:** {What was analyzed}
145
146## Concurrency Model
147
148| Aspect | Value | Notes |
149|--------|-------|-------|
150| Primary Model | {threading/asyncio/multiprocessing} | |
151| Worker Pool Type | {ThreadPoolExecutor/etc} | |
152| Max Workers | {count} | |
153| Parallel Operations | {what is parallelized} | |
154
155## Concurrency Diagram
156
157```mermaid
158%%{init: {'flowchart': {'nodeSpacing': 40, 'rankSpacing': 50, 'curve': 'basis'}}}%%
159flowchart TB
160 %% CLASS DEFINITIONS %%
161 classDef terminal fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;
162 classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;
163 classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;
164 classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;
165 classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;
166 classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
167 classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;
168
169 subgraph MainThread ["MAIN THREAD (Sequential)"]
170 direction TB
171 START([START])
172 INIT["Initialize<br/>━━━━━━━━━━<br/>Setup state"]
173 DECISION{"Multiple<br/>items?"}
174 SEQ["Sequential Path<br/>━━━━━━━━━━<br/>Single thread"]
175 SPAWN["Spawn Workers<br/>━━━━━━━━━━<br/>Fork point"]
176 BARRIER["Barrier<br/>━━━━━━━━━━<br/>Wait for all"]
177 ATOMIC["Atomic Update<br/>━━━━━━━━━━<br/>Main thread only"]
178 COMPLETE([COMPLETE])
179 end
180
181 subgraph ThreadPool ["THREAD POOL (Parallel)"]
182 direction TB
183 W1["Worker 1<br/>━━━━━━━━━━<br/>Task execution"]
184 W2["Worker 2<br/>━━━━━━━━━━<br/>Task execution"]
185 WN["Worker N<br/>━━━━━━━━━━<br/>Task execution"]
186 end
187
188 subgraph Isolation ["THREAD SAFETY"]
189 direction TB
190 ISO1["Isolated state"]
191 ISO2["No shared writes"]
192 ISO3["Return data only"]
193 end
194
195 %% MAIN FLOW %%
196 START --> INIT
197 INIT --> DECISION
198 DECISION -->|"1 item"| SEQ
199 DECISION -->|"N items"| SPAWN
200 SEQ --> COMPLETE
201
202 %% PARALLEL FLOW %%
203 SPAWN --> W1
204 SPAWN --> W2
205 SPAWN --> WN
206
207 W1 --> BARRIER
208 W2 --> BARRIER
209 WN --> BARRIER
210
211 BARRIER --> ATOMIC
212 ATOMIC --> COMPLETE
213
214 %% ISOLATION %%
215 W1 -.-> ISO1
216 W2 -.-> ISO2
217 WN -.-> ISO3
218
219 %% CLASS ASSIGNMENTS %%
220 class START,COMPLETE terminal;
221 class INIT,SEQ phase;
222 class DECISION stateNode;
223 class SPAWN,BARRIER detector;
224 class W1,W2,WN newComponent;
225 class ATOMIC output;
226 class ISO1,ISO2,ISO3 stateNode;
227```
228
229**Color Legend:**
230| Color | Category | Description |
231|-------|----------|-------------|
232| Dark Blue | Terminal | Start and end points |
233| Purple | Sequential | Single-threaded nodes |
234| Green | Workers | Parallel workers |
235| Red | Synchronization | Spawn and barrier points |
236| Dark Teal | Atomic | Main-thread-only state updates |
237| Teal | Isolation | Thread safety guarantees |
238
239## Concurrency Boundaries
240
241| Component | Model | Synchronization |
242|-----------|-------|-----------------|
243| {component} | {single-threaded/parallel} | {mechanism} |
244
245## Thread Safety Guarantees
246
247- **Isolation**: {how workers are isolated}
248- **State Access**: {who can modify shared state}
249- **Barrier**: {how results are collected}
250```
251
252---
253
254## Pre-Diagram Checklist
255
256Before creating the diagram, verify:
257
258- [ ] LOADED `/autoskillit:mermaid` skill using the Skill tool
259- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)
260- [ ] Diagram will include a color legend table
261
262---
263
264## Related Skills
265
266- `/autoskillit:make-arch-diag` - Parent skill for lens selection
267- `/autoskillit:mermaid` - MUST BE LOADED before creating diagram
268- `/autoskillit:arch-lens-process-flow` - For general workflow view
269- `/autoskillit:arch-lens-error-resilience` - For parallel failure handling