Repository/Data Access Architecture Lens
Cognitive Mode: Data-Centric
Primary Question: "How is data accessed?"
Focus: Repository Pattern, Entity Relationships, Query Patterns, Format Conversion
When to Use
- Need to understand data access layer architecture
- Documenting repository pattern implementation
- Analyzing entity relationships and query patterns
- User invokes
/autoskillit:arch-lens-repository-access or /autoskillit:make-arch-diag repository
Critical Constraints
NEVER:
- Modify any source code files
- Focus on data flow (that's data lineage lens)
- Include business logic details
ALWAYS:
- Focus on REPOSITORIES and their methods
- Show entity relationships (1:1, 1:N, N:N)
- Document key query patterns
- Identify format conversion boundaries
- 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:
Repository Classes
- Find all repository implementations
- Identify base repository patterns
- Look for: Repository classes, DAO (Data Access Object) patterns, base repository abstractions
Entity Models
- Find entity/model classes
- Identify table/collection definitions
- Look for: ORM models (ActiveRecord, Entity Framework, TypeORM, etc.), data models, entity classes
CRUD Operations
- Find standard CRUD methods
- Identify specialized query methods
- Look for: create, get, update, delete, save, find_*, get_by_*, query methods
Query Patterns
- Find complex queries and joins
- Identify index usage patterns
- Look for: filter, where, join, order_by, group_by, query builders
Factory/Scoping
- Find repository factory patterns
- Identify scope management
- Look for: Factory patterns, dependency injection, session/context management
Format Conversion
- Find adapter/converter patterns
- Identify boundary conversions
- Look for: Adapters, DTOs, to_*/from_* methods, serializers, mappers
Step 2: Map Entity Relationships
Document:
- Entities: All model classes
- Relationships: Foreign key relationships, cardinality
- Key Fields: Primary keys, business keys
- Repositories: Which repo manages which entity
CRITICAL - Analyze Read/Write Direction:
For EVERY repository method and data access:
- Read methods:
get_*, find_*, query_* - data flows OUT of storage
- Write methods:
save_*, create_*, update_*, delete_* - data flows INTO storage
- Bulk operations: Direction of each operation in batch
For EVERY caller-to-repository relationship:
- Does the caller READ from this repository?
- Does the caller WRITE to this repository?
- Or both?
Label connections accordingly (reads, writes, reads/writes)
Step 3: Document Access Patterns
| Pattern |
Repository Method |
Use Case |
| By ID |
get_by_id() |
Single entity lookup |
| By Business Key |
get_by_* |
Domain-specific lookup |
| List |
get_all(), get_for_* |
Collection queries |
| Bulk |
save_many() |
Batch operations |
Step 4: Create the Diagram
Use flowchart with:
Direction: LR (left-to-right) for caller-to-storage flow
Subgraphs:
- Callers (who uses repositories)
- Factory (repository construction)
- Repositories by Category
- Conversion (format boundaries)
- Storage (database tables)
Node Styling:
cli class: Callers (nodes, handlers)
phase class: Factory, scoping
newComponent class: Repositories (green to highlight)
handler class: Conversion adapters
integration class: Database storage
Show Relationships:
- Entity relationships with cardinality (1:N)
- Repository-to-table mapping
- Conversion flow
Step 5: Write Output
Write the diagram to: temp/arch-lens-repository-access/arch_diag_repository_access_{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
# Repository/Data Access Diagram: {System Name}
**Lens:** Repository/Data Access (Data-Centric)
**Question:** How is data accessed?
**Date:** {YYYY-MM-DD}
**Scope:** {What was analyzed}
## Repository Overview
| Category | Count | Key Repositories |
|----------|-------|------------------|
| {category} | {N} | {names} |
## Data Access Diagram
```mermaid
%%{init: {'flowchart': {'nodeSpacing': 50, 'rankSpacing': 60, 'curve': 'basis'}}}%%
flowchart LR
%% CLASS DEFINITIONS %%
classDef cli 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 output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef integration fill:#c62828,stroke:#ef9a9a,stroke-width:2px,color:#fff;
classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;
subgraph Callers ["CALLERS"]
CALLER1["Handler/Service<br/>━━━━━━━━━━<br/>Business logic"]
end
subgraph Factory ["REPOSITORY FACTORY"]
direction TB
FAC["RepositoryFactory<br/>━━━━━━━━━━<br/>Dependency injection"]
SCOPE["Scoping<br/>━━━━━━━━━━<br/>Context management"]
end
subgraph Repositories ["REPOSITORIES"]
direction TB
REPO1["EntityRepository<br/>━━━━━━━━━━<br/>CRUD methods"]
BASE["BaseRepository<T><br/>━━━━━━━━━━<br/>Generic CRUD"]
end
subgraph Conversion ["FORMAT CONVERSION"]
direction TB
ADAPTER["Adapters/DTOs<br/>━━━━━━━━━━<br/>Serialization"]
end
subgraph Storage ["DATABASE"]
direction TB
DB[("Table/Collection<br/>━━━━━━━━━━<br/>Persistent storage")]
end
%% FLOW %%
CALLER1 --> FAC
FAC --> SCOPE
SCOPE --> REPO1
BASE --> REPO1
REPO1 --> ADAPTER
ADAPTER --> DB
%% CLASS ASSIGNMENTS %%
class CALLER1 cli;
class FAC,SCOPE phase;
class REPO1 newComponent;
class BASE stateNode;
class ADAPTER handler;
class DB integration;
Color Legend:
| Color |
Category |
Description |
| Dark Blue |
Callers |
Services/handlers that use repositories |
| Purple |
Factory |
Repository construction and scoping |
| Green |
Repositories |
Repository implementations |
| Teal |
Base |
Generic base repository |
| Orange |
Conversion |
Format adapters/DTOs |
| Red |
Storage |
Database tables/collections |
Repository Categories
| Category |
Count |
Key Repositories |
| {category} |
{N} |
{list} |
Key Query Patterns
| Pattern |
Repository Method |
Use Case |
| {pattern} |
{method} |
{use case} |
Entity Relationships
| Parent |
Child |
Cardinality |
FK |
| {parent} |
{child} |
{1:N/1:1} |
{fk field} |
---
## 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-data-lineage` - For data flow view
- `/autoskillit:arch-lens-c4-container` - For storage container view
1---2name: arch-lens-repository-access3description: Create Repository/Data Access architecture diagram showing the repository pattern, entity relationships, and data access patterns. Data-centric lens answering "How is data accessed?"4---5
6# Repository/Data Access Architecture Lens
7
8**Cognitive Mode:** Data-Centric
9**Primary Question:** "How is data accessed?"
10**Focus:** Repository Pattern, Entity Relationships, Query Patterns, Format Conversion
11
12## When to Use
13
14- Need to understand data access layer architecture
15- Documenting repository pattern implementation
16- Analyzing entity relationships and query patterns
17- User invokes `/autoskillit:arch-lens-repository-access` or `/autoskillit:make-arch-diag repository`
18
19## Critical Constraints
20
21**NEVER:**
22- Modify any source code files
23- Focus on data flow (that's data lineage lens)
24- Include business logic details
25
26**ALWAYS:**
27- Focus on REPOSITORIES and their methods
28- Show entity relationships (1:1, 1:N, N:N)
29- Document key query patterns
30- Identify format conversion boundaries
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**Repository Classes**
42- Find all repository implementations
43- Identify base repository patterns
44- Look for: Repository classes, DAO (Data Access Object) patterns, base repository abstractions
45
46**Entity Models**
47- Find entity/model classes
48- Identify table/collection definitions
49- Look for: ORM models (ActiveRecord, Entity Framework, TypeORM, etc.), data models, entity classes
50
51**CRUD Operations**
52- Find standard CRUD methods
53- Identify specialized query methods
54- Look for: create, get, update, delete, save, find_*, get_by_*, query methods
55
56**Query Patterns**
57- Find complex queries and joins
58- Identify index usage patterns
59- Look for: filter, where, join, order_by, group_by, query builders
60
61**Factory/Scoping**
62- Find repository factory patterns
63- Identify scope management
64- Look for: Factory patterns, dependency injection, session/context management
65
66**Format Conversion**
67- Find adapter/converter patterns
68- Identify boundary conversions
69- Look for: Adapters, DTOs, to_*/from_* methods, serializers, mappers
70
71### Step 2: Map Entity Relationships
72
73Document:
74- **Entities**: All model classes
75- **Relationships**: Foreign key relationships, cardinality
76- **Key Fields**: Primary keys, business keys
77- **Repositories**: Which repo manages which entity
78
79**CRITICAL - Analyze Read/Write Direction:**
80For EVERY repository method and data access:
81- **Read methods**: `get_*`, `find_*`, `query_*` - data flows OUT of storage
82- **Write methods**: `save_*`, `create_*`, `update_*`, `delete_*` - data flows INTO storage
83- **Bulk operations**: Direction of each operation in batch
84
85For EVERY caller-to-repository relationship:
86- Does the caller READ from this repository?
87- Does the caller WRITE to this repository?
88- Or both?
89
90Label connections accordingly (reads, writes, reads/writes)
91
92### Step 3: Document Access Patterns
93
94| Pattern | Repository Method | Use Case |
95|---------|------------------|----------|
96| By ID | get_by_id() | Single entity lookup |
97| By Business Key | get_by_* | Domain-specific lookup |
98| List | get_all(), get_for_* | Collection queries |
99| Bulk | save_many() | Batch operations |
100
101### Step 4: Create the Diagram
102
103Use flowchart with:
104
105**Direction:** `LR` (left-to-right) for caller-to-storage flow
106
107**Subgraphs:**
108- Callers (who uses repositories)
109- Factory (repository construction)
110- Repositories by Category
111- Conversion (format boundaries)
112- Storage (database tables)
113
114**Node Styling:**
115- `cli` class: Callers (nodes, handlers)
116- `phase` class: Factory, scoping
117- `newComponent` class: Repositories (green to highlight)
118- `handler` class: Conversion adapters
119- `integration` class: Database storage
120
121**Show Relationships:**
122- Entity relationships with cardinality (1:N)
123- Repository-to-table mapping
124- Conversion flow
125
126### Step 5: Write Output
127
128Write the diagram to: `temp/arch-lens-repository-access/arch_diag_repository_access_{YYYY-MM-DD_HHMMSS}.md` (relative to the current working directory)
129
130After writing the diagram file, emit a structured output line:
131
132```
133diagram_path = {absolute_path_to_diagram_file}
134```
135
136---
137
138## Output Template
139
140```markdown
141# Repository/Data Access Diagram: {System Name}
142
143**Lens:** Repository/Data Access (Data-Centric)
144**Question:** How is data accessed?
145**Date:** {YYYY-MM-DD}
146**Scope:** {What was analyzed}
147
148## Repository Overview
149
150| Category | Count | Key Repositories |
151|----------|-------|------------------|
152| {category} | {N} | {names} |
153
154## Data Access Diagram
155
156```mermaid
157%%{init: {'flowchart': {'nodeSpacing': 50, 'rankSpacing': 60, 'curve': 'basis'}}}%%
158flowchart LR
159 %% CLASS DEFINITIONS %%
160 classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;
161 classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;
162 classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;
163 classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;
164 classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
165 classDef integration fill:#c62828,stroke:#ef9a9a,stroke-width:2px,color:#fff;
166 classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;
167
168 subgraph Callers ["CALLERS"]
169 CALLER1["Handler/Service<br/>━━━━━━━━━━<br/>Business logic"]
170 end
171
172 subgraph Factory ["REPOSITORY FACTORY"]
173 direction TB
174 FAC["RepositoryFactory<br/>━━━━━━━━━━<br/>Dependency injection"]
175 SCOPE["Scoping<br/>━━━━━━━━━━<br/>Context management"]
176 end
177
178 subgraph Repositories ["REPOSITORIES"]
179 direction TB
180 REPO1["EntityRepository<br/>━━━━━━━━━━<br/>CRUD methods"]
181 BASE["BaseRepository<T><br/>━━━━━━━━━━<br/>Generic CRUD"]
182 end
183
184 subgraph Conversion ["FORMAT CONVERSION"]
185 direction TB
186 ADAPTER["Adapters/DTOs<br/>━━━━━━━━━━<br/>Serialization"]
187 end
188
189 subgraph Storage ["DATABASE"]
190 direction TB
191 DB[("Table/Collection<br/>━━━━━━━━━━<br/>Persistent storage")]
192 end
193
194 %% FLOW %%
195 CALLER1 --> FAC
196 FAC --> SCOPE
197 SCOPE --> REPO1
198 BASE --> REPO1
199 REPO1 --> ADAPTER
200 ADAPTER --> DB
201
202 %% CLASS ASSIGNMENTS %%
203 class CALLER1 cli;
204 class FAC,SCOPE phase;
205 class REPO1 newComponent;
206 class BASE stateNode;
207 class ADAPTER handler;
208 class DB integration;
209```
210
211**Color Legend:**
212| Color | Category | Description |
213|-------|----------|-------------|
214| Dark Blue | Callers | Services/handlers that use repositories |
215| Purple | Factory | Repository construction and scoping |
216| Green | Repositories | Repository implementations |
217| Teal | Base | Generic base repository |
218| Orange | Conversion | Format adapters/DTOs |
219| Red | Storage | Database tables/collections |
220
221## Repository Categories
222
223| Category | Count | Key Repositories |
224|----------|-------|------------------|
225| {category} | {N} | {list} |
226
227## Key Query Patterns
228
229| Pattern | Repository Method | Use Case |
230|---------|------------------|----------|
231| {pattern} | {method} | {use case} |
232
233## Entity Relationships
234
235| Parent | Child | Cardinality | FK |
236|--------|-------|-------------|-----|
237| {parent} | {child} | {1:N/1:1} | {fk field} |
238```
239
240---
241
242## Pre-Diagram Checklist
243
244Before creating the diagram, verify:
245
246- [ ] LOADED `/autoskillit:mermaid` skill using the Skill tool
247- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)
248- [ ] Diagram will include a color legend table
249
250---
251
252## Related Skills
253
254- `/autoskillit:make-arch-diag` - Parent skill for lens selection
255- `/autoskillit:mermaid` - MUST BE LOADED before creating diagram
256- `/autoskillit:arch-lens-data-lineage` - For data flow view
257- `/autoskillit:arch-lens-c4-container` - For storage container view