Time and Activity Tracking
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- packages/desktop-lib/src/lib/desktop-timer.ts
- packages/core/src/lib/time-tracking/statistic/statistic.service.ts
- packages/mcp-server/src/lib/schema.ts
- packages/mcp-server/README.md
- apps/gauzy-e2e/src/support/step_definitions/ReportsTest/ReportsTest.ts
- apps/gauzy-e2e/src/integration/TimesheetsTest.ts
- apps/gauzy-e2e/src/integration/TimeTrackingTest.ts
- packages/plugins/integration-upwork/src/lib/upwork.service.ts
- packages/ui-core/i18n/assets/i18n/en.json
The Time and Activity Tracking system is a core feature of the Ever Gauzy platform, designed for employee time-tracking, activity monitoring, and productivity analysis. It combines a desktop application for data capture with a robust backend for data processing, storage, and reporting. This enables detailed insights into how time is spent across various projects and tasks.
Sources: README.md
System Architecture
The system consists of several key components that work together to capture, store, and display time and activity data.
- Ever® Gauzy™ Desktop Timer App: A cross-platform desktop application that employees use to start and stop the timer. It runs in the background to monitor keyboard/mouse activity, track active windows, and capture screenshots at configured intervals.
- Ever® Gauzy™ Server (API): The central backend service that receives data from the Desktop Timer App. It authenticates users, processes incoming data, and stores it in the database. It also serves the data for reports and timesheets displayed in the Web UI.
- Database: Persists all tracking-related data, including time logs, time slots, activities, and screenshots. The system is designed to work with multiple database systems like PostgreSQL and SQLite.
- MCP (Model Context Protocol) Server: A shared package providing a tool-based interface for interacting with the Gauzy API. It includes a
TimerToolfor programmatic control over time tracking. - Ever® Gauzy™ Web UI: The web interface where users, managers, and administrators can view timesheets, detailed activity reports, and dashboard statistics.
Sources: README.md, packages/mcp-server/README.md
The following diagram illustrates the high-level architecture of the time and activity tracking system.
This diagram shows the interaction between the Desktop Timer App, the backend API, the database, and the web UI.
Sources: README.md, packages/desktop-lib/src/lib/desktop-timer.ts, packages/mcp-server/README.md
Data Model
The time tracking data is structured around a few core entities. The relationships between these entities are crucial for aggregating data accurately for reports and timesheets.
This ER diagram shows the primary entities and their relationships in the time tracking data model.
Sources: packages/mcp-server/src/lib/schema.ts
Key Entities
TimeLog
A TimeLog represents a continuous period of work, from when a user starts the timer until they stop it.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier. |
startedAt | datetime | The timestamp when the time log began. |
stoppedAt | datetime | The timestamp when the time log ended. |
logType | enum | Type of log: TRACKED, MANUAL, IDLE, RESUMED. |
source | enum | The source of the time log, e.g., DESKTOP, WEB_TIMER, UPWORK. |
employeeId | string | The ID of the employee who tracked the time. |
projectId | string | The ID of the associated project. |
taskId | string | The ID of the associated task. |
Sources: packages/mcp-server/src/lib/schema.ts:11-19, 436-465
TimeSlot
A TimeLog is broken down into smaller TimeSlot intervals (typically 10 minutes). Each time slot aggregates activity data for that specific period.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier. |
startedAt | datetime | The start time of the 10-minute slot. |
duration | int | The duration of the slot in seconds (e.g., 600). |
keyboard | int | Aggregated keyboard activity score for the slot. |
mouse | int | Aggregated mouse activity score for the slot. |
overall | int | A combined overall activity score. |
employeeId | string | The ID of the employee. |
Sources: packages/mcp-server/src/lib/schema.ts:397-407
Desktop Timer and Activity Collection
The core of the data collection is the TimerHandler class in the desktop application. It manages the timer's state and orchestrates the collection of activity data and screenshots.
Sources: packages/desktop-lib/src/lib/desktop-timer.ts:25
Timer Lifecycle
The process begins when a user starts the timer and ends when they stop it.
This sequence diagram shows the flow of events from starting the timer to collecting and sending activity data.
Sources: packages/desktop-lib/src/lib/desktop-timer.ts:56-88, 273-392
Activity and Screenshot Collection
The TimerHandler collects data periodically. This period can be fixed or randomized based on organization settings.
- Activity Collection: The
collectActivitiesmethod runs on a 1-second interval to update the running timer's duration. - Data Aggregation: At the end of each time slot (e.g., 10 minutes), the
getAllActivitiesmethod is called. It gathers data from multiple sources:ActivityWatchservices: Collects window titles, app usage, and AFK (away from keyboard) time.DesktopEventCounter: IfActivityWatchis not connected, it falls back to counting keyboard and mouse events.- Wakatime Integration: Can pull in coding activity from the Wakatime service if configured.
- Screenshot Capture: The
takeScreenshotActivitiesmethod is triggered. It captures the user's screen using eitherElectronDesktopCaptureror thescreenshot-desktoplibrary. - Payload Creation: A comprehensive payload is created, including the screenshot, aggregated activity data, active window title, and metadata (project ID, task ID, etc.).
- Data Sync: This payload is sent to the Gauzy API to be stored in the database. The system uses an
EmbeddedQueueto handle data synchronization, ensuring that data captured while offline is sent to the server once a connection is re-established.
Sources: packages/desktop-lib/src/lib/desktop-timer.ts:94-150, 273-392, 532-595
Configuration
The behavior of the desktop timer is highly configurable through organization settings.
| Setting | Description |
|---|---|
allowManualTime | Allows employees to add time manually instead of using the timer. |
allowModifyTime | Allows employees to edit their time logs. |
allowDeleteTime | Allows employees to delete their time logs. |
allowScreenshotCapture | Enables or disables the screenshot capturing feature. |
screenshotFrequency | The interval in minutes for taking screenshots (if not random). |
randomScreenshot | If enabled, screenshots are taken at random intervals within the frequency period. |
trackOnSleep | If enabled, the timer continues to run even when the device is in sleep mode. |
Sources: packages/ui-core/i18n/assets/i18n/en.json:1410-1440
Reporting and Statistics
The StatisticService on the backend is responsible for querying the raw data from TimeLog and TimeSlot tables and aggregating it into meaningful statistics for dashboards and reports.
Sources: packages/core/src/lib/time-tracking/statistic/statistic.service.ts
Available Reports
The system provides a variety of reports and dashboard widgets related to time and activity:
- Time and Activity Report: A detailed breakdown of time spent, activity levels, and screenshots.
- Weekly Time and Activity Report: A summary of the week's activities.
- Apps & URLs Report: Shows time spent on different applications and websites.
- Manual Time Edit Report: Logs all manual additions or modifications to time entries.
- Dashboard Widgets:
- Members Worked
- Projects Worked
- Weekly/Today Activity Level
- Worked This Week/Today
- Recent Activities
Sources: apps/gauzy-e2e/src/support/step_definitions/ReportsTest/ReportsTest.ts:43-51, apps/gauzy-e2e/src/integration/TimeTrackingTest.ts:19-30, packages/ui-core/i18n/assets/i18n/en.json:800-840
Data Aggregation Flow
The service generates reports by executing complex database queries.
This flowchart shows the process of generating a report from raw tracked data.
Sources: packages/core/src/lib/time-tracking/statistic/statistic.service.ts
The StatisticService is designed to be database-agnostic, using helper functions like getDurationQueryString to generate SQL compatible with PostgreSQL, MySQL, and SQLite.
Sources: packages/core/src/lib/time-tracking/statistic/statistic.service.ts:50-54
Integrations
The time tracking system can sync data from external platforms. For example, the Upwork integration allows for syncing time logs, contracts (as projects), and work diaries.
The UpworkService contains methods like syncTimeLog and syncTimeSlots which create corresponding Gauzy entities from Upwork data, setting the source field to TimeLogSourceEnum.UPWORK. This allows for a unified view of time tracked across different platforms.
Sources: packages/plugins/integration-upwork/src/lib/upwork.service.ts:251-271, 273-311