A Flask-based web application for tracking and managing employee overtime hours.
- Secure login system with Flask-Login
- Personal dashboard to add and view overtime records
- Track overtime by date, duration (minutes), and description
- View total overtime hours accumulated
- Admin panel to view overtime records for managed groups
- Filter overtime records by:
- Group
- Date range
- View detailed overtime records for individual users
- Delete overtime records for users in managed groups
- Comprehensive logging of all activities
The application logs the following events:
- User login attempts (successful and failed)
- Overtime record creation (with full details)
- Overtime record deletion by admins (with full audit trail)
Logs are stored in logs/app.log by default.
overtime/
├── app.py # Main Flask application
├── models.py # Database models (User, Group, AdminGroup, Overtime)
├── init_db.py # Database initialization script
├── .env # Environment configuration (excluded from git)
├── requirements.txt # Python dependencies
├── logs/ # Application logs directory
│ └── app.log
├── templates/ # HTML templates
│ ├── base.html # Base template with navigation
│ ├── login.html # Login page
│ ├── dashboard.html # User dashboard
│ ├── admin.html # Admin panel
│ └── admin_user_details.html # Detailed user overtime view
├── static/ # Static files (CSS, JS, images)
└── venv/ # Python virtual environment
id: Primary keyusername: Unique usernamepassword_hash: Hashed passworduser_type: 'admin' or 'common'group_id: Foreign key to Group
id: Primary keyname: Group name (e.g., Engineering, Marketing)
id: Primary keyadmin_id: Foreign key to User (admin)group_id: Foreign key to Group- Maps which groups each admin can manage
id: Primary keyuser_id: Foreign key to Userdate: Date of overtime workminutes: Duration in minutesdescription: Work descriptioncreated_at: Record creation timestamp
- Python 3.8 or higher
- MariaDB/MySQL database server
- pip and venv
-
Clone or download the project
-
Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate # On Linux/Mac
# or
venv\Scripts\activate # On Windows- Install dependencies:
pip install -r requirements.txt- Configure environment variables in
.env:
SECRET_KEY=your-secret-key-change-this-in-production
FLASK_ENV=development
DB_HOST=your-database-host
DB_USER=your-database-user
DB_PASSWORD=your-database-password
DB_NAME=your-database-name
DB_PORT=3306
LOG_FILE=logs/app.log
LOG_LEVEL=INFO- Initialize the database:
python init_db.pyWhen prompted, type 'y' to seed test data with sample users and overtime records.
- Run the application:
python app.pyThe application will be available at http://localhost:5000
If you seeded test data, you can login with:
Admin Account:
- Username:
admin - Password:
admin123 - Can manage: Engineering and Marketing groups
User Accounts:
- Username:
john, Password:password123(Engineering) - Username:
jane, Password:password123(Engineering) - Username:
bob, Password:password123(Marketing) - Username:
alice, Password:password123(Sales)
- Login: Navigate to the login page and enter your credentials
- Add Overtime: On your dashboard, fill in the form with:
- Date of overtime work
- Duration in minutes
- Description of work done
- View Records: See all your overtime entries in a table below the form
- Track Total: View your total accumulated overtime hours
- Login with admin credentials
- Access Admin Panel: Click "Admin Panel" in the navigation
- Filter Records: Use filters to view overtime by:
- Specific group
- Date range
- View User Details: Click "View Details" to see individual user's overtime records
- Delete Records: On the user details page, click "Delete" to remove overtime entries (requires confirmation)
- Password hashing with Werkzeug's security utilities
- Session-based authentication with Flask-Login
- Role-based access control (admin vs common users)
- Group-based permissions (admins can only manage assigned groups)
- Comprehensive audit logging for security events
SECRET_KEY: Flask secret key for session managementFLASK_ENV: Application environment (development/production)DB_HOST: Database server hostnameDB_USER: Database usernameDB_PASSWORD: Database passwordDB_NAME: Database nameDB_PORT: Database port (default: 3306)LOG_FILE: Path to log fileLOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
To run in development mode with auto-reload:
export FLASK_ENV=development
python app.pyFor production deployment:
- Change
SECRET_KEYto a strong random value - Set
FLASK_ENV=production - Use a production WSGI server (e.g., Gunicorn, uWSGI)
- Configure proper database backups
- Set up log rotation
- Enable HTTPS
- Configure firewall rules
Example with Gunicorn:
gunicorn -w 4 -b 0.0.0.0:5000 app:app- Verify database credentials in
.env - Ensure database server is running and accessible
- Check firewall rules allow connection to database port
- Check logs in
logs/app.logfor error details - Verify user exists in database
- Ensure password was set correctly during user creation
- Verify admin user has entries in
admin_groupstable - Check user's
user_typeis set to 'admin' - Ensure admin is assigned to the correct groups
This project is provided as-is for educational and internal use.
For issues or questions, please check the logs and database configuration first. The logging system provides detailed information about all operations for troubleshooting.