-
Notifications
You must be signed in to change notification settings - Fork 51
Description
GitHub Issue: Task 1.0 - Data Layer Patterns Documentation and Examples (11.2.2)
🎯 Task Overview
Task ID: 1.0
Parent Spec: docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.md
Status: Ready for Implementation
Estimated Time: 2-3 hours
This task implements comprehensive documentation for Data Layer Patterns (11.2.2), including Repository, Active Record, and Concurrency patterns (Optimistic/Pessimistic Locking) with working Go examples and an interactive quiz.
📋 Specification Context
Project Overview
This specification defines the remaining Design Patterns subsections for Chapter 11 (Application Development) of the DevOps Bootcamp. Building on the completed SOLID Principles foundation (11.2.1), this spec focuses on architectural patterns (data layer and business logic) and classical Gang of Four patterns that students will encounter in production applications.
User Story
US-1: Understanding Data Layer Patterns
As a bootcamp apprentice learning production development, I want to understand Repository and Active Record patterns so that I can structure data access logic in enterprise applications.
US-2: Managing Concurrent Data Access
As a developer building multi-user applications, I want to understand Optimistic and Pessimistic Locking patterns so that I can handle concurrent data modifications safely.
Functional Requirements
| ID | Requirement |
|---|---|
| U2-FR1 | The system shall explain Repository Pattern with implementation examples showing interface abstraction over data access operations |
| U2-FR2 | The system shall explain Active Record Pattern with examples showing domain objects that encapsulate data access methods |
| U2-FR3 | The system shall provide decision guidance contrasting Repository vs Active Record based on domain complexity, testability requirements, and team preferences |
| U2-FR4 | The system shall demonstrate Optimistic Locking pattern with self-contained SQLite database examples showing version-based conflict detection |
| U2-FR5 | The system shall demonstrate Pessimistic Locking pattern with self-contained SQLite database examples showing exclusive access control |
| U2-FR6 | The system shall include multi-user scenario examples demonstrating when each concurrency pattern is appropriate |
| U2-FR7 | The system shall include anti-patterns showing pain points of direct data access mixed with business logic |
| U2-FR8 | The system shall provide a self-directed refactoring exercise for students to convert direct data access to Repository pattern |
| U2-FR9 | The system shall include an interactive quiz testing pattern recognition and decision-making for data layer patterns |
✅ Acceptance Criteria (Proof Artifacts)
The following artifacts must exist and be verified for task completion:
- Documentation:
docs/11-application-development/11.2.2-data-layer-patterns.mdexists with complete content including front-matter, pattern explanations, decision guidance, and exercises - Repository Pattern:
examples/ch11/data-patterns/repository/contains working Go implementation with README, tests, and clear interface abstraction - Active Record Pattern:
examples/ch11/data-patterns/active-record/contains working Go implementation with README demonstrating domain objects with encapsulated data access - Optimistic Locking:
examples/ch11/data-patterns/concurrency/optimistic/contains SQLite-based demonstration with README showing version-based conflict detection - Pessimistic Locking:
examples/ch11/data-patterns/concurrency/pessimistic/contains SQLite-based demonstration with README showing exclusive access control - Quiz:
src/quizzes/chapter-11/11.2.2/data-layer-patterns-quiz.jsexists with pattern recognition questions following quizdown format - CLI Verification:
go test ./...passes in all example directories - Integration Verification: Quiz renders correctly in Docsify when served with
npm start
📝 Sub-tasks
Documentation Tasks
- 1.1 Create documentation file
docs/11-application-development/11.2.2-data-layer-patterns.mdwith front-matter (category: Application Development, technologies: Go/SQLite/Design Patterns, estReadingMinutes: 45, exercise definition) - 1.2 Write Repository Pattern section explaining interface abstraction over data access, benefits (testability, flexibility), and when to use it
- 1.3 Write Active Record Pattern section explaining domain objects with encapsulated data access methods and when to use it
- 1.4 Write pattern comparison section with decision guidance based on domain complexity, testability requirements, and team preferences
- 1.5 Write Optimistic Locking section explaining version-based conflict detection with multi-user scenario examples
- 1.6 Write Pessimistic Locking section explaining exclusive access control with multi-user scenario examples
- 1.7 Write anti-patterns section showing problems with direct data access mixed with business logic
- 1.8 Add self-directed refactoring exercise description for converting direct data access to Repository pattern
Code Example Tasks
- 1.9 Create Repository Pattern Go example in
examples/ch11/data-patterns/repository/with main.go, go.mod, repository.go (interface + implementation), README.md, and repository_test.go - 1.10 Create Active Record Pattern Go example in
examples/ch11/data-patterns/active-record/with main.go, go.mod, user.go (domain object with data access methods), README.md, and user_test.go - 1.11 Create Optimistic Locking Go example in
examples/ch11/data-patterns/concurrency/optimistic/with main.go demonstrating multi-user simulation, SQLite version checking, README.md, and tests - 1.12 Create Pessimistic Locking Go example in
examples/ch11/data-patterns/concurrency/pessimistic/with main.go demonstrating exclusive locking, SQLite transaction control, README.md, and tests
Quiz and Verification Tasks
- 1.13 Create interactive quiz
src/quizzes/chapter-11/11.2.2/data-layer-patterns-quiz.jswith 6-8 questions covering pattern recognition, concurrency scenarios, and when to use each pattern - 1.14 Verify all Go examples run successfully with
go run main.goand tests pass withgo test ./... - 1.15 Embed quiz in documentation using Docsify quiz syntax and verify it renders correctly with
npm start
📁 Relevant Files
Files to Create
docs/11-application-development/11.2.2-data-layer-patterns.md- Main documentationsrc/quizzes/chapter-11/11.2.2/data-layer-patterns-quiz.js- Interactive quizexamples/ch11/data-patterns/repository/main.go- Repository pattern executable demoexamples/ch11/data-patterns/repository/go.mod- Go module definitionexamples/ch11/data-patterns/repository/repository.go- Repository interface and implementationexamples/ch11/data-patterns/repository/repository_test.go- Unit testsexamples/ch11/data-patterns/repository/README.md- Setup and explanationexamples/ch11/data-patterns/active-record/main.go- Active Record executable demoexamples/ch11/data-patterns/active-record/go.mod- Go module definitionexamples/ch11/data-patterns/active-record/user.go- Domain object with data accessexamples/ch11/data-patterns/active-record/user_test.go- Unit testsexamples/ch11/data-patterns/active-record/README.md- Setup and explanationexamples/ch11/data-patterns/concurrency/optimistic/main.go- Optimistic locking demoexamples/ch11/data-patterns/concurrency/optimistic/go.mod- Go module definitionexamples/ch11/data-patterns/concurrency/optimistic/optimistic_lock.go- Implementationexamples/ch11/data-patterns/concurrency/optimistic/optimistic_lock_test.go- Unit testsexamples/ch11/data-patterns/concurrency/optimistic/README.md- Setup and explanationexamples/ch11/data-patterns/concurrency/pessimistic/main.go- Pessimistic locking demoexamples/ch11/data-patterns/concurrency/pessimistic/go.mod- Go module definitionexamples/ch11/data-patterns/concurrency/pessimistic/pessimistic_lock.go- Implementationexamples/ch11/data-patterns/concurrency/pessimistic/pessimistic_lock_test.go- Unit testsexamples/ch11/data-patterns/concurrency/pessimistic/README.md- Setup and explanation
Files to Reference
docs/11-application-development/11.2.1-solid-principles.md- Completed SOLID principles documentation (for cross-references)docs/11-application-development/11.1-layers.md- Layered architecture foundationexamples/ch11/solid-exercises/- Example of existing code example structuresrc/quizzes/chapter-11/11.2.1/solid-principles-quiz.js- Example quiz format to follow
🎓 Repository Standards
Code Example Standards
- Project Structure: All examples must be self-contained with
src/(or root-level for Go),tests/,README.md,.gitignore - README Requirements: Include setup instructions, dependency installation, and commands to run examples and tests
- Development Environment: Assume modern ARM-based macOS; avoid external service dependencies
- Database: Use SQLite for portability (no external database servers)
- Go Standards: Go 1.21+ with Go modules, follow standard Go project layout
- Testing: Use Go's built-in testing package, tests must pass with
go test ./...
Documentation Standards
- Front-Matter: Include YAML metadata with category, technologies, estReadingMinutes, exercises (with title, description, estMinutes)
- Technologies: Use
Go,SQLite,Design Patternsas technology tags - Header Levels: Use H2 (
##) for navigation-visible sections, H3 (###) as default within sections - Images: Use HTML
<img>tags, place indocs/11-application-development/img11/if needed - Cross-References: Link to 11.1 (Layered Architecture) and 11.2.1 (SOLID Principles) where relevant
Quiz Standards
- Format: Follow existing quizdown format from
src/quizzes/chapter-11/11.2.1/solid-principles-quiz.js - Question Types: Include pattern recognition (with code snippets), conceptual understanding, and decision-making scenarios
- Question Count: 6-8 questions covering all patterns taught in the section
- Feedback: Provide immediate feedback explaining correct and incorrect answers
- Integration: Ensure quiz renders correctly within Docsify documentation
🔗 Related Documentation
- Full Spec:
docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.md - Complete Task List:
docs/specs/01-spec-design-patterns-section/01-tasks-design-patterns-section.md - Project Overview:
CLAUDE.md(repository root) - Style Guide:
STYLE.md(repository root)
🤖 AI Agent Instructions
Implementation Approach
- Start with Documentation Structure: Create the markdown file with proper front-matter first
- Write Pattern Explanations: Focus on clarity and practical examples in the documentation
- Build Examples Incrementally: Start with simplest (Repository), then Active Record, then concurrency patterns
- Test as You Go: Ensure each example runs and tests pass before moving to the next
- Create Quiz Last: Quiz questions should reflect the content you've written
- Verify Integration: Test the complete documentation with Docsify at the end
Quality Checklist
- All Go code follows Go best practices (gofmt, golint compliant)
- Each example has a clear, working README with setup instructions
- All tests pass with
go test ./... - Documentation includes proper front-matter matching bootcamp conventions
- Quiz follows quizdown format and renders in Docsify
- Cross-references to 11.1 and 11.2.1 are accurate
- Anti-patterns section provides clear contrast to patterns
- Self-directed exercise is actionable and clear
Dependencies
- Go 1.21 or higher
- SQLite (included with Go's database/sql driver)
- Go modules for dependency management
- No external services required
Success Criteria
This task is complete when:
- All 15 sub-tasks are checked off
- All proof artifacts exist and are verified
go test ./...passes in all example directoriesnpm startsuccessfully renders documentation with embedded quiz- Documentation follows bootcamp conventions and style guide
📋 How to Create This Issue
Option 1: After SAML Authorization
Authorize your GitHub token at: https://github.com/orgs/liatrio/sso
Then run:
gh issue create --repo liatrio/devops-bootcamp \
--title "Task 1.0: Data Layer Patterns Documentation and Examples (11.2.2)" \
--body-file docs/specs/01-spec-design-patterns-section/task-1.0-github-issue.mdOption 2: Manual Creation
- Go to https://github.com/liatrio/devops-bootcamp/issues/new
- Copy the content from this file (starting from "## 🎯 Task Overview")
- Paste into the issue body
- Set title: "Task 1.0: Data Layer Patterns Documentation and Examples (11.2.2)"
- Add labels:
documentation,enhancement,chapter-11