### Install Passport and OAuth Strategies Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Installs the necessary npm packages for Passport.js, Google OAuth2, and GitHub OAuth2 strategies. These are essential for implementing authentication flows with these providers. ```bash npm install passport passport-google-oauth20 passport-github2 ``` -------------------------------- ### Install JWT and Type Definitions Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Installs the jsonwebtoken library for JWT handling and its corresponding TypeScript type definitions. This is required for implementing token generation, refresh, and validation features. ```bash npm install jsonwebtoken @types/jsonwebtoken ``` -------------------------------- ### Reflection Document Structure Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt An example of the expected structure for a reflection document generated by the /reflect command. It includes sections for what went well, challenges, lessons learned, and improvements. ```markdown # Reflection: OAuth2 Authentication Implementation ## What Went Well - Passport.js integration was straightforward - Strategy factory pattern provided good abstraction - Test-driven approach caught token expiry edge cases early - Redis session storage performed well under load testing ## Challenges Encountered - GitHub OAuth callback URL validation was stricter than expected - Token refresh timing required fine-tuning to avoid race conditions - Environment variable management needed better documentation ## Lessons Learned ### Technical - Always implement token refresh with buffer time (5 min before expiry) - OAuth callback URLs must match exactly, including trailing slashes - Redis connection pooling is essential for session management - Strategy pattern works well for provider abstraction ### Process - Creative phase helped avoid over-engineering the solution - Writing tests for success criteria first improved implementation focus - Breaking into phases prevented scope creep - Documentation during build saved time in reflection ## Improvements for Next Time - Add OAuth provider testing checklist to planning phase - Create reusable OAuth integration template - Document provider-specific quirks in creative phase - Set up staging environment for OAuth testing earlier **Status:** COMPLETED **Next Command:** /archive ``` -------------------------------- ### Initialize Project Task Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/README.md The initial step in the workflow involves using the `/van` command to add a new task, such as user authentication with OAuth2 support. This sets up the task for subsequent planning and execution phases. ```bash # Step 1: Initialize /van Add user authentication with OAuth2 support ``` -------------------------------- ### Create Implementation Plan with /plan Command Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Generates a detailed implementation plan for tasks identified as Level 2-4 complexity. It reviews codebase structure, identifies components needing creative phases, and updates `tasks.md` with the plan, including components to build, files to modify, technology validation, and components requiring creative phases. The next command is typically `/creative`. ```bash # After /van determines Level 2-4 complexity /plan # Expected output appended to memory-bank/tasks.md: # ## Implementation Plan # # ### Components to Build # - [ ] OAuth2 configuration module # - [ ] Authentication middleware # - [ ] User session management # - [ ] Token refresh mechanism # # ### Files to Modify # - `src/config/auth.ts` - OAuth2 configuration # - `src/middleware/auth.ts` - Authentication middleware # - `src/routes/auth.ts` - Authentication routes # # ### Technology Validation # - OAuth2 library: passport.js # - Session store: Redis # - Dependencies verified in package.json # # ### Components Requiring Creative Phase # - [CREATIVE] OAuth2 flow architecture (architecture) # - [CREATIVE] Session storage strategy (architecture) # # **Next Command:** /creative ``` -------------------------------- ### Plan Project Task Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/README.md The `/plan` command is used to initiate the planning phase for a task, particularly for Level 3 features. This step is crucial before proceeding to design exploration or implementation. ```bash # Step 2: Plan (VAN routes to PLAN for Level 3) /plan ``` -------------------------------- ### Archive Document Structure Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt An example of the expected structure for an archive document generated by the /archive command. It includes task summary, implementation details, design decisions, achievements, and links to related artifacts. ```markdown # Archive: OAuth2 Authentication Implementation **Task ID:** task-2024-001 **Completion Date:** 2024-01-15 **Complexity Level:** 3 **Duration:** 3 days ## Task Summary Implemented OAuth2 authentication with support for Google and GitHub providers, using Passport.js strategy pattern with Redis session storage and JWT tokens. ## Implementation Overview ### Components Built - OAuth2 configuration module (src/config/auth.ts) - Authentication middleware (src/middleware/auth.ts) - User session management (src/services/session.ts) - Token refresh mechanism (src/services/token.ts) ### Design Decisions Selected Passport.js with custom strategies over custom OAuth implementation or Auth0 based on balance of flexibility, cost, and maintenance burden. Strategy factory pattern chosen for provider abstraction. ### Key Technical Achievements - Zero-downtime token refresh with 5-minute buffer - Provider-agnostic authentication flow - Comprehensive test coverage (100% of auth paths) - Production-ready error handling and logging ## Links to Artifacts - Plan: memory-bank/tasks.md (archived) - Creative Phase: memory-bank/creative/creative-oauth2-flow.md (archived) - Reflection: memory-bank/reflection/reflection-task-2024-001.md - Tests: test/auth/, test/middleware/, test/services/ ## Lessons Learned Archive - OAuth callback URLs require exact matching including trailing slashes - Token refresh requires buffer time to prevent race conditions - Strategy pattern excellent for OAuth provider abstraction - Test-driven approach crucial for security-critical auth code **Status:** ARCHIVED ## Updates to Memory Bank - memory-bank/tasks.md: Task marked COMPLETE - memory-bank/progress.md: Final status and archive reference added - memory-bank/activeContext.md: Reset for next task ``` -------------------------------- ### Run Authentication Tests Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Executes the authentication tests for the project. This command is used to verify the correctness of the authentication configuration and strategy implementations. ```bash npm test -- auth.test.ts ``` -------------------------------- ### Implement Code with /build Command Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Executes the implementation of planned changes based on the `tasks.md` and creative phase decisions. This command involves writing code, running tests to meet success criteria, documenting commands and their results, and updating the Memory Bank system with the progress, typically in `memory-bank/progress.md`. ```bash # After planning and creative phases complete /build # Expected workflow and output in memory-bank/progress.md: # ## Build Progress # # ### Phase 1: OAuth2 Configuration Module # - Created src/config/auth.ts with provider configurations # - Implemented strategy factory pattern ``` -------------------------------- ### Initialize Project with /van Command Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Initializes the Memory Bank structure for a new task. It detects the platform, determines task complexity (Level 1-4), and routes to the appropriate workflow. This command creates essential files in the `memory-bank/` directory, including `tasks.md`, `activeContext.md`, `progress.md`, and `projectbrief.md`. ```bash # Initialize a new feature implementation task /van Add user authentication with OAuth2 support # Expected output in memory-bank/tasks.md: # ## Task: Add user authentication with OAuth2 support # **Status:** INITIALIZED # **Complexity Level:** 3 # **Rationale:** Requires new components, design decisions for OAuth flow # **Next Command:** /plan # # Platform detected: linux # Memory Bank structure verified: memory-bank/ # Files created: # - memory-bank/tasks.md # - memory-bank/activeContext.md # - memory-bank/progress.md # - memory-bank/projectbrief.md ``` -------------------------------- ### Execute Task Reflection Command Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Initiates the task reflection process, which involves reviewing the implemented task against the original plan, documenting successes, challenges, and lessons learned. This command is typically run after implementation is complete. ```bash /reflect ``` -------------------------------- ### Archive Task Documentation Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/README.md The /archive command creates comprehensive archive documentation and updates the Memory Bank. It reads reflection documents and task details, generates an archive document in `memory-bank/archive/archive-[task_id].md`, archives creative documents, updates `memory-bank/tasks.md` to COMPLETE, updates `memory-bank/progress.md`, and resets `memory-bank/activeContext.md`. ```bash # Step 6: Archive the completed task /archive ``` -------------------------------- ### Implement Planned Changes Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/README.md The /build command implements planned changes based on the project plan and creative decisions. It reads plans from `memory-bank/tasks.md`, considers creative documents, implements systematically, tests, documents executed commands and results, and updates `memory-bank/tasks.md` and `memory-bank/progress.md`. ```bash # Step 4: Implement the feature /build ``` -------------------------------- ### Reflect on Task Implementation Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/README.md The /reflect command enables structured reflection on completed implementation. It reviews the implementation against the original plan, documents successes, challenges, lessons learned, and improvements, creating `memory-bank/reflection/reflection-[task_id].md` and updating `memory-bank/tasks.md`. ```bash # Step 5: Reflect on the implementation /reflect ``` -------------------------------- ### Graph-Based Efficiency Visualization (Mermaid) Source: https://github.com/vanzan01/cursor-memory-bank/blob/main/memory_bank_upgrade_guide.md Illustrates the graph-based structure used for optimized path navigation and contextual relationships within the system. This visualization aids in understanding how decision trees are traversed with minimal overhead. ```mermaid graph TD Start[Entry Point] --> A[Decision Node] A -->|Condition 1| B[Process B] A -->|Condition 2| C[Process C] B --> D[Next Step] C --> D style Start fill:#f9d77e,stroke:#d9b95c,color:black style A fill:#a8d5ff,stroke:#88b5e0,color:black style B fill:#c5e8b7,stroke:#a5c897,color:black style C fill:#ffcccc,stroke:#ff9999,color:black style D fill:#d9b3ff,stroke:#b366ff,color:black ``` -------------------------------- ### Execute Task Archive Command Source: https://context7.com/vanzan01/cursor-memory-bank/llms.txt Initiates the task archiving process, which involves creating comprehensive documentation for the completed task, consolidating all artifacts, and updating progress records. This command is run after the reflection phase is complete. ```bash /archive ```