Getting Started
Relevant source files
The following files were used as context for generating this wiki page:This guide provides all the necessary steps to set up, configure, and run the Smart Absen Face Recognition system locally. The project is a Flask-based web application that uses InsightFace/ArcFace for high-accuracy face recognition, coupled with a QR code system for cross-device synchronization. The backend is powered by Python and connects to a MySQL database.
Following this guide will result in a fully functional local instance of the application, ready for development or testing. For more detailed information on specific features, refer to the Usage Guide or the Security Documentation.
Sources: README.md:3-5, README.md:70-76
Prerequisites
Before starting the installation, ensure your development environment meets the following requirements.
| Requirement | How to Check |
|---|---|
| Python 3.8+ | python --version |
| pip | pip --version |
| MySQL Server 8.0+ | mysql --version |
| Git | git --version |
| Webcam | Check Device Manager / System Settings |
Sources: INSTALLATION.md:18-27, CONTRIBUTING.md:21-25
Installation and Setup
This section walks through the complete process of setting up the project, from cloning the repository to running the application.
The following diagram illustrates the overall setup flow.
Sources: INSTALLATION.md, README.md:29-42
1. Clone the Repository
Clone the project from GitHub to your local machine.
git clone https://github.com/Fahri-Hilm/Smart_Absen_Facerecognation-2025-Kelompok4.git
cd Smart_Absen_Facerecognation-2025-Kelompok4
Sources: README.md:30-31, INSTALLATION.md:70-74
2. Set Up a Python Virtual Environment
It is highly recommended to use a virtual environment to isolate project dependencies.
Create the environment:
python -m venv .venv
Activate the environment:
- Linux/macOS:
source .venv/bin/activate - Windows (Command Prompt):
.venv\Scripts\activate
Sources: INSTALLATION.md:91-110, CONTRIBUTING.md:33-34
3. Install Dependencies
Install all required Python packages using the requirements.txt file.
pip install -r requirements.txt
Key dependencies include:
| Package | Version | Purpose |
|---|---|---|
| Flask | ≥2.0.0 | Web framework |
| PyMySQL | ≥1.0.0 | MySQL database driver |
| opencv-python | ≥4.5.0 | Face detection and camera handling |
| insightface | ≥0.7.0 | High-accuracy face recognition model |
| onnxruntime | ≥1.10.0 | Runtime for the InsightFace model |
| scikit-learn | - | Used in the initial version for KNN classification |
| python-dotenv | - | Manages environment variables from the .env file |
Sources: requirements.txt, INSTALLATION.md:126-140, SECURITY.md:65-71
4. Configure the Database
The application requires a MySQL database.
1. Create the Database:
Log in to your MySQL server and run the following SQL command:
CREATE DATABASE absensi_karyawan_db;
2. Database Schema:
The application will automatically create the necessary tables upon first run. The schema defines the relationships between employees, their attendance records, and administrators.
This diagram shows the entity relationships for the core tables.
5. Configure the Application
Application and database configurations are managed via an .env file for security.
1. Create the .env file:
Copy the example file to create your local configuration.
cp .env.example .env
2. Edit the .env file:
Update the file with your specific database credentials and a new secret key.
# Database
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=absensi_karyawan_db
# App
SECRET_KEY=your-secret-key
FLASK_ENV=production
PORT=5001
# ML Config
FACE_CONFIDENCE=0.6
MAX_FACES=1
You can generate a secure SECRET_KEY with the following command:
python -c "import secrets; print(secrets.token_hex(32))"
Sources: README.md:79-93, CONTRIBUTING.md:55-62, SECURITY.md:13-16, INSTALLATION.md:189-196
6. Initialize and Run the Application
1. Initialize Database Tables:
The application automatically creates the required tables when it starts for the first time. This is handled by functions within database.py that are called from app.py.
2. Run the Application:
You can start the application using either the Python command or the provided shell script.
- Directly with Python:
python app.py - Using the start script (Linux/macOS):
chmod +x start.sh ./start.sh
After running, the application will be accessible at http://localhost:5001.
Sources: README.md:40-42, INSTALLATION.md:210-226
Project Structure
The project follows a modular structure to separate concerns, making it more maintainable.
Smart_Absen/
├── app.py # Main application entry point
├── config.py # Configuration loader
├── database.py # Database initialization & connection
├── models.py # Data models
├── helpers.py # API response helpers
├── validators.py # Input validation decorators
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
│
├── templates/ # HTML templates
│ ├── base.html # Base template for inheritance
│ └── admin/ # Admin panel templates
│
├── static/ # Static assets (CSS, JS, images)
│
└── docs/ # Project documentation
Sources: CONTRIBUTING.md:65-90, CLEANUP_REPORT.md:80-98
Basic Usage Flow
The primary user flow involves a two-device authentication process for security and convenience.
- QR Page (Laptop): A user navigates to
/authon a primary device (e.g., a kiosk laptop), which displays a unique QR code. - Scan QR (Phone): The employee scans the QR code with their personal device (e.g., a smartphone).
- Authentication: The scan authenticates the session, and the primary device is automatically redirected to the attendance page (
/web_attendance). - Face Scan (Laptop): The employee faces the camera on the primary device for face detection and recognition.
- Submit Attendance: The system verifies the identity and records the attendance in the database.
This sequence diagram shows the cross-device QR synchronization.
Sources: USAGE.md:32-132
Administration
The system includes a comprehensive admin panel for managing employees, viewing attendance records, and generating reports.
- Admin Login:
http://localhost:5001/admin/login - Default Credentials:
| Username | Password | Role |
|---|---|---|
admin | admin123 | Admin |
Sources: USAGE.md:135-147, USAGE.md:23-28