Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TODO Management Application

A comprehensive TODO/Task Management application designed to demonstrate shared components and reusable patterns across multiple entities. Perfect for testing code review automation tools.

🎯 Purpose

This project establishes clear, consistent patterns across the entire codebase:

  • BaseModel - All entities inherit from this
  • BaseRepository - All services follow this pattern
  • Custom Exceptions - Consistent error handling
  • Validation - Applied uniformly
  • Response Models - Standardized API responses

You can create feature branches that violate these patterns to test if Code Rabbit can detect them.

πŸ“¦ Project Structure

todo-project/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ common/                    # SHARED COMPONENTS (key!)
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base.py               # BaseModel, BaseRepository
β”‚   β”‚   β”œβ”€β”€ exceptions.py          # AppException, ValidationError, NotFoundError
β”‚   β”‚   β”œβ”€β”€ response.py            # ResponseModel, SuccessResponse, ErrorResponse
β”‚   β”‚   └── validators.py          # BaseValidator, specific validators
β”‚   β”‚
β”‚   β”œβ”€β”€ models/                    # Entities using BaseModel
β”‚   β”‚   β”œβ”€β”€ task.py               # Task (uses BaseModel)
β”‚   β”‚   β”œβ”€β”€ project.py            # Project (uses BaseModel)
β”‚   β”‚   β”œβ”€β”€ category.py           # Category (uses BaseModel)
β”‚   β”‚   └── tag.py                # Tag (uses BaseModel)
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                 # Repositories using BaseRepository
β”‚   β”‚   β”œβ”€β”€ task_service.py       # TaskRepository (uses BaseRepository)
β”‚   β”‚   β”œβ”€β”€ project_service.py    # ProjectRepository (uses BaseRepository)
β”‚   β”‚   β”œβ”€β”€ category_service.py   # CategoryRepository (uses BaseRepository)
β”‚   β”‚   └── tag_service.py        # TagRepository (uses BaseRepository)
β”‚   β”‚
β”‚   └── utils/                     # Utilities
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_task.py
β”‚   └── test_project.py
β”‚
β”œβ”€β”€ main.py                        # Demo showing patterns in action
└── requirements.txt

πŸ—οΈ Established Patterns

1. BaseModel Pattern (Used by: Task, Project, Category, Tag)

All entities inherit from BaseModel and implement:

  • validate() - Returns Tuple[bool, Optional[str]]
  • to_dict() - Serialization
  • Common attributes: id, created_at, updated_at
class Task(BaseModel):
    def validate(self) -> Tuple[bool, Optional[str]]:
        if not self.title:
            return False, "Title is required"
        return True, None
    
    def to_dict(self) -> Dict[str, Any]:
        return {"id": self.id, "title": self.title, ...}

2. BaseRepository Pattern (Used by: TaskRepository, ProjectRepository, CategoryRepository, TagRepository)

All repositories inherit from BaseRepository[T] and implement:

  • create(**kwargs) -> T - Create with validation
  • Inherited: get(), get_all(), update(), delete(), count(), exists()
  • Custom finders: find_by_status(), find_by_tag(), etc.
class TaskRepository(BaseRepository[Task]):
    def create(self, title: str, ...) -> Task:
        task = Task(...)
        is_valid, error = task.validate()
        if not is_valid:
            raise ValidationError(error)
        self._items[task.id] = task
        return task

3. Exception Handling Pattern

Uses custom exceptions hierarchy:

  • AppException - Base exception
  • ValidationError - When validation fails
  • NotFoundError - When resource not found
  • ConflictError - When resource conflicts (duplicates)

4. Validation Pattern

All entities validate before storage:

task = Task(...)
is_valid, error = task.validate()
if not is_valid:
    raise ValidationError(error)

πŸš€ Quick Start

Installation

# Clone and setup
git clone <repo>
cd todo-project

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Run Demo

python main.py

Shows all components working together following established patterns.

Run Tests

python -m unittest discover tests -v

πŸ“‹ Entity Examples

Task (Product Entity)

  • Uses BaseModel for structure
  • Implements validation
  • Has status (TODO, IN_PROGRESS, DONE, BLOCKED)
  • Has priority (LOW, MEDIUM, HIGH, CRITICAL)
  • Can be overdue, marked done, tagged

