# whilmarbitoco/hrms-microservices architecture

> Architecture diagram of the GitHub repository whilmarbitoco/hrms-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/whilmarbitoco/hrms-microservices
- Repository: https://github.com/whilmarbitoco/hrms-microservices

## Overview

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/nginx.conf`](https://github.com/whilmarbitoco/hrms-microservices/blob/main/nginx/nginx.conf) (Nginx), [`frontend/src/lib/api.ts`](https://github.com/whilmarbitoco/hrms-microservices/blob/main/frontend/src/lib/api.ts) (API client), [`leave-ms/app/modules/leave_requests/service.py`](https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/modules/leave_requests/service.py) (Leave domain), [`payroll-ms/app/modules/payroll_batches/service.py`](https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/modules/payroll_batches/service.py) (Payroll domain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform"]
  node_users(("Users<br/>actor"))
  node_nginx["Nginx<br/>reverse proxy<br/>[nginx.conf]"]
  node_broker(("Event bus<br/>message broker"))
end

subgraph group_frontend["Frontend"]
  node_frontend_app["React app<br/>vite frontend<br/>[App.tsx]"]
  node_frontend_api["API client<br/>shared client<br/>[api.ts]"]
end

subgraph group_auth["auth-ms"]
  node_auth_routes["Auth API<br/>flask routes<br/>[auth.py]"]
  node_auth_domain["Auth domain<br/>service layer<br/>[service.py]"]
  node_auth_data[("Auth DB<br/>persistence<br/>[schema.py]")]
end

subgraph group_employee["employee-ms"]
  node_employee_routes["HR API<br/>flask routes<br/>[employees.py]"]
  node_employee_domain["HR domain<br/>service layer<br/>[service.py]"]
  node_employee_data[("HR DB<br/>persistence<br/>[schema.py]")]
end

subgraph group_leave["leave-ms"]
  node_leave_routes["Leave API<br/>flask routes<br/>[leave_requests.py]"]
  node_leave_domain["Leave domain<br/>service layer<br/>[service.py]"]
  node_leave_cache["Employee cache<br/>cached read model<br/>[service.py]"]
  node_leave_data[("Leave DB<br/>persistence<br/>[schema.py]")]
end

subgraph group_payroll["payroll-ms"]
  node_payroll_routes["Payroll API<br/>flask routes<br/>[payroll_batches.py]"]
  node_payroll_domain["Payroll domain<br/>service layer<br/>[service.py]"]
  node_payroll_cache["Employee cache<br/>cached read model<br/>[service.py]"]
  node_payroll_data[("Payroll DB<br/>persistence<br/>[schema.py]")]
end

subgraph group_testing["Integration"]
  node_integration_tests["E2E tests<br/>integration suite<br/>[runner.py]"]
end

node_users -->|"uses"| node_frontend_app
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_api -->|"auth"| node_auth_routes
node_frontend_api -->|"hr"| node_employee_routes
node_frontend_api -->|"leave"| node_leave_routes
node_frontend_api -->|"payroll"| node_payroll_routes
node_frontend_app -->|"served by"| node_nginx
node_nginx -->|"routes"| node_auth_routes
node_nginx -->|"routes"| node_employee_routes
node_nginx -->|"routes"| node_leave_routes
node_nginx -->|"routes"| node_payroll_routes
node_auth_routes -->|"executes"| node_auth_domain
node_auth_domain -->|"persists"| node_auth_data
node_employee_routes -->|"executes"| node_employee_domain
node_employee_domain -->|"persists"| node_employee_data
node_leave_routes -->|"executes"| node_leave_domain
node_leave_domain -->|"reads"| node_leave_cache
node_leave_domain -->|"persists"| node_leave_data
node_payroll_routes -->|"executes"| node_payroll_domain
node_payroll_domain -->|"reads"| node_payroll_cache
node_payroll_domain -->|"persists"| node_payroll_data
node_auth_domain -->|"publishes"| node_broker
node_employee_domain -->|"publishes"| node_broker
node_broker -->|"consumes"| node_leave_domain
node_broker -->|"consumes"| node_payroll_domain
node_broker -->|"consumes"| node_auth_domain
node_broker -->|"consumes"| node_employee_domain
node_leave_domain -->|"publishes"| node_broker
node_payroll_domain -->|"publishes"| node_broker
node_integration_tests -->|"covers"| node_auth_routes
node_integration_tests -->|"covers"| node_employee_routes
node_integration_tests -->|"covers"| node_leave_routes
node_integration_tests -->|"covers"| node_payroll_routes

click node_nginx "https://github.com/whilmarbitoco/hrms-microservices/blob/main/nginx/nginx.conf"
click node_frontend_app "https://github.com/whilmarbitoco/hrms-microservices/blob/main/frontend/src/App.tsx"
click node_frontend_api "https://github.com/whilmarbitoco/hrms-microservices/blob/main/frontend/src/lib/api.ts"
click node_auth_routes "https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/routes/v1/auth.py"
click node_auth_domain "https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/modules/auth/service.py"
click node_auth_data "https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/database/schema.py"
click node_employee_routes "https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/routes/v1/employees.py"
click node_employee_domain "https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/modules/employees/service.py"
click node_employee_data "https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/database/schema.py"
click node_leave_routes "https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/routes/v1/leave_requests.py"
click node_leave_domain "https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/modules/leave_requests/service.py"
click node_leave_cache "https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/modules/employee_cache/service.py"
click node_leave_data "https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/database/schema.py"
click node_payroll_routes "https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/routes/v1/payroll_batches.py"
click node_payroll_domain "https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/modules/payroll_batches/service.py"
click node_payroll_cache "https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/modules/employee_cache/service.py"
click node_payroll_data "https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/database/schema.py"
click node_integration_tests "https://github.com/whilmarbitoco/hrms-microservices/blob/main/tests/integration/runner.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_users,node_nginx,node_broker,node_integration_tests toneBlue
class node_frontend_app,node_frontend_api toneAmber
class node_auth_routes,node_auth_domain,node_auth_data toneMint
class node_employee_routes,node_employee_domain,node_employee_data toneRose
class node_leave_routes,node_leave_domain,node_leave_cache,node_leave_data toneIndigo
class node_payroll_routes,node_payroll_domain,node_payroll_cache,node_payroll_data toneTeal
```

