# rredeemz/timetracker architecture

> Architecture diagram of the GitHub repository rredeemz/timetracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rredeemz/timetracker
- Repository: https://github.com/rredeemz/timetracker

## Overview

#### Purpose and Runtime Entry

TimeTracker is a local-first Flask application for recording employee time against projects, enforcing work/lunch/overtime rules, and exposing separate user and administrator workflows. The process starts at `app.py`, which creates the application through `tracker_app/__init__.py`; configuration, database initialization, and extension setup are centralized under `tracker_app/config.py`, `tracker_app/db.py`, and `tracker_app/extensions.py`.

#### Application Composition

The backend is organized by feature rather than by technical layer. Each feature follows the primary control path: HTTP routes invoke use cases, which invoke repositories for persistence. Shared cross-cutting concerns—authorization decorators, shared validation, and utilities—sit outside feature packages in `tracker_app/decorators.py`, `tracker_app/validation.py`, and `tracker_app/utils.py`.

#### Authentication and Session Boundary

Authentication supports password login, offline TOTP/QR provisioning, two-factor verification, and database-backed trusted-device tokens. The auth HTTP surface and session transitions reside in `tracker_app/auth/routes.py`; authentication policy and workflows are in `tracker_app/auth/use_cases.py`; database access is isolated in `tracker_app/repositories/auth_repository.py`. Templates `templates/login.html` and `templates/verify_2fa.html` are the primary unauthenticated UI entry points.

#### User Time-Tracking Workflow

Authenticated employees create, view, edit, and delete personal time logs through `tracker_app/user/routes.py`. Business rules in `tracker_app/user/use_cases.py` validate time ranges and overlaps, split applicable lunch breaks, handle explicit `PAUSA` entries, and calculate overtime based on work schedules, weekends, and holidays. Persistence is bounded by `tracker_app/repositories/user_repository.py`; user-facing state is rendered by `templates/user_dashboard.html` and partials under `templates/partials/user_dashboard/`.

#### Administrative Workflow

Admin-only routes in `tracker_app/admin/routes.py` provide dashboards, log registers, team administration, project management, reporting/chart data, and CSV export. `tracker_app/admin/use_cases.py` coordinates KPI and management operations, while `tracker_app/repositories/admin_repository.py` owns associated database queries. Main views are `templates/admin_dashboard.html` and `templates/admin_projects.html`, with dynamically targeted sections under `templates/partials/admin_dashboard/` and `templates/partials/admin_projects/`.

#### Data Model and Persistence

Feature-local model definitions—`tracker_app/auth/models.py`, `tracker_app/user/models.py`, and `tracker_app/admin/models.py`—represent domain-facing data used by their routes and use cases. The application uses a SQLite database configured by `DATABASE_URL`; startup creates the database/schema, seeds the configured default admin, and applies additive schema updates. Repository modules are the intended persistence boundary, preventing routes and use cases from directly coupling to database operations.

#### Presentation and Client Interaction

Flask renders a shared shell from `templates/base.html` and feature pages/partials. Dashboard-specific browser behavior is implemented in `static/js/user_dashboard.js`, `static/js/admin_dashboard.js`, and `static/js/admin_projects.js`; these scripts support interactive forms, dashboard updates, and client-side validation while backend validation remains authoritative. External dependencies are Python/Flask runtime libraries, SQLite, Werkzeug password hashing, secure cookies, and standard authenticator applications via TOTP-compatible provisioning.

