feat: Implement comprehensive architectural improvements and new features

This commit implements a complete architectural transformation of the TimeTracker
application, introducing modern design patterns and comprehensive feature set.

## Architecture Improvements

### Service Layer (18 Services)
- TimeTrackingService: Time entry management with timer functionality
- ProjectService: Project operations and lifecycle management
- InvoiceService: Invoice creation, management, and status tracking
- TaskService: Task management and workflow
- ExpenseService: Expense tracking and categorization
- ClientService: Client relationship management
- PaymentService: Payment processing and invoice reconciliation
- CommentService: Comment system for projects, tasks, and quotes
- UserService: User management and role operations
- NotificationService: Notification delivery system
- ReportingService: Report generation and analytics
- AnalyticsService: Event tracking and analytics
- ExportService: CSV export functionality
- ImportService: CSV import with validation
- EmailService: Email operations and invoice delivery
- PermissionService: Role-based permission management
- BackupService: Database backup operations
- HealthService: System health checks and monitoring

### Repository Layer (9 Repositories)
- BaseRepository: Generic CRUD operations
- TimeEntryRepository: Time entry data access
- ProjectRepository: Project data access with filtering
- InvoiceRepository: Invoice queries and status management
- TaskRepository: Task data access
- ExpenseRepository: Expense data access
- ClientRepository: Client data access
- UserRepository: User data access
- PaymentRepository: Payment data access
- CommentRepository: Comment data access

### Schema Layer (9 Schemas)
- Marshmallow schemas for validation and serialization
- Create, update, and full schemas for all entities
- Input validation and data transformation

### Utility Modules (15 Utilities)
- api_responses: Standardized API response helpers
- validation: Input validation utilities
- query_optimization: N+1 query prevention and eager loading
- error_handlers: Centralized error handling
- cache: Caching foundation (Redis-ready)
- transactions: Transaction management decorators
- event_bus: Domain event system
- performance: Performance monitoring decorators
- logger: Enhanced structured logging
- pagination: Pagination utilities
- file_upload: Secure file upload handling
- search: Full-text search utilities
- rate_limiting: Rate limiting helpers
- config_manager: Configuration management
- datetime_utils: Enhanced date/time utilities

## Database Improvements
- Performance indexes migration (15+ indexes)
- Query optimization utilities
- N+1 query prevention patterns

## Testing Infrastructure
- Comprehensive test fixtures (conftest.py)
- Service layer unit tests
- Repository layer unit tests
- Integration test examples

## CI/CD Pipeline
- GitHub Actions workflow
- Automated linting (Black, Flake8, Pylint)
- Security scanning (Bandit, Safety, Semgrep)
- Automated testing with coverage
- Docker image builds

## Documentation
- Architecture migration guide
- Quick start guide
- API enhancements documentation
- Implementation summaries
- Refactored route examples

## Key Benefits
- Separation of concerns: Business logic decoupled from routes
- Testability: Services and repositories can be tested in isolation
- Maintainability: Consistent patterns across codebase
- Performance: Database indexes and query optimization
- Security: Input validation and security scanning
- Scalability: Event-driven architecture and health checks

## Statistics
- 70+ new files created
- 8,000+ lines of code
- 18 services, 9 repositories, 9 schemas
- 15 utility modules
- 5 test files with examples

This transformation establishes a solid foundation for future development
and follows industry best practices for maintainable, scalable applications.
This commit is contained in:
Dries Peeters
2025-11-23 20:00:10 +01:00
parent 01b12687ae
commit 9d1ece5263
83 changed files with 12585 additions and 550 deletions
+159
View File
@@ -0,0 +1,159 @@
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: '3.11'
POSTGRES_VERSION: '16'
jobs:
lint:
name: Lint and Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black pylint bandit safety
- name: Run Black (code formatting check)
run: black --check app tests
- name: Run Flake8 (linting)
run: flake8 app tests --max-line-length=120 --extend-ignore=E203,W503
continue-on-error: true
- name: Run Pylint
run: pylint app --disable=all --enable=errors --max-line-length=120
continue-on-error: true
- name: Run Bandit (security linting)
run: bandit -r app -f json -o bandit-report.json
continue-on-error: true
- name: Run Safety (dependency vulnerability check)
run: safety check --json
continue-on-error: true
test:
name: Test Suite
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: timetracker
POSTGRES_PASSWORD: timetracker
POSTGRES_DB: timetracker_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run database migrations
env:
DATABASE_URL: postgresql+psycopg2://timetracker:timetracker@localhost:5432/timetracker_test
run: |
flask db upgrade
- name: Run tests with coverage
env:
DATABASE_URL: postgresql+psycopg2://timetracker:timetracker@localhost:5432/timetracker_test
FLASK_ENV: testing
SECRET_KEY: test-secret-key-for-ci
run: |
pytest --cov=app --cov-report=xml --cov-report=html --cov-report=term tests/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit safety semgrep
- name: Run Bandit security scan
run: bandit -r app -f json -o bandit-report.json
continue-on-error: true
- name: Run Safety dependency check
run: safety check --json
continue-on-error: true
- name: Run Semgrep security scan
run: semgrep --config=auto app/
continue-on-error: true
build:
name: Docker Build
runs-on: ubuntu-latest
needs: [lint, test]
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub (if needed)
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME || '' }}
password: ${{ secrets.DOCKER_PASSWORD || '' }}
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && secrets.DOCKER_USERNAME != ''
continue-on-error: true
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: timetracker:latest
cache-from: type=registry,ref=timetracker:latest
cache-to: type=inline