mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-05-08 23:03:13 -04:00
8.4 KiB
8.4 KiB
Cleanuparr - Claude AI Rules
Rules
- DO NOT break existing functionality - All features are critical and must continue to work
- When in doubt, ASK - Don't assume, clarify with the maintainer first
- Always read existing code before making changes - Understand the current architecture and patterns
- Follow existing patterns - Study the codebase style and match it exactly
- Ask before introducing new patterns - Use current coding standards or get approval first
- Prefer editing existing files over creating new ones - Build on existing work
- Flag potential gotchas or issues immediately - Document and report anything unexpected
- If unsure about an approach, ask before implementing
Project Overview
Cleanuparr is a tool for automating the cleanup of unwanted or blocked files in Sonarr, Radarr, Lidarr, Readarr, Whisparr and supported download clients (qBittorrent, Transmission, Deluge, uTorrent, rTorrent). It provides malware protection, automated cleanup, and queue management for *arr applications.
Key Features:
- Strike system for bad downloads
- Malware detection and blocking
- Automatic search triggering after removal (Seeker)
- Missing and upgrade search
- Orphaned download cleanup with cross-seed support
- Authentication (OIDC, 2FA)
- Notification providers (Apprise, Discord, Gotify, Notifiarr, Ntfy, Pushover, Telegram)
Architecture & Tech Stack
Backend
- .NET 10.0 (C#) with ASP.NET Core
- Architecture: Clean Architecture with
Features/subdirectory patternCleanuparr.Api- REST API and web host (Features/for endpoint groups)Cleanuparr.Application- Application services and use casesCleanuparr.Domain- Domain models (Entities, Enums, Exceptions)Cleanuparr.Infrastructure- External integrations (Features/for Arr, DownloadClient, Notifications, etc.)Cleanuparr.Persistence- Data access with EF Core (SQLite)Cleanuparr.Shared- Shared utilities
- Database: SQLite with Entity Framework Core
- Three separate contexts:
DataContext,EventsContext,UsersContext
- Three separate contexts:
- Key Libraries:
- MassTransit (messaging)
- Quartz.NET (scheduling)
- Serilog (logging)
- SignalR (real-time communication)
- Testing: xUnit + NSubstitute + Shouldly
- Always use NSubstitute for mocking in new tests (Moq is being phased out)
Frontend
- Angular 21 with TypeScript 5.9 (standalone components, zoneless, OnPush)
- UI: Custom glassmorphism design system with 33 custom components — no external UI frameworks
- Icons: @ng-icons/core + @ng-icons/tabler-icons
- Design System: 3-layer SCSS (
_variables->_tokens->_themes), dark/light themes - State Management: @ngrx/signals (Angular signals-based)
- Real-time Updates: @microsoft/signalr 10.0.0
- PWA: Service Worker support enabled
Project Structure
Cleanuparr/
├── code/
│ ├── backend/
│ │ ├── Cleanuparr.Api/ # REST API (Features/ for endpoint groups)
│ │ ├── Cleanuparr.Api.Tests/ # API layer tests
│ │ ├── Cleanuparr.Application/ # Business logic layer
│ │ ├── Cleanuparr.Domain/ # Domain models
│ │ ├── Cleanuparr.Infrastructure/ # External integrations (Features/ subdirs)
│ │ ├── Cleanuparr.Infrastructure.Tests/
│ │ ├── Cleanuparr.Persistence/ # SQLite data access
│ │ ├── Cleanuparr.Persistence.Tests/
│ │ └── Cleanuparr.Shared/ # Shared utilities
│ ├── frontend/ # Angular 21 application
│ ├── e2e/ # Playwright E2E tests
│ ├── Dockerfile # Multi-stage Docker build
│ ├── entrypoint.sh # Docker entrypoint
│ └── Makefile # Build & migration helpers
├── docs/ # Docusaurus documentation
├── .github/workflows/ # CI/CD pipelines
├── blacklist # Default malware patterns (strict)
├── blacklist_permissive # Less strict malware patterns
├── whitelist # Safe file extensions
└── whitelist_with_subtitles # Includes subtitle formats
Code Standards & Conventions
IMPORTANT: Always study existing code in the relevant area before making changes. Match the existing style exactly.
Backend (C#)
- Follow Microsoft C# Coding Conventions
- Use nullable reference types (
<Nullable>enable</Nullable>) - Add XML documentation comments for public APIs
- Use meaningful names - avoid abbreviations unless widely understood
- Keep services focused - single responsibility principle
- New integrations go under
Features/subdirectories (e.g.,Infrastructure/Features/Arr/)
Frontend (TypeScript/Angular)
- All components must be standalone with ChangeDetectionStrategy.OnPush
- Use
input()/output()function APIs (not@Input()/@Output()decorators) - Use Angular signals for reactive state (
signal(),computed(),effect()) - Follow the 3-layer SCSS design system (
_variables->_tokens->_themes) - Do not introduce external UI frameworks (no PrimeNG, Material, Tailwind, etc.)
- Component naming:
{feature}.component.ts - Service naming:
{feature}.service.ts - Look at similar existing components before creating new ones
Testing
- Backend: xUnit + NSubstitute + Shouldly
- Always use NSubstitute for mocking (Moq is being phased out)
- Write unit tests for new features and bug fixes
- Use descriptive test names that explain what is being tested
- No frontend unit tests currently
Git Commit Messages
- Use clear, descriptive messages in imperative mood
- Examples: "Add Discord notification support", "Fix memory leak in download client polling"
- Reference issue numbers when applicable: "Fix #123: Handle null response from Radarr API"
Development Setup
Running the Backend
cd code/backend
dotnet build Cleanuparr.Api/Cleanuparr.Api.csproj
dotnet run --project Cleanuparr.Api/Cleanuparr.Api.csproj
API runs at http://localhost:5000
Running the Frontend
cd code/frontend
npm install
npm start
UI runs at http://localhost:4200
Running Tests
cd code/backend
dotnet test
Database Migrations
Three separate database contexts, all commands run from the code directory:
# Data migrations (DataContext)
make migrate-data name=YourMigrationName
# Events migrations (EventsContext)
make migrate-events name=YourMigrationName
# Users migrations (UsersContext)
make migrate-users name=YourMigrationName
Common Development Workflows
Adding a New *arr Application Integration
- Add integration in
Cleanuparr.Infrastructure/Features/Arr/ - Update domain models in
Cleanuparr.Domain/ - Create/update services in
Cleanuparr.Application/ - Add API endpoints in
Cleanuparr.Api/Features/Arr/ - Update frontend in
code/frontend/src/app/
Adding a New Download Client
- Add client implementation in
Cleanuparr.Infrastructure/Features/DownloadClient/ - Follow existing patterns (qBittorrent, Transmission, etc.)
- Add configuration models to
Cleanuparr.Domain/ - Update API and frontend as above
Adding a New Notification Provider
- Add provider in
Cleanuparr.Infrastructure/Features/Notifications/ - Update configuration models
- Add UI configuration in frontend
Key Gotchas
- Custom glassmorphism design system - Do not introduce external UI frameworks (no PrimeNG, Material, Tailwind)
- All frontend components must be standalone with OnPush change detection
- Database migrations require awareness of all three contexts (Data, Events, Users)
- Malware blocker is a critical security feature - changes require careful testing
- Cross-seed integration allows keeping torrents that are actively seeding
- Real-time updates use SignalR - maintain websocket patterns when adding features
- Use
@ng-icons/core+@ng-icons/tabler-iconsfor icons (NOTangular-tabler-iconswhich doesn't support Angular 21) - Sidebar stays dark purple in both themes - uses sidebar-specific CSS variables
- The project uses Clean Architecture - respect layer boundaries
- Settings dirty tracking uses JSON snapshot comparison (
buildSnapshot()+hasPendingChanges())