## Components

### Platform

Deployment and integration boundary

- **Users**: actor · Human operators using the HRMS UI
- [Nginx](https://github.com/whilmarbitoco/hrms-microservices/blob/main/nginx/nginx.conf): reverse proxy · Front door for the frontend and backend containers · `nginx/nginx.conf`
- **Event bus**: message broker · Asynchronous integration boundary connecting services

### Frontend

Vite/React UI and shared API access

- [React app](https://github.com/whilmarbitoco/hrms-microservices/blob/main/frontend/src/App.tsx): vite frontend · Role-oriented UI for auth, HR, leave, payroll, roles, and users · `frontend/src/App.tsx`
- [API client](https://github.com/whilmarbitoco/hrms-microservices/blob/main/frontend/src/lib/api.ts): shared client · Common HTTP layer used by hooks to reach backend services · `frontend/src/lib/api.ts`

### auth-ms

Authentication and identity service

- [Auth API](https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/routes/v1/auth.py): flask routes · Health, auth, and user endpoints; JWT boundary · `auth-ms/app/routes/v1/auth.py`
- [Auth domain](https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/modules/auth/service.py): service layer · Login, refresh, registration, reset, roles, and user flows · `auth-ms/app/modules/auth/service.py`
- [Auth DB](https://github.com/whilmarbitoco/hrms-microservices/blob/main/auth-ms/app/database/schema.py): persistence · Auth/user schema and repository-owned storage · `auth-ms/app/database/schema.py`

### employee-ms

HR master data service

- [HR API](https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/routes/v1/employees.py): flask routes · Employees, departments, and employee roles endpoints · `employee-ms/app/routes/v1/employees.py`
- [HR domain](https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/modules/employees/service.py): service layer · Master data and policy enforcement for HR structures · `employee-ms/app/modules/employees/service.py`
- [HR DB](https://github.com/whilmarbitoco/hrms-microservices/blob/main/employee-ms/app/database/schema.py): persistence · Employees, departments, and role data store · `employee-ms/app/database/schema.py`

### leave-ms

Leave workflow service

- [Leave API](https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/routes/v1/leave_requests.py): flask routes · Leave requests, balances, policies, and employee cache endpoints · `leave-ms/app/routes/v1/leave_requests.py`
- [Leave domain](https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/modules/leave_requests/service.py): service layer · Leave workflow logic and cached employee-aware decisions · `leave-ms/app/modules/leave_requests/service.py`
- [Employee cache](https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/modules/employee_cache/service.py): cached read model · Local employee view used to decouple leave workflows from HR reads · `leave-ms/app/modules/employee_cache/service.py`
- [Leave DB](https://github.com/whilmarbitoco/hrms-microservices/blob/main/leave-ms/app/database/schema.py): persistence · Leave requests, balances, policies, and cache storage · `leave-ms/app/database/schema.py`

### payroll-ms

Compensation processing service

- [Payroll API](https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/routes/v1/payroll_batches.py): flask routes · Salary components, adjustments, batches, payslips, and cache endpoints · `payroll-ms/app/routes/v1/payroll_batches.py`
- [Payroll domain](https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/modules/payroll_batches/service.py): service layer · Payroll calculation pipeline and employee-aware compensation logic · `payroll-ms/app/modules/payroll_batches/service.py`
- [Employee cache](https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/modules/employee_cache/service.py): cached read model · Local employee view used to avoid tight coupling to HR service · `payroll-ms/app/modules/employee_cache/service.py`
- [Payroll DB](https://github.com/whilmarbitoco/hrms-microservices/blob/main/payroll-ms/app/database/schema.py): persistence · Salary components, adjustments, batches, and payslip storage · `payroll-ms/app/database/schema.py`

### Integration

Cross-service test harness

- [E2E tests](https://github.com/whilmarbitoco/hrms-microservices/blob/main/tests/integration/runner.py): integration suite · Cross-service validation for HRMS flows · `tests/integration/runner.py`

## Connections

- 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
