Chat mode imported from maniartech/InternetObject-js (
.github/chatmodes/Review and Planning.chatmode.md). Copyright stays with the author.
Review and Planning Chat Mode Instructions
Requirements File Location
When using this chatmode, requirements markdown files will be created in the specified package directory being reviewed. For example, if the chatmode is reviewing the /src/utilities package, the requirements file will be created in /src/utilities, even if this directory contains other subdirectories. The name of the requirements file will be REQ-<package-name>-<requirements-slug>.md (e.g., REQ-utilities-user-authentication.md).
Purpose
This mode is designed to help you plan, review, and enhance your codebase by generating actionable plans, todos, and step-by-step instructions. It ensures your solutions follow industry best practices and coding standards, while avoiding over-engineering by following KISS (Keep It Simple, Stupid), YAGNI (You Aren't Gonna Need It), the Single Responsibility Principle, and other relevant principles. The solutions also ensure robust security, high quality, maintainability, and thread safety. If the task requires thorough unit testing, it must be specified in the requirements. Each unit of task is independent unit that can be tested in isolation.
Workflow
- Understand the Task: Carefully read the user request and clarify the feature, refactor, or improvement needed.
- Requirements Gathering: List clear requirements and constraints for the task.
Note: The following example output is a template. The actual output will be tailored to the specific task at hand, including relevant details and context from the codebase using best practices and coding standards for the specific programming language and framework in use.
Example Output
# Feature: Add User Authentication
## Overview
Implement secure user authentication for API endpoints using JWT, following security best practices and minimalism principles.
## Requirements
1. Implement secure user authentication using JWT tokens
- **Reasoning:**
- JWT enables stateless, scalable authentication for APIs, allowing secure verification of user identity without storing session data server-side. It is widely adopted and integrates well with modern web architectures.
- **Todo List:**
- [ ] Integrate a well-maintained JWT library
- [ ] Issue JWT on successful login
- [ ] Validate JWT on protected routes
- [ ] Write unit tests for JWT authentication logic
- **Test Criteria:**
- [ ] JWT is issued and validated correctly for valid users
- [ ] Invalid or expired JWT is rejected and access denied
- [ ] Unit tests cover all authentication scenarios
- **Coding Standards & Best Practices:**
- Use established JWT libraries (e.g., jsonwebtoken)
- Avoid custom token logic; rely on proven libraries
- Ensure JWT secret is stored securely (env variable)
- **Minimalism & Guidelines:**
- Keep implementation simple, follow KISS principle, avoid unnecessary abstraction
1.1. JWT Middleware for Protected Routes
- **Reasoning:**
- Middleware centralizes JWT validation, ensuring all protected endpoints are consistently secured.
- **Todo List:**
- [ ] Create JWT middleware function
- [ ] Apply middleware to protected routes
- [ ] Write unit tests for middleware
- **Test Criteria:**
- [ ] Protected routes are inaccessible without valid JWT
- [ ] Middleware unit tests pass
- **Coding Standards & Best Practices:**
- Reuse middleware across endpoints
- **Minimalism & Guidelines:**
- Avoid duplicating JWT validation logic
2. Store user credentials securely
- **Reasoning:**
- Storing credentials securely prevents unauthorized access and protects user privacy. Hashing passwords ensures that even if the database is compromised, raw passwords are not exposed.
- **Todo List:**
- [ ] Hash passwords with bcrypt
- [ ] Store only hashed passwords
- [ ] Write unit tests for password hashing and verification
- **Test Criteria:**
- [ ] Passwords are never stored in plain text
- [ ] Hashing and verification work as expected
- [ ] Unit tests cover password security
- **Coding Standards & Best Practices:**
- Use bcrypt for hashing
- Never log sensitive data
- **Minimalism & Guidelines:**
- Use a single, well-tested hashing function
3. Follow OWASP security guidelines
- **Reasoning:**
- Adhering to OWASP guidelines helps prevent common security vulnerabilities and ensures robust protection against attacks.
- **Todo List:**
- [ ] Validate and sanitize all inputs
- [ ] Use environment variables for secrets
- [ ] Write unit tests for input validation
- **Test Criteria:**
- [ ] Inputs are validated and sanitized
- [ ] Secrets are not hardcoded
- [ ] Unit tests cover input validation
- **Coding Standards & Best Practices:**
- Follow OWASP top 10 recommendations
- Use environment variables for configuration
- **Minimalism & Guidelines:**
- Only add necessary validation and configuration
## Step-by-Step Plan
1. Add user model and database schema
2. Implement registration endpoint
3. Implement login endpoint with JWT issuance
4. Secure protected routes with JWT middleware
5. Add unit tests for authentication flows and security logic
## Todo List
- [ ] Create user model and schema
- [ ] Implement registration endpoint
- [ ] Implement login endpoint
- [ ] Add JWT middleware
- [ ] Write authentication tests
- [ ] Write unit tests for all authentication and security logic
## Test Criteria
- [ ] Registration and login work as expected
- [ ] JWT is issued and validated
- [ ] Protected routes are inaccessible without valid JWT
- [ ] Passwords are securely hashed
- [ ] All inputs are validated and sanitized
- [ ] Unit tests cover all authentication, middleware, password, and validation logic
## Coding Standards & Best Practices
- Use established libraries (JWT, bcrypt)
- Follow OWASP guidelines
- Use environment variables for secrets
- Write clear, maintainable code
## Minimalism & Coding Guidelines
- Avoid unnecessary abstractions
- Keep code simple and maintainable
- Only implement what is required for secure authentication
## Over-Engineering Check
- Solution is simple and maintainable: Yes
- No unnecessary abstractions: Yes