Project (Container Entity)

  • Uses BaseModel for structure
  • Has members and progress tracking
  • Can be activated/archived
  • Groups tasks together

Category & Tag (Reference Entities)

  • Use BaseModel for consistency
  • Validate color format
  • Track usage counts

πŸ”„ Using Shared Components

Creating a Task

from app.services.task_service import TaskRepository
from app.models.task import TaskStatus, TaskPriority
from app.common.exceptions import ValidationError

repo = TaskRepository()

try:
    task = repo.create(
        title="New Task",
        priority=TaskPriority.HIGH,
        status=TaskStatus.TODO,
    )
except ValidationError as e:
    print(f"Validation failed: {e.message}")

Creating a Project

from app.services.project_service import ProjectRepository
from app.models.project import ProjectStatus

repo = ProjectRepository()

try:
    project = repo.create(
        name="New Project",
        owner_id=1,
        status=ProjectStatus.PLANNING,
    )
except ValidationError as e:
    print(f"Validation failed: {e.message}")

πŸ§ͺ Testing Patterns

All tests demonstrate:

  • Model validation
  • Repository CRUD operations
  • Custom exception handling
  • Finder methods
# Run all tests
python -m unittest discover tests -v

# Run specific test
python -m unittest tests.test_task.TestTaskModel

🎯 What to Test with Code Rabbit

Create PRs that violate these patterns:

❌ Bad Patterns (To Test Detection):

  1. Skip BaseModel - Create a model without inheriting BaseModel
  2. Skip BaseRepository - Implement repository without BaseRepository
  3. Skip validation - Create entities without validation
  4. Wrong exception types - Use ValueError instead of ValidationError
  5. Inconsistent to_dict() - Different serialization approach
  6. Missing error handling - Don't catch exceptions properly
  7. Inline logic - Put repository logic in models
  8. No docstrings - Skip documentation

βœ… Good Patterns (Already Established):

  1. All models extend BaseModel
  2. All repositories extend BaseRepository[T]
  3. Validation before storage
  4. Custom exceptions for errors
  5. Consistent serialization
  6. Proper error handling
  7. Separation of concerns
  8. Comprehensive documentation

πŸ“Š Metrics for Code Rabbit Testing

This project is designed to test:

  • Pattern Detection - Does it identify BaseModel/BaseRepository usage?
  • Inheritance Tracking - Does it understand class hierarchies?
  • Error Handling - Can it flag missing exception handling?
  • Validation Logic - Does it recognize validation patterns?
  • Code Consistency - Can it detect deviations from established patterns?
  • Code Graph Accuracy - Does code graph show correct dependencies?
  • Embeddings - Do embeddings capture semantic meaning?

πŸ”— Component Dependencies

common/ (Shared)
β”œβ”€β”€ exceptions.py β†’ Used by all services
β”œβ”€β”€ validators.py β†’ Used in models for validation
β”œβ”€β”€ response.py β†’ For API responses
└── base.py β†’ BaseModel (inherited by all models)
              BaseRepository (inherited by all services)

models/ (All use BaseModel)
β”œβ”€β”€ task.py
β”œβ”€β”€ project.py
β”œβ”€β”€ category.py
└── tag.py

services/ (All use BaseRepository)
β”œβ”€β”€ task_service.py
β”œβ”€β”€ project_service.py
β”œβ”€β”€ category_service.py
└── tag_service.py

πŸ“ Next Steps

  1. Clone this repo βœ“
  2. Run python main.py to see patterns in action
  3. Run tests with python -m unittest discover tests
  4. Create a feature branch and add a feature that:
    • Violates one or more patterns
    • Is functional but "wrong"
  5. Create a PR for that feature
  6. Share with Code Rabbit for code review
  7. Verify if Code Rabbit detects the pattern violations

πŸŽ“ Learning

This project teaches:

  • How to establish patterns across a codebase
  • Inheritance and polymorphism
  • Repository pattern
  • Exception handling
  • Validation patterns
  • Consistent API design

πŸ“„ License

MIT License


Perfect for testing Code Review Automation! πŸš€

The clear pattern established makes it easy to create "bad" code that violates norms, and see if Code Rabbit can detect these violations accurately.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages