Skip to content

feat: single table design#8

Merged
hackmajoris merged 4 commits into
mainfrom
feat/single-table-design
Dec 7, 2025
Merged

feat: single table design#8
hackmajoris merged 4 commits into
mainfrom
feat/single-table-design

Conversation

@hackmajoris
Copy link
Copy Markdown
Owner

DynamoDB Single Table Design Implementation

Summary

Implements a comprehensive DynamoDB single table design architecture for the GLAD project, establishing scalable data access patterns and repository infrastructure for user and skill management.

Key Changes

Architecture & Database Layer

  • Migrated from multi-table to single table design using composite keys (PK/SK) and GSI patterns
  • Implemented repository pattern with dedicated UserRepository and SkillRepository interfaces
  • Added database factory pattern for cleaner dependency injection (cmd/app/internal/database/factory.go)
  • Enhanced mock database implementation with comprehensive test coverage

New Entities

  • User: Updated with single table design keys (PK: USER#<username>, SK: #METADATA#<username>)
  • UserSkill: New entity for user-skill relationships with proficiency levels and experience tracking
    • Supports access patterns: query skills by user, query users by skill, query by proficiency level
    • GSI for inverted lookups (GSI1PK: SKILL#<skill_name>, GSI1SK: LEVEL#<proficiency>#USER#<username>)

API & Handler Improvements

  • Refactored monolithic handler into focused user_handler.go with 7 user-related endpoints
  • Added DTO layer for clean API request/response contracts (cmd/app/internal/dto/dto.go)
  • Improved error handling with user-specific error types
  • Enhanced integration tests for new repository pattern

Infrastructure

  • Updated CDK deployment with single table configuration (deployments/app/cdk.go)
  • Added GSI definitions with proper capacity planning
  • Configured DynamoDB table with on-demand billing mode

Documentation Added

Three comprehensive documentation files in docs/:

  1. README-DYNAMODB-DESIGN.md - Overview and navigation guide

  2. dynamodb-single-table-design-plan.md (481 lines) - Complete implementation plan with:

    • Access pattern mapping (13+ patterns)
    • Entity designs with examples
    • Migration strategy and phases
    • Cost analysis and capacity planning
  3. entity-addition-protocol.md (607 lines) - Step-by-step protocol for adding new entities:

    • Decision trees for key pattern selection
    • Go code templates
    • Complete implementation checklist
    • Troubleshooting guide
  4. dynamodb-quick-reference.md (420 lines) - Developer cheat sheet with code snippets and common patterns

Testing

  • Updated integration tests for new repository interfaces
  • Added mock repository test coverage (cmd/app/internal/database/mock_test.go)
  • All existing tests passing with new architecture

This PR establishes the foundation for scalable DynamoDB usage and sets clear patterns for future entity additions.

hackmajoris and others added 4 commits December 7, 2025 14:43
Add new API endpoint that returns the authenticated user's profile
information based on the username extracted from JWT token.

Changes:
- Add GetCurrentUser handler in handler.go
- Add CurrentUserResponse DTO with ISO 8601 timestamps
- Register GET /me route with JWT authentication
- Update CDK stack to include /me API Gateway resource
- Add comprehensive handler tests with 100% coverage

Tests:
- TestHandler_GetCurrentUser: Success, invalid claims, user not found
- TestHandler_GetCurrentUser_TimestampFormat: ISO 8601/RFC3339 validation
- TestHandler_GetCurrentUser_DoesNotExposePassword: Security verification

Security:
- Password hash is never exposed in response
- Only returns safe fields: username, name, created_at, updated_at

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@hackmajoris hackmajoris changed the title Feat/single table design feat: single table design Dec 7, 2025
@hackmajoris hackmajoris merged commit 0f21a1f into main Dec 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant