How whilmarbitoco/hrms-microservices works
1. This repository is a containerized HRMS built as multiple independent Flask services plus a separate TypeScript frontend. The codebase currently contains four backend services: auth-ms, employee-ms, leave-ms, and payroll-ms. The README also mentions an “Attendance” service, but no separate attendance microservice exists in the tree; leave management is implemented in leave-ms.
2. The frontend is a Vite/React app under frontend/. It provides role-oriented dashboards and pages for auth, employees, departments, leave, payroll, roles, and users. AuthContext holds login/session state, and the hooks/ directory shows the UI talks to each backend service through a shared API client rather than directly to the database.
3. Each backend service follows the same internal architecture: Flask app bootstrap, core config/logging, SQLAlchemy-style database schema, error handlers, event integration, and a domain-oriented modules/ layer. The common split is route layer → service layer → repository/model layer, which makes the services easy to diagram as cleanly separated API, business logic, and persistence boundaries.
4. auth-ms owns authentication and user identity. Its routes are health, v1/auth, and v1/users, and its domain modules are auth and users. This service is the JWT boundary for the system, handling registration, login, refresh, password reset, and role/user management. It also contains both event producer and consumer code, indicating it participates in cross-service user lifecycle propagation.
5. employee-ms owns the HR master data: employees, departments, and employee_roles. It exposes corresponding versioned routes and has policy modules alongside each domain, suggesting authorization and domain-rule enforcement close to the business objects. This service is the canonical source for employee/org structure data used by other services.
6. leave-ms owns leave-related workflows: leave_requests, leave_balances, leave_policies, plus an employee_cache module. The cache module is important architecturally because it decouples leave workflows from live reads against the employee service. This service has both producer and consumer event code, so it likely keeps its cache and leave balances in sync asynchronously when employee/user changes occur.
7. payroll-ms owns compensation processing: salary_components, adjustments, payroll_batches, payslips, and an employee_cache. Like leave, it avoids tight coupling to the employee service by maintaining its own cached employee view. Its domain layout suggests a flow from salary component definitions and adjustments into batch payroll runs, then into generated payslips.
8. Cross-service communication is event-driven. The presence of events/producer.py, events/consumer.py, and events/handlers.py in multiple services implies asynchronous integration through a message broker rather than direct service-to-service HTTP calls. In the architecture diagram, this should be shown as a broker-centric integration boundary connecting auth, employee, leave, and payroll.
9. Persistence is per-service and isolated. Each backend has its own migrations/ folder, seed.sql, and database/schema.py, which strongly suggests separate databases or at least separate schemas managed independently. That isolation is a core architectural choice: each microservice owns its data model and migration lifecycle.
10. Security and policy enforcement are standardized but domain-specific. All services include shared utils/permissions.py, utils/policy.py, and utils/sanitizer.py, while some domains also have their own policy.py. That indicates a layered authorization model: common permission helpers at the service level, plus business-rule policies near the domains that need them.
11. Operationally, each service is containerized with its own Dockerfile, wsgi.py, .env.sample, and Flask app package. The repo also includes top-level Docker Compose files and an nginx/ directory, so the likely deployment shape is reverse-proxy fronted containers for the UI and APIs, with service-specific environment configuration.
12. Testing is split between unit/service tests inside each microservice and cross-service integration tests under top-level tests/integration. That means the repo supports both local confidence inside each bounded context and end-to-end validation of the multi-service HRMS flows.
13. For an architecture diagram, the key nodes are: browser/user → frontend → service APIs; service APIs → per-service databases; services → message broker; and shared cached-read paths in leave/payroll that depend on employee events. The most important boundaries are auth/JWT, per-service data ownership, and asynchronous event propagation between the HR domains.
Main entry points: nginx.conf Nginx · api.ts API client · leave_requests/service.py Leave domain · payroll_batches/service.py Payroll domain
Components 20
Platform
Deployment and integration boundary
- Users · Human operators using the HRMS UI
- Nginx · Front door for the frontend and backend containers
nginx/nginx.conf - Event bus · Asynchronous integration boundary connecting services
Frontend
Vite/React UI and shared API access
- React app · Role-oriented UI for auth, HR, leave, payroll, roles, and users
frontend/src/App.tsx - API client · Common HTTP layer used by hooks to reach backend services
frontend/src/lib/api.ts
auth-ms
Authentication and identity service
- Auth API · Health, auth, and user endpoints; JWT boundary
auth-ms/app/routes/v1/auth.py - Auth domain · Login, refresh, registration, reset, roles, and user flows
auth-ms/app/modules/auth/service.py - Auth DB · Auth/user schema and repository-owned storage
auth-ms/app/database/schema.py
employee-ms
HR master data service
leave-ms
Leave workflow service
- Leave API · Leave requests, balances, policies, and employee cache endpoints
leave-ms/app/routes/v1/leave_requests.py - Leave domain · Leave workflow logic and cached employee-aware decisions
leave-ms/app/modules/leave_requests/service.py - Employee cache · Local employee view used to decouple leave workflows from HR reads
leave-ms/app/modules/employee_cache/service.py - Leave DB · Leave requests, balances, policies, and cache storage
leave-ms/app/database/schema.py
payroll-ms
Compensation processing service
- Payroll API · Salary components, adjustments, batches, payslips, and cache endpoints
payroll-ms/app/routes/v1/payroll_batches.py - Payroll domain · Payroll calculation pipeline and employee-aware compensation logic
payroll-ms/app/modules/payroll_batches/service.py - Employee cache · Local employee view used to avoid tight coupling to HR service
payroll-ms/app/modules/employee_cache/service.py - Payroll DB · Salary components, adjustments, batches, and payslip storage
payroll-ms/app/database/schema.py
Integration
Cross-service test harness
- E2E tests · Cross-service validation for HRMS flows
tests/integration/runner.py
Connections 33
- Users → React app: uses · People interact with the web UI
- React app → API client: calls · UI pages and dashboards use the shared API layer
- API client → Auth API: auth · Login, session, profile, and user management requests
- API client → HR API: hr · Employee, department, and role requests
- API client → Leave API: leave · Leave workflow requests
- API client → Payroll API: payroll · Payroll and payslip requests
- React app → Nginx: served by · Frontend is reverse-proxied in containerized deployment
- Nginx → Auth API: routes · Proxy to backend service endpoints
- Nginx → HR API: routes · Proxy to backend service endpoints
- Nginx → Leave API: routes · Proxy to backend service endpoints
- Nginx → Payroll API: routes · Proxy to backend service endpoints
- Auth API → Auth domain: executes · Route layer delegates to auth service logic
- Auth domain → Auth DB: persists · Auth/user data is stored in service-owned schema
- HR API → HR domain: executes · Route layer delegates to HR service logic
- HR domain → HR DB: persists · HR master data is stored in service-owned schema
- Leave API → Leave domain: executes · Route layer delegates to leave service logic
- Leave domain → Employee cache: reads · Leave workflows consult the local employee cache
- Leave domain → Leave DB: persists · Leave data is stored in service-owned schema
- Payroll API → Payroll domain: executes · Route layer delegates to payroll service logic
- Payroll domain → Employee cache: reads · Payroll calculations consult the local employee cache
- Payroll domain → Payroll DB: persists · Payroll data is stored in service-owned schema
- Auth domain → Event bus: publishes · Auth/user lifecycle events are emitted asynchronously
- HR domain → Event bus: publishes · HR changes are emitted for downstream consumers
- Event bus → Leave domain: consumes · Leave service reacts to employee/user events
- Event bus → Payroll domain: consumes · Payroll service reacts to employee/user events
- Event bus → Auth domain: consumes · Auth service participates in event-driven user lifecycle handling
- Event bus → HR domain: consumes · HR service participates in event-driven propagation
- Leave domain → Event bus: publishes · Leave workflows can emit state changes asynchronously
- Payroll domain → Event bus: publishes · Payroll workflows can emit state changes asynchronously
- E2E tests → Auth API: covers · End-to-end tests validate service flows
- E2E tests → HR API: covers · End-to-end tests validate service flows
- E2E tests → Leave API: covers · End-to-end tests validate service flows
- E2E tests → Payroll API: covers · End-to-end tests validate service flows