How ducanh271/backenddoan works
This Go backend provides employee administration, authentication, company configuration, and face-based attendance. The principal workflow accepts an attendance request, verifies identity via the AI service (and, for mobile check-in, checks company network/location constraints), then records attendance or access outcomes. The startup and route wiring and core attendance/authentication code are excerpted; README content is absent, and some handlers and services are unsampled, so those branches are shown only where route declarations or initialization support them.
Main entry points: routes.go Route setup · auth_service.go Authentication · attendance_service.go Attendance decisions · employee_repository.go Employee repository
Components 24
API and security
- Gin server
cmd/main.go - Route setup
routes/routes.go - JWT authorization
middleware/jwt_auth.go - Auth endpoints
handlers/auth_handler.go - Authentication
service/auth_service.go - Token and OTP
security/token.go - OTP generation
security/otp.go - OTP email
utils/email.go
Workforce management
- Employee endpoints
handlers/employee_handler.go - Employee services
service/employee_service.go - Employee registration
service/register_service.go - Config endpoints
handlers/config_handler.go - Company configuration
service/config_service.go
Attendance
- Attendance endpoints
handlers/attendance_handler.go - Attendance decisions
service/attendance_service.go
Persistence and integrations
- Face AI client
infrastructure/ai/ai_client.go - Employee repository
repository/employee_repository.go - Attendance repository
repository/attendance_repository.go - Config repository
repository/company_config_repository.go - Refresh token repository
repository/refresh_token_repository.go - MySQL database
database/db.go
Other components
- API clients
- AI service
- SMTP service
Connections 33
- API clients → Gin server: sends requests
- Gin server → Route setup: configures routes
cmd/main.go - Route setup → Auth endpoints: routes auth
routes/routes.go - Route setup → Attendance endpoints: routes attendance
routes/routes.go - Route setup → Employee endpoints: routes employees
routes/routes.go - Route setup → Config endpoints: routes config
routes/routes.go - Route setup → JWT authorization: guards routes
routes/routes.go - Auth endpoints → Authentication: calls
handlers/auth_handler.go - Authentication → Employee repository: reads and updates
service/auth_service.go - Authentication → Refresh token repository: rotates tokens
service/auth_service.go - Authentication → Token and OTP: generates tokens
service/auth_service.go - Authentication → OTP generation: generates OTP
service/auth_service.go - Authentication → OTP email: sends OTP
service/auth_service.go - OTP email → SMTP service: sends mail
- Employee endpoints → Employee registration: registers employees
- Employee endpoints → Employee services: manages employees
- Employee services → Employee repository: uses repository
- Employee registration → Employee repository: stores employees
- Employee registration → Face AI client: registers faces
- Config endpoints → Company configuration: calls
- Company configuration → Config repository: reads and updates
- Attendance endpoints → Attendance decisions: calls
handlers/attendance_handler.go - Attendance decisions → Employee repository: loads employees
service/attendance_service.go - Attendance decisions → Config repository: checks company settings
service/attendance_service.go - Attendance decisions → Face AI client: verifies faces
service/attendance_service.go - Face AI client → AI service: posts images
infrastructure/ai/ai_client.go - Attendance decisions → Attendance repository: reads and saves records
service/attendance_service.go - Attendance decisions → Employee repository: logs access
service/attendance_service.go - Employee repository → MySQL database: queries employees
- Attendance repository → MySQL database: queries attendance
- Config repository → MySQL database: stores settings
- Refresh token repository → MySQL database: stores tokens
- Gin server → MySQL database: opens connection
cmd/main.go