Main entry points: [`tracker_app/db.py`](https://github.com/rredeemz/timetracker/blob/main/tracker_app/db.py) (SQLite Database), [`tracker_app/auth/routes.py`](https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/routes.py) (Auth Routes), [`tracker_app/user/routes.py`](https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/routes.py) (User Routes), [`tracker_app/admin/routes.py`](https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/routes.py) (Admin Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Application Core"]
  node_entry{{"Process Entry<br/>Flask entry<br/>[app.py]"}}
  node_app_factory["App Factory<br/>application setup<br/>[__init__.py]"]
  node_bootstrap["Config &amp; Database Bootstrap<br/>startup services<br/>[config.py]"]
  node_cross_cutting["Authorization &amp; Validation<br/>shared concerns<br/>[decorators.py]"]
  node_sqlite[("SQLite Database<br/>persistence<br/>[db.py]")]
  node_shared_shell["Shared Page Shell<br/>base template<br/>[base.html]"]
end

subgraph group_auth["Authentication"]
  node_auth_routes["Auth Routes<br/>HTTP surface<br/>[routes.py]"]
  node_auth_use_cases["Auth Workflows<br/>use cases<br/>[use_cases.py]"]
  node_auth_repository["Auth Repository<br/>persistence boundary<br/>[auth_repository.py]"]
  node_auth_models["Auth Models<br/>domain models<br/>[models.py]"]
  node_auth_views["Login &amp; 2FA Views<br/>templates<br/>[login.html]"]
end

subgraph group_user["User Time Tracking"]
  node_user_routes["User Routes<br/>HTTP surface<br/>[routes.py]"]
  node_user_use_cases["Time-Tracking Rules<br/>use cases<br/>[use_cases.py]"]
  node_user_repository["User Repository<br/>persistence boundary<br/>[user_repository.py]"]
  node_user_models["Time Models<br/>domain models<br/>[models.py]"]
  node_user_dashboard["User Dashboard<br/>templates and client UI"]
end

subgraph group_admin["Administration"]
  node_admin_routes["Admin Routes<br/>HTTP surface<br/>[routes.py]"]
  node_admin_use_cases["Admin Operations<br/>use cases<br/>[use_cases.py]"]
  node_admin_repository["Admin Repository<br/>persistence boundary"]
  node_admin_models["Admin Models<br/>domain models<br/>[models.py]"]
  node_admin_dashboard["Admin Dashboard<br/>templates and client UI"]
end

node_entry -->|"creates"| node_app_factory
node_app_factory -->|"initializes"| node_bootstrap
node_bootstrap -->|"creates and updates schema"| node_sqlite
node_auth_routes -.->|"uses authorization"| node_cross_cutting
node_auth_routes -->|"invokes"| node_auth_use_cases
node_auth_use_cases -->|"persists through"| node_auth_repository
node_auth_use_cases -.->|"uses"| node_auth_models
node_auth_repository -->|"queries"| node_sqlite
node_auth_routes -->|"renders"| node_auth_views
node_user_routes -.->|"uses authorization"| node_cross_cutting
node_user_routes -->|"invokes"| node_user_use_cases
node_user_use_cases -->|"persists through"| node_user_repository
node_user_use_cases -.->|"uses"| node_user_models
node_user_repository -->|"queries"| node_sqlite
node_user_routes -->|"renders"| node_user_dashboard
node_admin_routes -.->|"uses authorization"| node_cross_cutting
node_admin_routes -->|"invokes"| node_admin_use_cases
node_admin_use_cases -->|"persists through"| node_admin_repository
node_admin_use_cases -.->|"uses"| node_admin_models
node_admin_repository -->|"queries"| node_sqlite
node_admin_routes -->|"renders"| node_admin_dashboard
node_auth_views -.->|"extends"| node_shared_shell
node_user_dashboard -.->|"extends"| node_shared_shell
node_admin_dashboard -.->|"extends"| node_shared_shell

click node_entry "https://github.com/rredeemz/timetracker/blob/main/app.py"
click node_app_factory "https://github.com/rredeemz/timetracker/blob/main/tracker_app/__init__.py"
click node_bootstrap "https://github.com/rredeemz/timetracker/blob/main/tracker_app/config.py"
click node_cross_cutting "https://github.com/rredeemz/timetracker/blob/main/tracker_app/decorators.py"
click node_sqlite "https://github.com/rredeemz/timetracker/blob/main/tracker_app/db.py"
click node_auth_routes "https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/routes.py"
click node_auth_use_cases "https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/use_cases.py"
click node_auth_repository "https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/auth_repository.py"
click node_auth_models "https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/models.py"
click node_auth_views "https://github.com/rredeemz/timetracker/blob/main/templates/login.html"
click node_user_routes "https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/routes.py"
click node_user_use_cases "https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/use_cases.py"
click node_user_repository "https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/user_repository.py"
click node_user_models "https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/models.py"
click node_user_dashboard "https://github.com/rredeemz/timetracker/blob/main/templates/user_dashboard.html"
click node_admin_routes "https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/routes.py"
click node_admin_use_cases "https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/use_cases.py"
click node_admin_repository "https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/admin_repository.py"
click node_admin_models "https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/models.py"
click node_admin_dashboard "https://github.com/rredeemz/timetracker/blob/main/templates/admin_dashboard.html"
click node_shared_shell "https://github.com/rredeemz/timetracker/blob/main/templates/base.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_app_factory,node_bootstrap,node_cross_cutting,node_sqlite,node_shared_shell toneBlue
class node_auth_routes,node_auth_use_cases,node_auth_repository,node_auth_models,node_auth_views toneAmber
class node_user_routes,node_user_use_cases,node_user_repository,node_user_models,node_user_dashboard toneMint
class node_admin_routes,node_admin_use_cases,node_admin_repository,node_admin_models,node_admin_dashboard toneRose
```

## Components

### Application Core

- [Process Entry](https://github.com/rredeemz/timetracker/blob/main/app.py): Flask entry · `app.py`
- [App Factory](https://github.com/rredeemz/timetracker/blob/main/tracker_app/__init__.py): application setup · Creates the Flask application and wires startup. · `tracker_app/__init__.py`
- [Config & Database Bootstrap](https://github.com/rredeemz/timetracker/blob/main/tracker_app/config.py): startup services · Configures extensions, initializes schema, updates it, and seeds the default admin. · `tracker_app/config.py`
- [Authorization & Validation](https://github.com/rredeemz/timetracker/blob/main/tracker_app/decorators.py): shared concerns · Shared authorization decorators, validation, and utilities. · `tracker_app/decorators.py`
- [SQLite Database](https://github.com/rredeemz/timetracker/blob/main/tracker_app/db.py): persistence · Local database configured through DATABASE_URL. · `tracker_app/db.py`
- [Shared Page Shell](https://github.com/rredeemz/timetracker/blob/main/templates/base.html): base template · `templates/base.html`

### Authentication

- [Auth Routes](https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/routes.py): HTTP surface · Login, 2FA verification, and session transitions. · `tracker_app/auth/routes.py`
- [Auth Workflows](https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/use_cases.py): use cases · Password, TOTP provisioning, and trusted-device policy. · `tracker_app/auth/use_cases.py`
- [Auth Repository](https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/auth_repository.py): persistence boundary · `tracker_app/repositories/auth_repository.py`
- [Auth Models](https://github.com/rredeemz/timetracker/blob/main/tracker_app/auth/models.py): domain models · `tracker_app/auth/models.py`
- [Login & 2FA Views](https://github.com/rredeemz/timetracker/blob/main/templates/login.html): templates · `templates/login.html`

### User Time Tracking

- [User Routes](https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/routes.py): HTTP surface · Personal time-log create, view, edit, and delete endpoints. · `tracker_app/user/routes.py`
- [Time-Tracking Rules](https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/use_cases.py): use cases · Checks overlaps, lunch and PAUSA entries, schedules, holidays, and overtime. · `tracker_app/user/use_cases.py`
- [User Repository](https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/user_repository.py): persistence boundary · `tracker_app/repositories/user_repository.py`
- [Time Models](https://github.com/rredeemz/timetracker/blob/main/tracker_app/user/models.py): domain models · `tracker_app/user/models.py`
- [User Dashboard](https://github.com/rredeemz/timetracker/blob/main/templates/user_dashboard.html): templates and client UI · Dashboard templates, partial updates, and browser interactions. · `templates/user_dashboard.html`

### Administration

- [Admin Routes](https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/routes.py): HTTP surface · Admin dashboard, registers, teams, projects, reporting, and CSV export. · `tracker_app/admin/routes.py`
- [Admin Operations](https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/use_cases.py): use cases · Coordinates KPIs and management operations. · `tracker_app/admin/use_cases.py`
- [Admin Repository](https://github.com/rredeemz/timetracker/blob/main/tracker_app/repositories/admin_repository.py): persistence boundary · `tracker_app/repositories/admin_repository.py`
- [Admin Models](https://github.com/rredeemz/timetracker/blob/main/tracker_app/admin/models.py): domain models · `tracker_app/admin/models.py`
- [Admin Dashboard](https://github.com/rredeemz/timetracker/blob/main/templates/admin_dashboard.html): templates and client UI · Dashboard and project views with targeted partial updates. · `templates/admin_dashboard.html`

## Connections

- Process Entry → App Factory: creates
- App Factory → Config & Database Bootstrap: initializes
- Config & Database Bootstrap → SQLite Database: creates and updates schema
- Auth Routes → Authorization & Validation: uses authorization
- Auth Routes → Auth Workflows: invokes
- Auth Workflows → Auth Repository: persists through
- Auth Workflows → Auth Models: uses
- Auth Repository → SQLite Database: queries
- Auth Routes → Login & 2FA Views: renders
- User Routes → Authorization & Validation: uses authorization
- User Routes → Time-Tracking Rules: invokes
- Time-Tracking Rules → User Repository: persists through
- Time-Tracking Rules → Time Models: uses
- User Repository → SQLite Database: queries
- User Routes → User Dashboard: renders
- Admin Routes → Authorization & Validation: uses authorization
- Admin Routes → Admin Operations: invokes
- Admin Operations → Admin Repository: persists through
- Admin Operations → Admin Models: uses
- Admin Repository → SQLite Database: queries
- Admin Routes → Admin Dashboard: renders
- Login & 2FA Views → Shared Page Shell: extends
- User Dashboard → Shared Page Shell: extends
- Admin Dashboard → Shared Page Shell: extends
