- Intended Audience
- Overview
- Core Features
- Development Rules
- Code Organization
- Performance Guidelines
- Error Prevention
- Database Schema
- TODO & Future Improvements
This document serves as a reference for:
- Developers implementing todo list features
- Code reviewers evaluating changes
- Project managers tracking technical requirements
- QA engineers validating implementations
This document outlines the development guidelines and rules for the hierarchical Todo List application. These guidelines ensure:
- Consistent code quality across the project
- Maintainable and scalable architecture
- Reduced technical debt
- Faster onboarding for new team members
-
Task Creation
- New tasks via "Nuovo Task" input field
- Support for standalone and child tasks
- Input validation required
-
Task Hierarchy
- Maximum 4 levels of nesting (depth-0 through depth-3)
- Visual level indicators:
- Level 1: Primary blue (
--color-primary) - Level 2: Success green (
--color-success) - Level 3: Warning yellow (
--color-warning) - Level 4: Danger red (
--color-danger)
- Level 1: Primary blue (
-
Task Actions
- Complete/uncomplete functionality
- Delete capability
- Subtask counter
- List refresh feature
- Title length: 3-255 characters
- Allowed characters: alphanumeric, basic punctuation
- No HTML/script injection
- Examples: ✅ "Complete project report" ❌ "script tag with alert"
- Invalid input: Display inline validation message
- Network failure: Retry mechanism with user feedback
- Maximum depth reached: Clear warning with explanation
- Standalone: Top-level tasks with no parent
- Child: Subtasks that belong to a parent task Example hierarchy:
- Project Plan (standalone)
- Research (child)
- Market Analysis (child)
- Research (child)
- Browsers: Latest 2 versions of Chrome, Firefox, Safari, Edge
- Mobile: iOS 14+, Android 10+
- Minimum screen size: 320px width
- Unit test coverage: >80%
- E2E test scenarios:
- Task CRUD operations
- Nested task management
- Error handling
/* Container maximum width */
.todo {
max-width: 900px;
margin: 0 auto;
}
/* Task list height */
.todo__list {
height: calc(100vh - 180px);
overflow-y: auto;
}-
Breakpoints
- Mobile: < 768px (single column)
- Tablet: 768px - 1024px
- Desktop: > 1024px
-
Mobile Adaptations
- Hide button text
- Adjust task indentation
- Stack columns vertically
-
Accessibility Requirements
- Support reduced motion
- Keyboard navigation
- ARIA labels for interactive elements
- Minimum contrast ratio: 4.5:1
- Task items: role="listitem"
- Buttons: aria-label="[action description]"
- Status updates: aria-live="polite"
- Focus management for nested tasks
- Primary text: 7:1 ratio
- Secondary text: 4.5:1 ratio Example combinations:
- Text #2c3e50 on #ffffff = 7.72:1 ✅
- Text #6c757d on #f8f9fa = 3.28:1 ❌
-
Variable Naming
:root { /* Spacing */ --spacing-xs: 0.25rem; --spacing-sm: 0.5rem; --spacing-md: 0.75rem; --spacing-lg: 1rem; --spacing-xl: 1.5rem; /* Colors */ --color-border: #e9ecef; --color-bg-hover: #f8f9fa; --color-text: #2c3e50; --color-text-muted: #6c757d; --color-primary: #4a90e2; --color-success: #50b83c; --color-warning: #f4b400; --color-danger: #db4437; }
-
Class Naming Convention
- Follow BEM methodology
- Use descriptive, functional names
- Maintain consistent prefixing
✅ Good: .task-list {} .task-list__item {} .task-list__item--completed {}
❌ Bad: .taskList {} .task_list__item-completed {}
src/ config/ # Application configuration config.json # Environment-specific settings logger.ts # Logging configuration typeorm.config.ts # Database configuration controllers/ # Request handlers task.ts # Task-related business logic models/ # Data models Task.ts # Task entity definition public/ # Static assets css/ # Stylesheets js/ # Client-side scripts images/ # Image assets routes/ # Route definitions task.ts # Task-related routes views/ # Pug templates layouts/ # Layout templates mixins/ # Reusable template mixins home.pug # Main page template error.pug # Error page template index.ts # Application entry point
Required for each component:
- Purpose
- Props interface
- Usage examples
- Known limitations
-
Task Component Structure
.task { position: relative; display: grid; grid-template-columns: 1fr auto; min-height: 2rem; margin: var(--spacing-xs) 0; border-radius: var(--border-radius); }
-
Nesting Guidelines
- Maximum depth: 4 levels
- Visual indicators per level
- Consistent indentation
-
Pug Template Structure
- Use layouts for common elements
- Implement mixins for reusable components
- Keep templates DRY (Don't Repeat Yourself)
- Use semantic class names matching BEM
-
Template Organization
- Place page templates in root of views/
- Group related templates in subdirectories
- Use descriptive filenames (e.g., task-list.pug)
- Keep templates focused and single-purpose
-
Template Best Practices
- Use proper indentation (2 spaces)
- Include error handling blocks
- Implement responsive design classes
- Add data-testid attributes for testing
-
Mixin Usage
- Create mixins for repeated patterns
- Keep mixins in dedicated directory
- Document mixin parameters
- Use mixins for complex components
-
Controller Organization
- One controller per domain entity
- Keep controllers focused and single-purpose
- Implement proper error handling
- Use TypeScript types for request/response
-
Controller Best Practices
- Validate input before processing
- Use async/await for database operations
- Implement proper error responses
- Keep business logic in controllers
-
Error Handling
- Use consistent error response format
- Log errors appropriately
- Provide user-friendly error messages
- Handle edge cases gracefully
-
Type Safety
- Define interfaces for request/response
- Use TypeORM decorators properly
- Validate data types
- Handle null/undefined cases
-
Environment Configuration
- Use config.json for environment settings
- Keep sensitive data in environment variables
- Document all configuration options
- Use TypeScript for type safety
-
Logging Configuration
- Implement structured logging
- Use appropriate log levels
- Include request IDs for tracing
- Configure log rotation
-
Database Configuration
- Use TypeORM configuration file
- Document connection settings
- Implement migration strategy
- Handle connection errors
-
Security Configuration
- Configure CORS properly
- Set up security headers
- Implement rate limiting
- Use secure session management
-
Test Organization
- Place tests next to source files
- Use descriptive test names
- Group related tests
- Follow AAA pattern (Arrange, Act, Assert)
-
E2E Testing
- Use Playwright for browser tests
- Implement Page Object Model
- Test critical user flows
- Handle cleanup properly
-
Test Coverage
- Aim for >80% coverage
- Focus on business logic
- Test error cases
- Include edge cases
-
Test Data Management
- Use fixtures for test data
- Clean up after tests
- Use unique identifiers
- Handle async operations
-
Transitions
- Duration: ≤ 200ms
- Use hardware acceleration
- Implement reduced motion alternatives
-
Layout Performance
- Avoid nested animations
- Use CSS Grid for layouts
- Implement virtual scrolling
-
Image Optimization
- Use appropriate formats
- Implement lazy loading
- Compress assets
-
Code Splitting
- Lazy load components
- Bundle optimization
- Tree shaking
-
Input Validation
- No empty tasks
- Maximum character limit: 255
- Sanitize input
-
Nesting Validation
- Prevent excess nesting
- Validate parent-child relations
- Maintain hierarchy integrity
-
Boundary Protection
- Overflow handling
- Responsive safeguards
- Minimum touch targets: 44x44px
-
Error Handling
- Clear error messages
- Fallback UI states
- Recovery mechanisms
- Strip HTML tags
- Encode special characters
- Validate UTF-8 encoding
- Maximum length enforcement
- CSRF protection on forms
- XSS prevention in task content
- Rate limiting: 100 requests/minute
- Input validation on both client and server
CREATE TABLE tasks (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
createdAt DATETIME,
updatedAt DATETIME,
parentId TEXT,
depth INTEGER,
FOREIGN KEY (parentId) REFERENCES tasks(id)
);-
Required Indexes
- Primary key (id)
- Parent relationship (parentId)
- Creation date (createdAt)
-
Constraints
- NOT NULL on required fields
- Cascade delete for child tasks
- Maximum depth validation
- main: Production code
- develop: Integration branch
- feature/*: New features
- hotfix/*: Emergency fixes
- Follows naming conventions
- Implements error handling
- Includes tests
- Meets accessibility requirements
- Performance impact considered
- Implement internationalization (i18n) support
- Add query optimization for large datasets
- Implement caching strategy
- Define documentation update process
- Add comprehensive troubleshooting guides
-
Service Organization
- Create services for complex business logic
- Keep controllers thin, services thick
- One service per domain entity
- Use dependency injection
-
Service Responsibilities
- Handle business logic
- Manage data transformations
- Implement validation rules
- Handle complex queries
-
Service Best Practices
- Use TypeScript interfaces
- Implement proper error handling
- Keep methods focused
- Document public methods
-
RESTful Endpoints
- Use proper HTTP methods
- Follow resource naming conventions
- Implement proper status codes
- Version APIs when needed
-
API Documentation
- Document all endpoints
- Include request/response examples
- Document error responses
- Keep documentation up to date
-
API Security
- Implement proper authentication
- Use HTTPS
- Validate all inputs
- Rate limit endpoints
-
Client-Side State
- Use local storage for persistence
- Implement optimistic updates
- Handle offline scenarios
- Manage loading states
-
Server-Side State
- Use proper caching
- Implement session management
- Handle concurrent updates
- Maintain data consistency
-
Error Types
- ValidationError: Input validation failures
- NotFoundError: Resource not found
- BusinessError: Business rule violations
- SystemError: Technical failures
-
Error Response Format
interface ErrorResponse { code: string; message: string; details?: any; timestamp: string; }
-
Error Handling Strategy
- Log all errors
- Return appropriate status codes
- Provide user-friendly messages
- Handle edge cases
-
Keep It Simple
- Start with basic implementation
- Add features incrementally
- Avoid premature optimization
- Focus on core functionality
-
When to Add Components
- Business logic becomes complex
- Code duplication occurs
- Testing becomes difficult
- Maintenance becomes challenging
-
When to Add Services
- Business logic spans multiple controllers
- Complex data transformations needed
- External service integration required
- Complex validation rules needed
Note: These guidelines should be reviewed and updated as the project evolves. All team members should follow these rules to maintain consistency and quality across the codebase.