A comprehensive TODO/Task Management application designed to demonstrate shared components and reusable patterns across multiple entities. Perfect for testing code review automation tools.
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.
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
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 taskUses custom exceptions hierarchy:
AppException- Base exceptionValidationError- When validation failsNotFoundError- When resource not foundConflictError- When resource conflicts (duplicates)
All entities validate before storage:
task = Task(...)
is_valid, error = task.validate()
if not is_valid:
raise ValidationError(error)# 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.txtpython main.pyShows all components working together following established patterns.
python -m unittest discover tests -v- Uses
BaseModelfor structure - Implements validation
- Has status (TODO, IN_PROGRESS, DONE, BLOCKED)
- Has priority (LOW, MEDIUM, HIGH, CRITICAL)
- Can be overdue, marked done, tagged
- Uses
BaseModelfor structure - Has members and progress tracking
- Can be activated/archived
- Groups tasks together
- Use
BaseModelfor consistency - Validate color format
- Track usage counts
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}")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}")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.TestTaskModelCreate PRs that violate these patterns:
- Skip BaseModel - Create a model without inheriting BaseModel
- Skip BaseRepository - Implement repository without BaseRepository
- Skip validation - Create entities without validation
- Wrong exception types - Use ValueError instead of ValidationError
- Inconsistent to_dict() - Different serialization approach
- Missing error handling - Don't catch exceptions properly
- Inline logic - Put repository logic in models
- No docstrings - Skip documentation
- All models extend BaseModel
- All repositories extend BaseRepository[T]
- Validation before storage
- Custom exceptions for errors
- Consistent serialization
- Proper error handling
- Separation of concerns
- Comprehensive documentation
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?
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
- Clone this repo β
- Run
python main.pyto see patterns in action - Run tests with
python -m unittest discover tests - Create a feature branch and add a feature that:
- Violates one or more patterns
- Is functional but "wrong"
- Create a PR for that feature
- Share with Code Rabbit for code review
- Verify if Code Rabbit detects the pattern violations
This project teaches:
- How to establish patterns across a codebase
- Inheritance and polymorphism
- Repository pattern
- Exception handling
- Validation patterns
- Consistent API design
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.