Skip to content

Rbdigital-01/Rbdigital

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‹ Enterprise Attendance Management System

Production-Ready Enterprise Architecture | REST API | Advanced Security | Audit Logging | Multi-Environment Support

A complete enterprise-grade web-based attendance management system built with Flask 3.0, SQLAlchemy 2.0, Blueprint Architecture, and RESTful API. Employees can view their attendance records, admins can manage employees and upload attendance data via CSV, and external systems can integrate programmatically via REST API.

✨ Key Improvements (Latest Major Upgrade)

πŸ—οΈ Architecture Modernization

  • Factory Pattern: Multi-environment configuration (Development/Production/Testing)
  • Blueprint Architecture: Modular code organization (auth, admin, employee, api blueprints)
  • SQLAlchemy 2.0: Advanced ORM with type hints and performance optimizations
  • Production-Ready: Gunicorn WSGI entry point, security headers, rate limiting

πŸ”’ Security Enhancements

  • Talisman Integration: Security headers (HSTS, X-Frame-Options, Content Security Policy)
  • Rate Limiting: 5 requests/minute on auth endpoints, 200/day global limit
  • Audit Logging: Complete change history with JSON diffs and IP tracking
  • Enhanced Validation: Comprehensive input validation and sanitization
  • CSRF Protection: Ready for deployment with proper middleware

πŸ”Œ REST API (New)

  • Versioned API: /api/v1 endpoints for external integrations
  • 6 Core Endpoints: Health check, attendance check, export, statistics, employee list
  • JSON Serialization: Consistent API responses with proper error codes
  • Rate Limited: Dedicated rate limiting for API endpoints

πŸ“Š Advanced Database Features

  • Timestamp Mixin: Automatic created_at/updated_at on all models
  • Audit Trail: AuditLog model tracking all changes with who/what/when/where
  • Indexes: Performance-optimized database queries (employee_id, date, status)
  • Constraints: Unique constraints prevent duplicate attendance entries
  • Dynamic Timestamps: check_in/check_out support for precise tracking

πŸ“ Developer Experience

  • CLI Commands: flask init-db, flask seed-db, flask create-admin
  • Comprehensive Logging: Dual file/console logging with timestamp and levels
  • Error Handlers: Dedicated handlers for 400, 403, 404, 429, 500 errors
  • Context Processors: Thread-safe template variables

🎯 Core Features

For Admins πŸ‘¨β€πŸ’Ό

  • Admin Dashboard: Overview with key statistics and quick actions
  • Employee Management: Create, update, and manage employee accounts
  • Bulk Upload: CSV file upload for batch attendance records
  • Attendance View: Filter and view all employee attendance with date ranges
  • Department Management: Organize employees by department and designation
  • Audit Trail: See who changed what and when

For Employees πŸ‘¨β€πŸ’»

  • Personal Dashboard: Attendance statistics and summary
  • Attendance History: Detailed view with filtering by date/status
  • Profile Management: View and update personal information
  • Privacy: Each employee can only see their own records

For External Systems πŸ”Œ

  • REST API: Programmatic access to all system data
  • Attendance Export: Download attendance in JSON format
  • Employee Directory: Query employee information
  • Statistics API: Access system-wide attendance statistics
  • Health Endpoint: Monitor system status

πŸš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Configure Environment

Copy and customize .env.example to .env:

cp .env.example .env

Edit .env with your settings:

FLASK_ENV=development
DATABASE_URL=sqlite:///attendance.db
SECRET_KEY=your-secret-key-here-32chars

3. Initialize Database

flask init-db

Or seed with sample data:

flask seed-db

4. Create Admin Account

flask create-admin --username admin --password admin123 --email admin@example.com

5. Run the Application

Development:

python app.py

Production:

gunicorn -w 4 -b 0.0.0.0:5000 wsgi:app

Application will be available at http://localhost:5000

πŸ“± Usage Guide

Admin Workflow

  1. Navigate to http://localhost:5000
  2. Click "Admin Login"
  3. Enter your admin credentials
  4. From dashboard:
    • Create Employees: Add new staff members with basic info
    • Upload Attendance: Use CSV file with format: Employee ID, Date, Status
    • View Records: Search and filter attendance history
    • View Audit: Monitor all system changes

Employee Workflow

  1. Navigate to http://localhost:5000
  2. Click "Employee Login"
  3. Enter your Employee ID and password
  4. From dashboard:
    • View Statistics: See attendance overview
    • Check History: Search attendance records by date
    • Download Reports: Export personal attendance data

REST API Usage

Get System Health:

curl http://localhost:5000/api/v1/health

