# SERVICE LAYER KNOWLEDGE BASE

**Generated:** 2026-01-28
**Parent:** EmailBill/AGENTS.md

## OVERVIEW
Business logic layer with job scheduling, email processing, and application services.

## STRUCTURE
```
Service/
├── GlobalUsings.cs              # Common imports
├── Jobs/                        # Background jobs
│   ├── BudgetArchiveJob.cs      # Budget archiving
│   ├── DbBackupJob.cs           # Database backups
│   ├── EmailSyncJob.cs          # Email synchronization
│   └── PeriodicBillJob.cs       # Periodic bill processing
├── EmailServices/               # Email processing
│   ├── EmailHandleService.cs    # Email handling logic
│   ├── EmailFetchService.cs     # Email fetching
│   ├── EmailSyncService.cs      # Email synchronization
│   └── EmailParse/              # Email parsing services
├── AppSettingModel/             # Configuration models
├── Budget/                      # Budget services
└── [Various service classes]    # Core business services
```

## WHERE TO LOOK
| Task | Location | Notes |
|------|----------|-------|
| Background jobs | Jobs/ | Scheduled tasks, cron patterns |
| Email processing | EmailServices/ | Email parsing, handling, sync |
| Budget logic | Budget/ | Budget calculations, stats |
| Configuration | AppSettingModel/ | Settings models, validation |
| Core services | *.cs | Main business logic |

## CONVENTIONS
- Service classes end with "Service" suffix
- Jobs inherit from appropriate base job classes
- Use IDateTimeProvider for time operations
- Async/await for I/O operations
- Dependency injection via constructor

## ANTI-PATTERNS (THIS LAYER)
- Never access database directly (use repositories)
- Don't return domain entities to controllers (use DTOs)
- Avoid long-running operations in main thread
- No hardcoded configuration values
- Don't mix service responsibilities

## UNIQUE STYLES
- Email parsing with multiple format handlers
- Background job patterns with error handling
- Configuration models with validation attributes
- Service composition patterns