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.
- 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
- 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
- Versioned API:
/api/v1endpoints 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
- Timestamp Mixin: Automatic
created_at/updated_aton 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
- 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
- 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
- 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
- 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
pip install -r requirements.txtCopy and customize .env.example to .env:
cp .env.example .envEdit .env with your settings:
FLASK_ENV=development
DATABASE_URL=sqlite:///attendance.db
SECRET_KEY=your-secret-key-here-32chars
flask init-dbOr seed with sample data:
flask seed-dbflask create-admin --username admin --password admin123 --email admin@example.comDevelopment:
python app.pyProduction:
gunicorn -w 4 -b 0.0.0.0:5000 wsgi:appApplication will be available at http://localhost:5000
- Navigate to
http://localhost:5000 - Click "Admin Login"
- Enter your admin credentials
- 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
- Navigate to
http://localhost:5000 - Click "Employee Login"
- Enter your Employee ID and password
- From dashboard:
- View Statistics: See attendance overview
- Check History: Search attendance records by date
- Download Reports: Export personal attendance data
Get System Health:
curl http://localhost:5000/api/v1/healthGet Attendance Summary:
curl http://localhost:5000/api/v1/attendance/check?date=2024-01-15Export Attendance:
curl http://localhost:5000/api/v1/attendance/export?start=2024-01-01&end=2024-01-31List All Employees:
curl http://localhost:5000/api/v1/employees
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)
FLASK_ENV = 'development'
DEBUG = True
TESTING = False
DATABASE_URL = 'sqlite:///attendance.db'FLASK_ENV = 'production'
DEBUG = False
DATABASE_URL = 'postgresql://user:pass@host/dbname'
TALISMAN_FORCE_HTTPS = TrueSee config.py for complete configuration options.
Comprehensive documentation is available:
- SETUP_GUIDE.md: Complete installation and troubleshooting
- ARCHITECTURE.md: System design, patterns, and database schema
- COMPLETE_UPGRADE_SUMMARY.md: All changes and improvements from upgrade
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
Run tests:
pytest tests/With coverage:
pytest --cov=. tests/Lint code:
flake8 app.py models.py config.py
black app.py models.py config.pyFor 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,LeaveSupported statuses: Present, Absent, Leave, Half-day, Work From Home
# Reset database
flask init-db --reset
# Check database
sqlite3 attendance.db ".tables"# Use different port
python -m flask run --port 5001pip install --upgrade -r requirements.txtSee SETUP_GUIDE.md for detailed troubleshooting.
| 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 |
This project is part of an enterprise attendance management solution.
For issues or questions:
- Check SETUP_GUIDE.md
- Review ARCHITECTURE.md
- Check application logs in
logs/directory
β¨ Latest Version: 2.0 (Production-Ready Enterprise Architecture)
π
Last Updated: 2024
π― Stability: Production-Ready
π Security Level: Enterprise-Grade
- Go to Admin Dashboard
- Click "Create Employee" card
- Enter:
- Employee ID (e.g., EMP001)
- Employee Name
- Password
- Click "Create Employee"
- Go to Admin Dashboard
- Click "Upload Attendance" card
- Prepare a CSV file with columns:
employee_id, date, status - 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
- Click "Employee Login" on home page
- Enter your Employee ID and Password
- View your attendance statistics and records
- Click "History" to see detailed records
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
id: Primary keyemployee_id: Unique employee identifier (e.g., EMP001)name: Employee full namepassword: Hashed passwordcreated_at: Account creation timestamp
id: Primary keyemployee_id: Foreign key linking to Employeedate: Attendance datestatus: Present/Absent/Leavecreated_at: Record creation timestamp
id: Primary keyusername: Usernamepassword: Hashed password
- 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
- 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
- Username:
admin - Password:
admin123
Edit app.py and modify the line where the default admin is created:
admin = Admin(username='admin', password=generate_password_hash('your_new_password'))In app.py, update:
app.config['SECRET_KEY'] = 'your-complex-secret-key-here'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
Change the port in app.py:
app.run(debug=True, host='0.0.0.0', port=5001) # Use different portDelete attendance.db and restart the app to reset the database.
Clear your browser cookies and login again.
/- 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
For questions or issues, please check:
- Ensure Flask and dependencies are installed
- Check database permissions
- Verify CSV format for uploads
- Clear browser cache if UI issues occur
This project is open-source and available for educational and commercial use.
Happy Attendance Tracking! πβ