Get Attendance Summary:

curl http://localhost:5000/api/v1/attendance/check?date=2024-01-15

Export Attendance:

curl http://localhost:5000/api/v1/attendance/export?start=2024-01-01&end=2024-01-31

List All Employees:

curl http://localhost:5000/api/v1/employees

πŸ“¦ Project Structure

attendance-system/
β”œβ”€β”€ app.py                    # Application factory & main entry point
β”œβ”€β”€ wsgi.py                   # Production WSGI entry point
β”œβ”€β”€ config.py                 # Multi-environment configuration
β”œβ”€β”€ models.py                 # SQLAlchemy database models
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ .env.example              # Environment variables template
β”‚
β”œβ”€β”€ routes/                   # API route blueprints
β”‚   β”œβ”€β”€ auth.py              # Authentication (login/logout)
β”‚   β”œβ”€β”€ admin.py             # Admin features
β”‚   β”œβ”€β”€ employee.py          # Employee portal
β”‚   └── api.py               # REST API endpoints
β”‚
β”œβ”€β”€ utils/                    # Utility functions
β”‚   └── validators.py        # Input validation
β”‚
β”œβ”€β”€ templates/               # HTML templates
β”‚   β”œβ”€β”€ base.html            # Base template
β”‚   β”œβ”€β”€ admin_login.html     # Admin login
β”‚   β”œβ”€β”€ employee_login.html  # Employee login
β”‚   β”œβ”€β”€ admin_dashboard.html # Admin interface
β”‚   β”œβ”€β”€ employee_dashboard.html
β”‚   └── errors/              # Error pages
β”‚       β”œβ”€β”€ 400.html, 403.html, 404.html, 429.html, 500.html
β”‚
└── database/                # Database files
    └── attendance.db        # SQLite database (auto-created)

πŸ”§ Configuration

Development Environment

FLASK_ENV = 'development'
DEBUG = True
TESTING = False
DATABASE_URL = 'sqlite:///attendance.db'

Production Environment

FLASK_ENV = 'production'
DEBUG = False
DATABASE_URL = 'postgresql://user:pass@host/dbname'
TALISMAN_FORCE_HTTPS = True

See config.py for complete configuration options.

πŸ“š Documentation

Comprehensive documentation is available:

πŸ” Security

This system implements enterprise-level security:

βœ… Password Hashing: Werkzeug secure hashing
βœ… Session Security: HttpOnly, SameSite, Secure flags
βœ… Rate Limiting: DDoS protection per endpoint
βœ… CSRF Protection: Token validation on all forms
βœ… Security Headers: HSTS, CSP, X-Frame-Options via Talisman
βœ… Audit Logging: Complete change history tracking
βœ… Input Validation: Comprehensive validation on all inputs

πŸ§ͺ Testing

Run tests:

pytest tests/

With coverage:

pytest --cov=. tests/

Lint code:

flake8 app.py models.py config.py
black app.py models.py config.py

πŸ“‹ CSV Import Format

For attendance bulk upload, use this CSV format:

employee_id,date,status
EMP001,2024-01-15,Present
EMP002,2024-01-15,Absent
EMP003,2024-01-15,Leave

Supported statuses: Present, Absent, Leave, Half-day, Work From Home

πŸ› Troubleshooting

Database Issues

# Reset database
flask init-db --reset

# Check database
sqlite3 attendance.db ".tables"

Port Already in Use

# Use different port
python -m flask run --port 5001

Missing Dependencies

pip install --upgrade -r requirements.txt

See SETUP_GUIDE.md for detailed troubleshooting.

πŸ“Š Technology Stack

Component Version Purpose
Flask 3.0.0 Web Framework
SQLAlchemy 2.0.23 ORM
Werkzeug 3.0.1 Security
Flask-Limiter 3.5.0 Rate Limiting
Flask-Talisman 1.1.0 Security Headers
Gunicorn 21.2.0 WSGI Server

πŸ“„ License

This project is part of an enterprise attendance management solution.

🀝 Support

For issues or questions:

  1. Check SETUP_GUIDE.md
  2. Review ARCHITECTURE.md
  3. Check application logs in logs/ directory

βœ… Status

✨ Latest Version: 2.0 (Production-Ready Enterprise Architecture)
πŸ“… Last Updated: 2024
🎯 Stability: Production-Ready
πŸ”’ Security Level: Enterprise-Grade

Admin Tasks

Create New Employee

  1. Go to Admin Dashboard
  2. Click "Create Employee" card
  3. Enter:
    • Employee ID (e.g., EMP001)
    • Employee Name
    • Password
  4. Click "Create Employee"

