Electrician Log MVP is a full-stack web app for tracking electrical work on floor plans.
It uses a Flask backend, a modular browser frontend (Vue via CDN), OpenSeadragon for map viewing, JWT auth, role-based dashboards, real-time updates, and offline mutation queueing.
- JWT authentication with role-based access (
worker,supervisor,admin) - Project-based workflow (projects, floor plans, worker assignment to projects)
- Interactive floor map with work log markers
- Critical sector management
- Work assignments and notifications
- Role dashboards (
worker_dashboard,supervisor_dashboard,admin_dashboard) - Tile generation and tile serving for floor plans
- Real-time updates via WebSocket (
/ws) - Offline mutation queue + background sync service worker for unstable connections
- Project delete + backup ZIP and restore from backup ZIP
- Backend: Flask, Flask-CORS, Flask-Sock, SQLite, PyJWT, bcrypt
- Image/tiles: pyvips, Pillow, pdf2image
- Frontend: Vue 3 (CDN), OpenSeadragon, Tailwind CSS, Chart.js
- Tests: pytest
backend/
run.py
run_migrations.py
requirements.txt
app/
__init__.py
config.py
api/
auth/
projects/
floors/
work_logs/
critical_sectors/
assignments/
notifications/
dashboard/
tiles/
realtime/
__init__.py
services/
models/
database/
utils/
tests/
utils/
setup_admin.py
user_manager.py
tile_generator_safe.py
regenerate_tiles_safe.py
regenerate_all_tiles_hd.py
frontend/
login.html
index.html
worker_dashboard.html
supervisor_dashboard.html
admin_dashboard.html
app-openseadragon.js
auth.js
sw-offline-sync.js
core/
api/
realtime/
offline/
utils/
map/
components/
css/
cd backend
pip install -r requirements.txtpython run_migrations.pypython utils/setup_admin.pypython run.pyApp runs at http://localhost:5000.
The backend also serves frontend files, so use:
Main backend config is in backend/app/config.py.
Useful environment variables:
FLASK_ENV(development/production/testing)SECRET_KEYDATABASE_PATHFLOOR_PLANS_DIRPROJECT_BACKUPS_DIRCORS_ORIGINS(comma-separated)JWT_EXPIRATION_HOURS- Tile settings:
TILES_DIRECTORY,TILE_SIZE,TILE_OVERLAP,TILE_DPI,TILE_PNG_COMPRESS_LEVEL,TILE_MAX_LEVEL
Frontend base API URL is defined in frontend/config/app.config.js (api.baseUrl).
Base URL: http://localhost:5000/api
/auth- login, logout, verify, refresh, profile, users, password management/projects- CRUD, worker assignment, restore backup, delete with backup/floors- CRUD, upload, summaries/statistics/activity/work-logs- CRUD, dashboard, export, spatial helpers, bulk update/critical-sectors- CRUD + statistics/check/export/bulk update/assignments- CRUD + status/statistics/worker queries/bulk create/notifications- list/read/read-all/clear/statistics/dashboard- supervisor dashboard aggregates/tiles- generate/regenerate/status/clear/list/serve/batch
- WebSocket endpoint:
/ws - Authenticated via JWT token in query string (
?token=...) - Frontend client:
frontend/core/realtime/ws-client.js - Backend broadcast hub:
backend/app/realtime/__init__.py
- Offline queue stores mutation requests (POST/PUT/PATCH/DELETE) in IndexedDB
- Queue replays when API is reachable again
- Background Sync integration via
frontend/sw-offline-sync.js - Core module:
frontend/core/offline/offline-queue.js
worker: creates/updates own work logs, sees worker dashboardsupervisor: project/floor operations, assignments, critical sectors, supervision dashboardsadmin: full access, administration dashboard and management actions
Run tests:
cd backend
python -m pytest tests/Current test files:
backend/tests/test_auth.pybackend/tests/test_project_delete_backup.py
Create/manage users:
cd backend
python utils/user_manager.pyRegenerate tiles:
cd backend
python utils/regenerate_tiles_safe.py
python utils/regenerate_all_tiles_hd.py- The repository may contain additional planning docs like
PLAN.mdandPROBLEMOVI.md. - This README is intentionally focused on implemented architecture and practical setup/use.
MIT
A professional web application for tracking electrician work logs across multiple floors of a building using high-performance OpenSeadragon tile-based floor plan visualization with JWT authentication and role-based access control.
- ๐ JWT Authentication - Secure user authentication with role-based access (Worker, Supervisor, Admin)
- ๐บ๏ธ OpenSeadragon Integration - High-performance tile-based floor plan viewing with zoom and pan
- ๐ Interactive Floor Plans - Click to place work markers with visual feedback
โ ๏ธ Critical Sectors - Define and manage critical areas on floor plans (Supervisor/Admin)- ๐ Role-Based Dashboards - Customized views for Workers, Supervisors, and Admins
- ๐ Date Navigation - Filter and navigate work logs by date with keyboard shortcuts
- ๐จ Dark Theme - Modern dark UI with golden accents
- ๐พ SQLite Database - Lightweight and portable database
- ๐ฑ Responsive Design - Works on desktop, tablet, and mobile devices
The backend follows a clean architecture pattern with separation of concerns:
backend/
โโโ run.py # Application entry point (NEW)
โโโ run_migrations.py # Database migration runner
โโโ requirements.txt # Python dependencies
โโโ database.db # SQLite database (auto-created)
โโโ app/ # Main application package
โ โโโ __init__.py # Flask app factory
โ โโโ config.py # Configuration management
โ โโโ api/ # API route blueprints
โ โ โโโ auth/ # Authentication routes
โ โ โโโ work_logs/ # Work log routes
โ โ โโโ floors/ # Floor routes
โ โ โโโ critical_sectors/ # Critical sector routes
โ โ โโโ assignments/ # Work assignment routes
โ โ โโโ dashboard/ # Supervisor stats (uses DashboardService)
โ โ โโโ notifications/ # Notification routes
โ โ โโโ tiles/ # Tile generation routes
โ โโโ services/ # Business logic layer
โ โ โโโ auth_service.py
โ โ โโโ work_log_service.py
โ โ โโโ floor_service.py
โ โ โโโ dashboard_service.py # Supervisor stats
โ โ โโโ ...
โ โโโ models/ # Data models
โ โ โโโ user.py
โ โ โโโ work_log.py
โ โ โโโ floor.py
โ โ โโโ ...
โ โโโ database/ # Database management
โ โ โโโ connection.py
โ โ โโโ migrations.py
โ โโโ utils/ # Utilities
โ โโโ decorators.py # Auth decorators (_extract_and_validate_token)
โ โโโ result.py # ServiceResult dataclass
โ โโโ validators.py
โ โโโ helpers.py
โโโ utils/ # CLI utilities
โ โโโ user_manager.py # User management CLI
โ โโโ setup_admin.py # Admin setup script
โ โโโ tile_generator_safe.py # Tile generation utility
โโโ tiles/ # Generated DZI tiles
โโโ floor-1/
โโโ floor-2/
โโโ ...
The frontend uses Vue.js 3 with a service-oriented architecture:
frontend/
โโโ index.html # Main application (OpenSeadragon)
โโโ login.html # Login page
โโโ worker_dashboard.html # Worker dashboard
โโโ supervisor_dashboard.html # Supervisor dashboard
โโโ app-openseadragon.js # Main Vue.js app (uses MarkerManager)
โโโ auth.js # Authentication manager
โโโ login.js # Login page logic
โโโ theme.js # Theme switcher
โโโ theme.css # Theme styles
โโโ config/
โ โโโ app.config.js # Frontend configuration
โโโ core/
โ โโโ api/ # API service layer
โ โ โโโ api.client.js # HTTP client with auth
โ โ โโโ auth.service.js # Auth API calls
โ โ โโโ workLogs.service.js
โ โ โโโ floors.service.js
โ โ โโโ tiles.service.js
โ โ โโโ criticalSectors.service.js
โ โโโ utils/ # Utility functions
โ โโโ date.utils.js
โ โโโ format.utils.js
โโโ css/
โ โโโ dashboard-shared.css # Shared dashboard styles
โโโ map/
โ โโโ marker-manager.js # OpenSeadragon marker handling
โโโ components/
โโโ critical-sector-drawer.js
โโโ dashboard-components.js # StatCard, shared components
โโโ sector-integration-methods.js
- Python 3.7+ installed
- Modern web browser (Chrome, Firefox, Safari, Edge)
- pip package manager
-
Clone or download the repository
-
Install Python dependencies:
cd backend
pip install -r requirements.txt- Set up the database and create an admin user:
# Run database migrations
python run_migrations.py
# Create admin user (interactive)
python utils/setup_admin.py- Start the backend server:
cd backend
python run.pyThe server will start on http://localhost:5000
You should see:
============================================================
๐๏ธ Electrician Log MVP - Refactored Architecture
Environment: development
Database: database.db
============================================================
Available API endpoints:
Authentication:
POST /api/auth/login - User login
POST /api/auth/logout - User logout
GET /api/auth/verify - Verify token
POST /api/auth/refresh - Refresh token
Work Logs:
GET /api/work-logs - Get work logs
POST /api/work-logs - Create work log
PUT /api/work-logs/<id> - Update work log
DELETE /api/work-logs/<id> - Delete work log
Critical Sectors:
GET /api/critical-sectors - Get critical sectors
POST /api/critical-sectors - Create critical sector
Tiles:
POST /api/tiles/generate/<floor_id> - Generate tiles
GET /api/tiles/status/<floor_id> - Check tile status
============================================================
๐ Authentication enabled!
๐ Modular architecture active!
============================================================
-
Open the frontend:
- Open
frontend/login.htmlin your web browser - Or navigate to:
file:///path/to/electrician-log-mvp/frontend/login.html - Login with your admin credentials
- You'll be redirected to the main application
- Open
Create users via CLI:
cd backend
python utils/user_manager.pyAvailable roles:
worker- Can create and view work logssupervisor- Can manage critical sectors and view all logsadmin- Full system access
- Open
frontend/login.html - Enter your credentials
- Click "Sign In"
- Select a Floor - Choose from available floors in the left panel
- View Work Logs - Markers show work locations (color-coded by work type)
- Click Marker - View work log details
- Click Empty Area - Create new work log at that location
- Date Navigation - Use date controls to filter logs by date
- Keyboard Shortcuts:
1-6- Jump to floor 1-6โ/โ- Navigate between datesT- Go to todayA- Toggle date filterR- Reset viewF- Toggle fullscreenESC- Show all dates
- Draw Rectangle - Click "Draw Rectangle" button, click two corners
- Draw Polygon - Click "Draw Polygon" button, click points, double-click to finish
- Save Sector - Enter name and priority, click save
- View Sectors - Toggle visibility with "Show/Hide Sectors"
- Delete Sector - Click sector, view details, click delete
Access via the sidebar menu:
- Worker Dashboard - View assignments and personal work logs
- Supervisor Dashboard - Manage critical sectors, view all work, create assignments
- Admin Dashboard - System statistics, tile generation, user management
http://localhost:5000/api
All API endpoints (except /api/auth/login) require a JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
POST /api/auth/login # Login user
POST /api/auth/logout # Logout user
GET /api/auth/verify # Verify token
POST /api/auth/refresh # Refresh tokenGET /api/work-logs # Get work logs (with filters)
POST /api/work-logs # Create work log
GET /api/work-logs/<id> # Get specific work log
PUT /api/work-logs/<id> # Update work log
DELETE /api/work-logs/<id> # Delete work log
GET /api/work-logs/dashboard # Get dashboard statsQuery Parameters for GET /api/work-logs:
floor_id- Filter by floorworker_id- Filter by workerstart_date- From date (YYYY-MM-DD)end_date- To date (YYYY-MM-DD)
GET /api/floors # Get all floors
GET /api/floors/<id> # Get specific floor
POST /api/floors # Create floor (admin)
PUT /api/floors/<id> # Update floor (admin)GET /api/critical-sectors # Get critical sectors
POST /api/critical-sectors # Create critical sector (supervisor/admin)
DELETE /api/critical-sectors/<id> # Delete critical sector (supervisor/admin)POST /api/tiles/generate/<floor_id> # Generate tiles for floor
GET /api/tiles/status/<floor_id> # Check tile status
GET /api/tiles/<floor_id>/<path> # Serve tile files
POST /api/tiles/batch-generate # Generate all tiles (admin)GET /api/assignments # Get assignments
POST /api/assignments # Create assignment
PUT /api/assignments/<id> # Update assignmentGET /api/notifications # Get notifications
PUT /api/notifications/<id>/read # Mark as readcurl -X POST http://localhost:5000/api/work-logs \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-token>" \
-d '{
"floor_id": 1,
"x_coord": 0.456,
"y_coord": 0.789,
"work_date": "2024-11-22",
"worker_name": "John Doe",
"work_type": "Electrical",
"description": "Replaced faulty outlet"
}'- Authentication and role management
- Fields: id, username, password_hash, full_name, role, is_active, created_at, last_login
- Building floor information
- Fields: id, name, image_path, width, height
- Work log entries with coordinates
- Fields: id, floor_id, worker_id, x_coord, y_coord, work_date, worker_name, work_type, description, created_at, updated_at
- Critical areas on floor plans
- Fields: id, floor_id, sector_name, type, x_coord, y_coord, radius, width, height, priority, created_by, created_at
- Work assignments for workers
- Fields: id, work_log_id, assigned_to, assigned_by, due_date, status, notes, created_at
- User notifications
- Fields: id, user_id, type, title, message, related_id, is_read, created_at
- ๐ด Red - Electrical
- ๐ต Blue - Lighting
- ๐ข Green - Maintenance
- ๐ก Yellow - Installation
- ๐ฃ Purple - Inspection/Other
The refactored architecture follows these principles:
- Separation of Concerns - Routes, business logic, and data access are separated
- Service Layer - Business logic isolated in service classes
- Reusable Components - Frontend services for API communication
- Security First - JWT authentication, role-based access control
- Scalability - Easy to add new features and endpoints
-
Backend:
- Create model in
backend/app/models/ - Create service in
backend/app/services/ - Create routes in
backend/app/api/new_feature/ - Register blueprint in
backend/app/__init__.py
- Create model in
-
Frontend:
- Create service in
frontend/core/api/ - Add UI components/pages
- Wire up with Vue.js
- Create service in
cd backend
python -m pytest tests/See FEATURES.md for implemented features (with how they work), future roadmap, and code simplification opportunities. Last updated: Feb 2025.
# Check Python version (need 3.7+)
python --version
# Reinstall dependencies
pip install -r requirements.txt
# Check if port 5000 is in use
# Windows: netstat -ano | findstr :5000
# Mac/Linux: lsof -i :5000# Recreate admin user
cd backend
python utils/setup_admin.py
# Check database
sqlite3 database.db "SELECT * FROM users;"# Regenerate tiles for a specific floor
cd backend
python utils/regenerate_tiles_safe.py
# Or regenerate all tiles
python utils/regenerate_all_tiles_hd.py- Verify backend is running on
http://localhost:5000 - Check browser console for errors (F12)
- Verify CORS is enabled in backend
- Clear browser cache and localStorage
- Flask - Web framework
- Flask-CORS - CORS support
- PyJWT - JWT token handling
- Pillow - Image processing
- pdf2image - PDF to image conversion
- pyvips - High-performance image processing
Install all: pip install -r requirements.txt
- Vue.js 3 - Frontend framework
- Tailwind CSS - Utility-first CSS
- OpenSeadragon - Deep zoom image viewer
- Chart.js - Data visualization
See FEATURES.md for the full roadmap. Planned items:
- Real-time updates with WebSockets
- Progressive Web App (PWA) support
- Offline mode with service workers
- Export to PDF/Excel
- Email notifications
- Mobile native apps
- PostgreSQL support for production
- Docker containerization
- CI/CD pipeline
- Multi-language support
MIT License - Feel free to use and modify for your needs.
This project follows a modular architecture. When contributing:
- Follow the existing code structure
- Add services for business logic
- Use decorators for authentication
- Write tests for new features
- Update this README if needed
For issues or questions:
- Check the Troubleshooting section
- Review the API documentation
- Create an issue in the project repository
Built with โค๏ธ using Flask, Vue.js, and OpenSeadragon