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
/arch-lens-repository-access or /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
/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
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 `/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
- `/make-arch-diag` - Parent skill for lens selection
- `/mermaid` - MUST BE LOADED before creating diagram
- `/arch-lens-data-lineage` - For data flow view
- `/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---56# Repository/Data Access Architecture Lens78**Cognitive Mode:** Data-Centric9**Primary Question:** "How is data accessed?"10**Focus:** Repository Pattern, Entity Relationships, Query Patterns, Format Conversion1112## When to Use1314- Need to understand data access layer architecture15- Documenting repository pattern implementation16- Analyzing entity relationships and query patterns17- User invokes `/arch-lens-repository-access` or `/make-arch-diag repository`1819## Critical Constraints2021**NEVER:**22- Modify any source code files23- Focus on data flow (that's data lineage lens)24- Include business logic details2526**ALWAYS:**27- Focus on REPOSITORIES and their methods28- Show entity relationships (1:1, 1:N, N:N)29- Document key query patterns30- Identify format conversion boundaries31- BEFORE creating any diagram, LOAD the `/mermaid` skill using the Skill tool - this is MANDATORY3233---3435## Analysis Workflow3637### Step 1: Launch Parallel Exploration Subagents3839Spawn Explore subagents to investigate:4041**Repository Classes**42- Find all repository implementations43- Identify base repository patterns44- Look for: Repository classes, DAO (Data Access Object) patterns, base repository abstractions4546**Entity Models**47- Find entity/model classes48- Identify table/collection definitions49- Look for: ORM models (ActiveRecord, Entity Framework, TypeORM, etc.), data models, entity classes5051**CRUD Operations**52- Find standard CRUD methods53- Identify specialized query methods54- Look for: create, get, update, delete, save, find_*, get_by_*, query methods5556**Query Patterns**57- Find complex queries and joins58- Identify index usage patterns59- Look for: filter, where, join, order_by, group_by, query builders6061**Factory/Scoping**62- Find repository factory patterns63- Identify scope management64- Look for: Factory patterns, dependency injection, session/context management6566**Format Conversion**67- Find adapter/converter patterns68- Identify boundary conversions69- Look for: Adapters, DTOs, to_*/from_* methods, serializers, mappers7071### Step 2: Map Entity Relationships7273Document:74- **Entities**: All model classes75- **Relationships**: Foreign key relationships, cardinality76- **Key Fields**: Primary keys, business keys77- **Repositories**: Which repo manages which entity7879**CRITICAL - Analyze Read/Write Direction:**80For EVERY repository method and data access:81- **Read methods**: `get_*`, `find_*`, `query_*` - data flows OUT of storage82- **Write methods**: `save_*`, `create_*`, `update_*`, `delete_*` - data flows INTO storage83- **Bulk operations**: Direction of each operation in batch8485For EVERY caller-to-repository relationship:86- Does the caller READ from this repository?87- Does the caller WRITE to this repository?88- Or both?8990Label connections accordingly (reads, writes, reads/writes)9192### Step 3: Document Access Patterns9394| 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 |100101### Step 4: Create the Diagram102103Use flowchart with:104105**Direction:** `LR` (left-to-right) for caller-to-storage flow106107**Subgraphs:**108- Callers (who uses repositories)109- Factory (repository construction)110- Repositories by Category111- Conversion (format boundaries)112- Storage (database tables)113114**Node Styling:**115- `cli` class: Callers (nodes, handlers)116- `phase` class: Factory, scoping117- `newComponent` class: Repositories (green to highlight)118- `handler` class: Conversion adapters119- `integration` class: Database storage120121**Show Relationships:**122- Entity relationships with cardinality (1:N)123- Repository-to-table mapping124- Conversion flow125126### Step 5: Write Output127128Write the diagram to: `temp/arch-lens-repository-access/arch_diag_repository_access_{YYYY-MM-DD_HHMMSS}.md`129130---131132## Output Template133134```markdown135# Repository/Data Access Diagram: {System Name}136137**Lens:** Repository/Data Access (Data-Centric)138**Question:** How is data accessed?139**Date:** {YYYY-MM-DD}140**Scope:** {What was analyzed}141142## Repository Overview143144| Category | Count | Key Repositories |145|----------|-------|------------------|146| {category} | {N} | {names} |147148## Data Access Diagram149150```mermaid151%%{init: {'flowchart': {'nodeSpacing': 50, 'rankSpacing': 60, 'curve': 'basis'}}}%%152flowchart LR153 %% CLASS DEFINITIONS %%154 classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;155 classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;156 classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;157 classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;158 classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;159 classDef integration fill:#c62828,stroke:#ef9a9a,stroke-width:2px,color:#fff;160 classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;161162 subgraph Callers ["CALLERS"]163 CALLER1["Handler/Service<br/>━━━━━━━━━━<br/>Business logic"]164 end165166 subgraph Factory ["REPOSITORY FACTORY"]167 direction TB168 FAC["RepositoryFactory<br/>━━━━━━━━━━<br/>Dependency injection"]169 SCOPE["Scoping<br/>━━━━━━━━━━<br/>Context management"]170 end171172 subgraph Repositories ["REPOSITORIES"]173 direction TB174 REPO1["EntityRepository<br/>━━━━━━━━━━<br/>CRUD methods"]175 BASE["BaseRepository<T><br/>━━━━━━━━━━<br/>Generic CRUD"]176 end177178 subgraph Conversion ["FORMAT CONVERSION"]179 direction TB180 ADAPTER["Adapters/DTOs<br/>━━━━━━━━━━<br/>Serialization"]181 end182183 subgraph Storage ["DATABASE"]184 direction TB185 DB[("Table/Collection<br/>━━━━━━━━━━<br/>Persistent storage")]186 end187188 %% FLOW %%189 CALLER1 --> FAC190 FAC --> SCOPE191 SCOPE --> REPO1192 BASE --> REPO1193 REPO1 --> ADAPTER194 ADAPTER --> DB195196 %% CLASS ASSIGNMENTS %%197 class CALLER1 cli;198 class FAC,SCOPE phase;199 class REPO1 newComponent;200 class BASE stateNode;201 class ADAPTER handler;202 class DB integration;203```204205**Color Legend:**206| Color | Category | Description |207|-------|----------|-------------|208| Dark Blue | Callers | Services/handlers that use repositories |209| Purple | Factory | Repository construction and scoping |210| Green | Repositories | Repository implementations |211| Teal | Base | Generic base repository |212| Orange | Conversion | Format adapters/DTOs |213| Red | Storage | Database tables/collections |214215## Repository Categories216217| Category | Count | Key Repositories |218|----------|-------|------------------|219| {category} | {N} | {list} |220221## Key Query Patterns222223| Pattern | Repository Method | Use Case |224|---------|------------------|----------|225| {pattern} | {method} | {use case} |226227## Entity Relationships228229| Parent | Child | Cardinality | FK |230|--------|-------|-------------|-----|231| {parent} | {child} | {1:N/1:1} | {fk field} |232```233234---235236## Pre-Diagram Checklist237238Before creating the diagram, verify:239240- [ ] LOADED `/mermaid` skill using the Skill tool241- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)242- [ ] Diagram will include a color legend table243244---245246## Related Skills247248- `/make-arch-diag` - Parent skill for lens selection249- `/mermaid` - MUST BE LOADED before creating diagram250- `/arch-lens-data-lineage` - For data flow view251- `/arch-lens-c4-container` - For storage container view