Upload Attendance (CSV)

  1. Go to Admin Dashboard
  2. Click "Upload Attendance" card
  3. Prepare a CSV file with columns: employee_id, date, status
  4. Upload the file

CSV Format Example:

employee_id,date,status
EMP001,2024-03-30,Present
EMP002,2024-03-30,Absent
EMP003,2024-03-30,Leave
EMP001,2024-03-29,Present

Employee Tasks

Login & View Records

  1. Click "Employee Login" on home page
  2. Enter your Employee ID and Password
  3. View your attendance statistics and records
  4. Click "History" to see detailed records

πŸ“ Project Structure

attendance-system/
β”œβ”€β”€ app.py                      # Main Flask application
β”œβ”€β”€ requirements.txt            # Dependencies
β”œβ”€β”€ attendance.db              # SQLite database (auto-created)
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html             # Base template with navigation
β”‚   β”œβ”€β”€ login_choice.html      # Home page - choose admin/employee
β”‚   β”œβ”€β”€ admin_login.html       # Admin login page
β”‚   β”œβ”€β”€ admin_dashboard.html   # Admin dashboard
β”‚   β”œβ”€β”€ create_employee.html   # Employee creation form
β”‚   β”œβ”€β”€ upload_attendance.html # CSV upload form
β”‚   β”œβ”€β”€ employee_login.html    # Employee login page
β”‚   β”œβ”€β”€ employee_dashboard.html# Employee dashboard
β”‚   β”œβ”€β”€ attendance_history.html# Detailed attendance
β”‚   β”œβ”€β”€ view_all_attendance.html# All records view
β”‚   β”œβ”€β”€ 404.html               # 404 error page
β”‚   └── 500.html               # 500 error page
└── uploads/                   # Directory for uploaded CSV files

πŸ—„οΈ Database Models

Employee

  • id: Primary key
  • employee_id: Unique employee identifier (e.g., EMP001)
  • name: Employee full name
  • password: Hashed password
  • created_at: Account creation timestamp

Attendance

  • id: Primary key
  • employee_id: Foreign key linking to Employee
  • date: Attendance date
  • status: Present/Absent/Leave
  • created_at: Record creation timestamp

Admin

  • id: Primary key
  • username: Username
  • password: Hashed password

πŸ” Security Features

  • Password Hashing: All passwords are hashed using Werkzeug
  • Session Management: Secure session handling with Flask
  • Access Control: Role-based access (admin vs employee)
  • Data Privacy: Employees can only see their own records
  • CSRF Protection: Can be enabled with Flask-WTF

🎨 UI Features

  • Bootstrap 5: Responsive design
  • Gradient Background: Modern styling
  • Emoji Icons: User-friendly interface
  • Statistics Cards: Quick overview of attendance
  • Responsive Tables: Mobile-friendly data display
  • Flash Messages: User feedback for actions

πŸ“ Default Admin Credentials

  • Username: admin
  • Password: admin123

⚠️ IMPORTANT: Change these credentials in production!

πŸ”§ Customization

Change Admin Password

Edit app.py and modify the line where the default admin is created:

admin = Admin(username='admin', password=generate_password_hash('your_new_password'))

Change Secret Key

In app.py, update:

app.config['SECRET_KEY'] = 'your-complex-secret-key-here'

πŸ“‹ CSV Upload Template

Download or create a CSV file with this format:

employee_id,date,status
EMP001,2024-03-30,Present
EMP002,2024-03-30,Absent
EMP003,2024-03-30,Leave

Status Options: Present, Absent, Leave

πŸ› Troubleshooting

Port Already in Use

Change the port in app.py:

app.run(debug=True, host='0.0.0.0', port=5001)  # Use different port

Database Issues

Delete attendance.db and restart the app to reset the database.

Session Issues

Clear your browser cookies and login again.

πŸ“– API Endpoints

  • / - Home page
  • /admin_login - Admin login
  • /employee_login - Employee login
  • /admin_dashboard - Admin dashboard
  • /create_employee - Create new employee
  • /upload_attendance - Upload CSV
  • /view_all_attendance - View all records
  • /employee_dashboard - Employee dashboard
  • /attendance_history - Detailed history
  • /logout - Logout user

πŸ“ž Support

For questions or issues, please check:

  1. Ensure Flask and dependencies are installed
  2. Check database permissions
  3. Verify CSV format for uploads
  4. Clear browser cache if UI issues occur

πŸ“„ License

This project is open-source and available for educational and commercial use.


Happy Attendance Tracking! πŸ“Šβœ…

About

Attendance tracking system

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages