TraceFlow is a state-of-the-art, AI-driven platform developed for Enda Tao to streamline territorial activity tracking, timesheet management, and receipt book traceability. Created as a final-year project, TraceFlow empowers roles such as Super Admin, Admin, Director, Regional Manager, Supervisor, Purchase Team, Stock Manager, and HR with secure authentication, geolocation, real-time updates, and AI-powered analytics. Featuring dynamic dashboards, multilingual support (English, French, Arabic), and seamless integrations, TraceFlow delivers operational excellence in a scalable, user-centric package. ๐
- ๐ Overview
- ๐ฅ Key Features
- ๐๏ธ System Architecture
- ๐ ๏ธ Technology Stack
- ๐ Getting Started
- โ๏ธ Configuration
- ๐ฎ Usage
- ๐ API Documentation
- ๐งช Testing
- ๐ Deployment
- ๐ค Contributing
- ๐ License
- ๐ฌ Support
TraceFlow revolutionizes Enda Taoโs operational workflows by digitizing and optimizing key processes. It integrates:
- Timesheet Management: Streamlined creation, validation, and AI-driven scheduling. ๐
- Visit Tracking: Real-time geolocation and QR code-based logging. ๐
- Receipt Book Traceability: Secure tracking with QR codes and OTP. ๐
- AI Analytics: Anomaly detection and actionable insights. ๐ค
- Dynamic Dashboards: Role-specific, multilingual interfaces. ๐
- Real-Time Notifications: WebSocket-driven alerts for instant updates. ๐
Built for scalability and security, TraceFlow leverages modern technologies to ensure efficiency, traceability, and accountability.
- Timesheet Management ๐
- Create, edit, validate, and delete timesheets with role-based access.
- AI-generated suggestions (up to 5 per request) for optimized scheduling.
- Filter by week, year, or role (e.g., Supervisor, HR).
- Visit Tracking ๐
- Log visits via QR code scanning and OTP validation.
- Google Maps integration for real-time agent tracking, route optimization, and nearby agent detection.
- Filter by regions, governorates, or delegations.
- Receipt Book Traceability ๐
- Secure tracking with QR codes and OTP for books and stubs.
- Transfer history, stock management, and validation for Purchase Team and Stock Manager roles.
- Comprehensive audit trails.
- AI-Powered Analytics ๐ค
- Anomaly detection with a 0.95 confidence threshold.
- Automated report generation for Directors and Admins.
- Dynamic Dashboards ๐
- Interactive, role-specific KPIs with dark mode support.
- Multilingual: English, French, Arabic.
- Real-Time Notifications ๐
- WebSocket-based alerts for timesheet approvals, visit logs, and receipt transfers.
- Configurable notification rules.
- Secure Authentication ๐
- Keycloak with OAuth2 and Google Auth integration.
- Token lifespans: Access (15 min), Refresh (1 day), SSO Session (1 day, idle: 9 hours).
- Rate Limiting โก
- Sensitive operations: 10 requests/10 min.
- OTP and refresh token limits for security.
- Logging ๐
- 30-day retention with log statistics, filters, and health metrics.
- Max page size: 500, default: 50.
Tip: TraceFlow supports up to 5 file downloads per session for reports and logs.
TraceFlowโs modular architecture ensures scalability and maintainability:
- Frontend (Web): React with TypeScript, Vite, and Tailwind CSS for responsive dashboards.
- Frontend (Mobile): Flutter for cross-platform Android/iOS apps.
- Backend: Node.js with Express.js for API, authentication, and WebSocket communication.
- Database: PostgreSQL for relational data, Redis for caching.
- AI Engine: Ollama with Mistral model for analytics and suggestions.
- Authentication: Keycloak for SSO, Google OAuth2 for Maps and Calendar.
- Infrastructure: Docker for containerization, NGINX for reverse proxy, PM2 for process management.
TraceFlow leverages a modern, robust tech stack, showcased with GitHub-style badges for clarity and visual appeal:
Node.js v22.14 or later
PostgreSQL with pgAdmin4 v9
Redis (latest stable)
Docker for Keycloak and Redis
Flutter v3.29, Dart 3.7
Git for repository access
-
Clone the Repository:
git clone https://github.com/CodeWizard-404/traceflow.git cd traceflow
-
Install Backend Dependencies:
cd Back npm install
-
Install Frontend (Web) Dependencies:
cd ../Front npm install
-
Install Mobile Dependencies:
cd ../Mobile flutter pub get
-
Set Up Database:
- Create a PostgreSQL database:
traceflow_db
. - Run migrations:
cd Back npm run migrate
- Create a PostgreSQL database:
-
Start Docker Containers:
- Launch Keycloak and Redis:
docker-compose up -d
- Launch Keycloak and Redis:
Configuration is managed via .env
files included in the repository. Key settings are detailed below:
๐ View Backend Configuration
- Database:
- Host:
localhost:5432
- User:
postgres
- Password:
admin
- Database:
traceflow_db
- Host:
- URLs:
- Development:
http://localhost
- Production:
https://localhost
- Frontend:
http://localhost:5173
,http://192.168.1.21:5173
,http://192.168.1.100
- Login:
http://localhost:5173/login
- Redirect:
http://localhost:5000/api/auth/callback
- Development:
- Keycloak:
- URL:
http://localhost:8080
- Realm:
TraceFlow
- Client ID:
traceflow-backend
- Client Secret:
9FQJDVvEU3MZvB9CGxuM50IcTVOapED7
- Admin: Configured for administrative access
- URL:
- Google APIs:
- Maps API Key:
AIzaSyDkbpHSSJc-fsV5fcwYkSxk0Mq0RNCAb7g
- Calendar Client ID:
803294683158-1o22qb2cda9c5mgvj5dhn8pdcn11jo45.apps.googleusercontent.com
- Calendar Redirect URI:
http://localhost:5000/api/auth/google-calendar-auth/callback
- Maps API Key:
- Redis:
- Host:
localhost:6379
- Cluster: Disabled
- Host:
- Ollama (AI):
- URL:
http://localhost:11434/api
- Model:
mistral
- Timeout: 5 minutes
- Max Retries: 3
- Anomaly Threshold: 0.95
- Max Timesheet Suggestions: 5
- URL:
- SMTP:
- Host:
smtp.gmail.com:587
- Configured with app-specific credentials
- Host:
- SMS:
- WBM.tn API (v5):
https://wbm.tn/wbmonitor/send/webapi/v5/
- API Key:
9c5362a406e609d0ecc6f9a0e129c0a6
- WBM.tn API (v3):
https://wbm.tn/wbmonitor/send/webapi/v3/send_ack.php
- Username:
enda-cash
- Password: Configured for secure access
- WBM.tn API (v5):
- Rate Limiting:
- Sensitive Operations: 10 requests/10 min
- OTP: 10 requests/10 min
- Refresh Tokens: 5 requests/10 min
- Logging:
- Level:
info
- Retention: 30 days
- Secret: Configured for secure logging
- Sample Rate: 1
- Level:
- CSV Processing:
- Encoding:
utf8
(fallback:win1252
) - Delimiter:
,
- Config Path:
./config/csv-config.json
- Encoding:
- Roles:
- Super Admin, Admin, Director, Regional Manager, Supervisor, Purchase Team, Stock Manager, HR
- Initialization:
- Enabled: Database, SMTP, SMS, Redis, Google Services, WebSocket, etc.
- Vault:
- Address:
http://127.0.0.1:8200
- Token: Configured for secret management
- Address:
- mDNS: Enabled for local discovery
๐ View Frontend Configuration
- API:
- URL:
http://192.168.1.21:5000/api
- Timeout: 30 seconds
- Access Token Lifespan: 15 minutes
- URL:
- Keycloak: Matches backend configuration
- Google APIs: Configured for Maps and Calendar
- Permissions (Selected):
- Users:
access_all_users
,create_users
,update_users
,delete_users
- Timesheets:
access_all_timesheets
,validate_timesheets
,suggest_timesheets
- Visits:
scan_visits
,log_visits
,sync_calendar
- Receipt Books:
transfer_receipt_books
,validate_receipt_stubs
,access_receipt_book_history
- Agents:
access_agents_by_location
,update_agents_location
,access_nearby_agents
- Notifications:
trigger_notifications
,manage_notification_rules
- Logs:
view_logs
,archive_logs
,export_logs
,view_logger_metrics
- Reports:
generate_report
,schedule_report
,download_report
- AI:
access_ai_anomaly_detection
,manage_ai_config
- Users:
- Roles: Matches backend roles
- Checklist Items:
Transfer a receipt book
Collect receipt stub
๐ View Mobile Configuration
- Base URL:
http://192.168.1.21:5000/api
- Keycloak:
- URL:
http://localhost:8080
- Realm:
TraceFlow
- Client ID:
traceflow-backend
- Client Secret:
9FQJDVvEU3MZvB9CGxuM50IcTVOapED7
- Redirect URI:
http://localhost:8080/realms/TraceFlow/broker/google/endpoint
- URL:
- Google:
- Web Client ID:
803294683158-1o22qb2cda9c5mgvj5dhn8pdcn11jo45.apps.googleusercontent.com
- Android Client ID:
803294683158-jf323a7qjjo3nfblgl2nao9il1fgroia.apps.googleusercontent.com
- iOS Client ID:
803294683158-47b4jojal7je374cr7n4qh7ra47pcttq.apps.googleusercontent.com
- Web Client ID:
- Keycloak:
- Admin Console:
http://localhost:8080
- Configure
TraceFlow
realm, clients, and roles.
- Admin Console:
- Google APIs:
- Enable Maps and Calendar APIs in Google Cloud Console.
- Update
.env
files with credentials.
- SSL (Production):
- Paths:
/etc/ssl/private/key.pem
,/etc/ssl/certs/cert.pem
- Paths:
- Vault:
- Address:
http://127.0.0.1:8200
- Token: Configured for secure secrets.
- Address:
- Web Application:
- Start backend:
cd Back npm start
- Start frontend:
cd ../Front npm run dev
- Access:
http://localhost:5173
- Start backend:
- Mobile Application:
- Run Flutter app:
cd Mobile flutter run
- Run Flutter app:
- Log a Visit ๐:
- Scan QR code, enter OTP, complete checklist (e.g., โTransfer a receipt bookโ).
- View agent locations on Google Maps.
- Manage Timesheets ๐
:
- Create timesheets, review AI suggestions, and validate via web interface.
- Filter by week, year, or role.
- Track Receipt Books ๐:
- Scan QR codes to transfer books or collect stubs.
- Validate transfers or view history.
- Generate Reports ๐:
- Schedule AI-driven reports or download (max 5 per session).
- Analyze anomalies (0.95 threshold).
- Access Swagger docs:
http://localhost:5000/api-docs
- Key Endpoints:
- Users:
/api/users
,/api/roles/assign
,/api/users/by-role
- Timesheets:
/api/timesheets
,/api/timesheets/suggest
,/api/timesheets/validate
- Visits:
/api/visits
,/api/visits/scan
,/api/visits/sync-calendar
- Receipt Books:
/api/receipt-books
,/api/receipt-books/transfer
,/api/receipt-books/history
- Agents:
/api/agents
,/api/agents/locations
,/api/agents/nearby
- Notifications:
/api/notifications
,/api/notifications/rules
- Logs:
/api/logs
,/api/logs/export
,/api/logs/statistics
- Reports:
/api/reports/generate
,/api/reports/schedule
- Users:
- Unit Tests:
- Backend:
cd Back npm test
- Mobile:
cd Mobile flutter test
- Backend:
- API Tests:
- Use Postman collections in
Back/tests
.
- Use Postman collections in
- Coverage:
- Target 80%+ coverage for critical modules.
- Development:
- Set
NODE_ENV=development
. - Start services:
docker-compose up -d
- Set
- Production:
- Set
NODE_ENV=production
and updatePROD_URL
. - Configure NGINX:
nginx -s reload
- Manage Node.js with PM2:
pm2 start Back/app.js --name traceflow-backend
- Deploy with Docker:
docker-compose -f docker-compose.prod.yml up -d
- Enable HTTPS with SSL certificates.
- Set
Contributions are welcome to enhance TraceFlowโs capabilities.
- Issues: Report bugs or suggest features via GitHub Issues.
- Pull Requests:
- Fork the repository.
- Create a branch:
git checkout -b feature/your-feature
. - Commit changes and submit a pull request.
- Guidelines:
- Follow ESLint, TypeScript, and Dart standards.
- Include unit tests.
- Provide detailed PR descriptions.
For inquiries or issues, please use GitHub Issues. Additional support is available through the platformโs official channels.
TraceFlow โ Empowering Enda Tao with AI-driven efficiency, traceability, and scalability. ๐