How rredeemz/timetracker works
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: db.py SQLite Database · auth/routes.py Auth Routes · user/routes.py User Routes · admin/routes.py Admin Routes
Components 21
Application Core
- Process Entry
app.py - App Factory · Creates the Flask application and wires startup.
tracker_app/__init__.py - Config & Database Bootstrap · Configures extensions, initializes schema, updates it, and seeds the default admin.
tracker_app/config.py - Authorization & Validation · Shared authorization decorators, validation, and utilities.
tracker_app/decorators.py - SQLite Database · Local database configured through DATABASE_URL.
tracker_app/db.py - Shared Page Shell
templates/base.html
Authentication
- Auth Routes · Login, 2FA verification, and session transitions.
tracker_app/auth/routes.py - Auth Workflows · Password, TOTP provisioning, and trusted-device policy.
tracker_app/auth/use_cases.py - Auth Repository
tracker_app/repositories/auth_repository.py - Auth Models
tracker_app/auth/models.py - Login & 2FA Views
templates/login.html
User Time Tracking
- User Routes · Personal time-log create, view, edit, and delete endpoints.
tracker_app/user/routes.py - Time-Tracking Rules · Checks overlaps, lunch and PAUSA entries, schedules, holidays, and overtime.
tracker_app/user/use_cases.py - User Repository
tracker_app/repositories/user_repository.py - Time Models
tracker_app/user/models.py - User Dashboard · Dashboard templates, partial updates, and browser interactions.
templates/user_dashboard.html
Administration
- Admin Routes · Admin dashboard, registers, teams, projects, reporting, and CSV export.
tracker_app/admin/routes.py - Admin Operations · Coordinates KPIs and management operations.
tracker_app/admin/use_cases.py - Admin Repository
tracker_app/repositories/admin_repository.py - Admin Models
tracker_app/admin/models.py - Admin Dashboard · Dashboard and project views with targeted partial updates.
templates/admin_dashboard.html
Connections 24
- 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