# gustavo4681501/porceramica-hrms architecture

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

- Interactive diagram: https://gitdiagram.com/gustavo4681501/porceramica-hrms
- Repository: https://github.com/gustavo4681501/porceramica-hrms

## Overview

1. **Overall shape**
   - This repository is a **full-stack HR and payroll system** built as a modular monolith.
   - It is split into a **FastAPI backend** and a **React/Vite frontend**, deployed together through **Docker Compose**.
   - The system centers on replacing a payroll Excel workflow with a database-backed, role-based application.

2. **Runtime and deployment boundaries**
   - `docker-compose.yml` orchestrates the main runtime dependencies: **frontend**, **backend**, **PostgreSQL**, and **MailCatcher** for email inspection.
   - The backend exposes the API on `:8000`; the frontend is served on `:3000`; MailCatcher is available on `:1080`.
   - The README indicates a seed/reset lifecycle, so initial state is managed as part of deployment rather than left to manual setup.

3. **Frontend architecture**
   - The frontend is a **React SPA** using **Vite** and **Tailwind CSS**.
   - `src/pages` contains the business screens: employees, payroll, vacations, loans, recruitment, training, disciplinary actions, dashboard, and employee self-service pages.
   - `src/components` contains reusable UI dialogs and modals, especially for payroll and employee management.
   - `src/context/AuthContext.jsx` suggests centralized session/auth state on the client.
   - `src/api/*` is a thin API client layer, separating UI from backend endpoint details.

4. **Backend application structure**
   - The backend follows a layered FastAPI structure:
     - **routers** expose HTTP endpoints,
     - **services** implement business logic,
     - **models** define database entities,
     - **schemas** define request/response contracts,
     - **core** contains config, database setup, security, and exception handling,
     - **utils** hosts cross-cutting domain helpers such as payroll calculation, PDF generation, and email.
   - This separation is important: the routers stay thin, while business rules live in services and utilities.

5. **Core infrastructure and cross-cutting concerns**
   - `core/database.py` and the model layer indicate a relational persistence boundary, with PostgreSQL as the backing store.
   - `core/security.py` and `routers/auth.py`/`services/auth_service.py` implement authentication, likely with **JWT-based login** and role checks.
   - `core/exceptions.py` centralizes API error behavior, which helps keep error responses consistent across domains.
   - `core/config.py` holds environment-driven settings, which is typical for Dockerized deployment.

6. **Domain modules**
   - The repository is organized around HR/payroll domains:
     - **employees**: core employee records and related UI.
     - **payroll / payroll_draft**: periodic payroll calculation, review, and finalization.
     - **vacations**: requests, approvals, and employee self-service.
     - **loans**: employee loan deductions and balances.
     - **recruitment**: candidate pipeline and onboarding-related workflows.
     - **training**: training records and plans.
     - **disciplinary**: disciplinary incidents and tracking.
   - Each of these domains appears in all three layers: model, schema, router, and service, which implies a consistent bounded-context style inside one backend.

7. **Payroll is the main business engine**
   - The most specialized logic lives in `utils/payroll_engine.py`, which the README describes as extracted from the original Excel rules.
   - This engine computes gross and net payroll using salary, worked days, overtime multipliers, holiday pay, CCSS deductions, loan deductions, and other adjustments.
   - `services/payroll_service.py` and `services/payroll_draft_service.py` likely orchestrate the calculation lifecycle: draft creation, validation, finalization, and persistence.
   - `utils/payroll_pdf.py` generates payroll receipts, making payroll both a calculation subsystem and a document-generation subsystem.

8. **Notifications and external side effects**
   - `utils/email.py` and the README’s MailCatcher workflow indicate outbound email is part of the payroll delivery path.
   - The generated PDF is attached to payroll emails, so document generation and email sending are coupled in the payroll reporting flow.
   - MailCatcher is used as a local-only external service for safe inspection of outbound mail during development and testing.

9. **Approval workflow and employee self-service**
   - Vacations are a multi-step approval flow: employee request, optional direct manager approval, then HR final approval.
   - The frontend has dedicated employee-facing pages such as `MyVacations`, `MyLoans`, and `MyPayroll`, which indicates a self-service portal distinct from admin/HR screens.
   - This creates a clear role boundary: employees can view and request; admins/RRHH can approve and manage records.

10. **Reporting and analytics**
   - `routers/reports.py` and `services/report_service.py` provide cross-domain summaries rather than a single business entity.
   - The dashboard likely aggregates data from employees, payroll, vacations, and loans for operational visibility.
   - The repo also includes a `docs/indicador-rotacion.md` file, suggesting some reporting metrics are documented separately from the code.

11. **Data model and persistence**
   - The backend models cover users plus HR entities such as employees, payroll, payroll drafts, loans, vacations, recruitment, training, and disciplinary records.
   - `models/enums.py` indicates shared domain states and role/status values are normalized rather than duplicated.
   - The presence of `seed.py` and the README’s import from an Excel source show the database is initialized with real domain data and test users, not just empty schema.

12. **Authentication and role model**
   - The system supports at least three roles: **Administrator**, **RRHH**, and **Employee**.
   - Role separation affects both API access and UI surfaces, with administrative screens for management and employee-facing screens for personal records.
   - The login flow is isolated in the auth router/service and consumed by the frontend auth context.

13. **End-to-end data flow**
   - A typical flow starts in the React UI, which calls the FastAPI API through the frontend API client layer.
   - The router validates the request schema, delegates to the service, which reads/writes database models and may call utility modules for calculation, PDF generation, or email.
   - Final outputs are returned to the frontend as JSON, while side effects such as emails and PDFs happen in the backend boundary.

14. **What matters most for an architecture diagram**
   - Show three main zones: **frontend SPA**, **backend API/service layer**, and **PostgreSQL + MailCatcher infrastructure**.
   - Inside the backend, emphasize the separation between **HTTP routers**, **domain services**, **ORM models**, and **shared utilities**.
   - The most important flows are:
     - login/authentication,
     - employee CRUD and self-service,
     - payroll calculation and receipt delivery,
     - vacation approval,
     - reporting/dashboard aggregation,
     - seed/reset bootstrap from Excel-derived data.

Main entry points: [`backend/app/services`](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/services) (Services), [`backend/app/main.py`](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/main.py) (API Entry), [`frontend/src/App.jsx`](https://github.com/gustavo4681501/porceramica-hrms/blob/main/frontend/src/App.jsx) (React App), [`frontend/src/api`](https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/api) (API Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["React App<br/>spa<br/>[App.jsx]"]
  node_frontend_pages["Pages<br/>ui screens"]
  node_frontend_components["UI Components<br/>shared ui"]
  node_frontend_auth(("Auth Context<br/>client state<br/>[AuthContext.jsx]"))
  node_frontend_api["API Client<br/>http client"]
end

subgraph group_backend["Backend API"]
  node_backend_main["API Entry<br/>fastapi app<br/>[main.py]"]
  node_backend_auth["Auth Layer<br/>auth service<br/>[auth.py]"]
  node_backend_employees["Employees<br/>hr domain<br/>[employees.py]"]
  node_backend_payroll["Payroll<br/>[payroll.py]"]
  node_backend_vacations["Vacations<br/>workflow domain<br/>[vacations.py]"]
  node_backend_loans["Loans<br/>hr domain<br/>[loans.py]"]
  node_backend_reports["Reports<br/>analytics<br/>[reports.py]"]
  node_backend_services["Services<br/>business logic"]
  node_backend_models[("Models<br/>orm entities")]
  node_backend_schemas["Schemas<br/>contracts"]
  node_backend_core["Core<br/>infrastructure"]
  node_backend_utils["Utils<br/>shared logic"]
end

subgraph group_infra["Runtime & Data"]
  node_infra_db[("PostgreSQL<br/>database<br/>[docker-compose.yml]")]
  node_infra_mail["MailCatcher<br/>mail service<br/>[docker-compose.yml]"]
  node_infra_seed["Seed Data<br/>bootstrap<br/>[seed.py]"]
end

node_frontend_app -->|"renders"| node_frontend_pages
node_frontend_app -->|"uses"| node_frontend_components
node_frontend_app -->|"reads session"| node_frontend_auth
node_frontend_pages -->|"calls"| node_frontend_api
node_frontend_auth -->|"auth header"| node_frontend_api
node_frontend_api -->|"HTTP"| node_backend_main
node_backend_main -->|"mounts"| node_backend_auth
node_backend_main -->|"mounts"| node_backend_employees
node_backend_main -->|"mounts"| node_backend_payroll
node_backend_main -->|"mounts"| node_backend_vacations
node_backend_main -->|"mounts"| node_backend_loans
node_backend_main -->|"mounts"| node_backend_reports
node_backend_auth -->|"delegates"| node_backend_services
node_backend_employees -->|"delegates"| node_backend_services
node_backend_payroll -->|"delegates"| node_backend_services
node_backend_vacations -->|"delegates"| node_backend_services
node_backend_loans -->|"delegates"| node_backend_services
node_backend_reports -->|"aggregates"| node_backend_services
node_backend_services -->|"persists"| node_backend_models
node_backend_services -->|"validates"| node_backend_schemas
node_backend_services -->|"uses"| node_backend_utils
node_backend_utils -->|"sends mail"| node_infra_mail
node_backend_core -->|"connects"| node_infra_db
node_backend_models -->|"stores"| node_infra_db
node_infra_seed -->|"loads"| node_infra_db

click node_frontend_app "https://github.com/gustavo4681501/porceramica-hrms/blob/main/frontend/src/App.jsx"
click node_frontend_pages "https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/pages"
click node_frontend_components "https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/components"
click node_frontend_auth "https://github.com/gustavo4681501/porceramica-hrms/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_api "https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/api"
click node_backend_main "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/main.py"
click node_backend_auth "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/auth.py"
click node_backend_employees "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/employees.py"
click node_backend_payroll "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/payroll.py"
click node_backend_vacations "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/vacations.py"
click node_backend_loans "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/loans.py"
click node_backend_reports "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/reports.py"
click node_backend_services "https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/services"
click node_backend_models "https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/models"
click node_backend_schemas "https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/schemas"
click node_backend_core "https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/core"
click node_backend_utils "https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/utils"
click node_infra_db "https://github.com/gustavo4681501/porceramica-hrms/blob/main/docker-compose.yml"
click node_infra_mail "https://github.com/gustavo4681501/porceramica-hrms/blob/main/docker-compose.yml"
click node_infra_seed "https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/seed.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_frontend_app,node_frontend_pages,node_frontend_components,node_frontend_auth,node_frontend_api toneBlue
class node_backend_main,node_backend_auth,node_backend_employees,node_backend_payroll,node_backend_vacations,node_backend_loans,node_backend_reports,node_backend_services,node_backend_models,node_backend_schemas,node_backend_core,node_backend_utils toneAmber
class node_infra_db,node_infra_mail,node_infra_seed toneMint
```

## Components

### Frontend SPA

React/Vite client for admin and employee self-service

- [React App](https://github.com/gustavo4681501/porceramica-hrms/blob/main/frontend/src/App.jsx): spa · Main Vite-powered single-page application · `frontend/src/App.jsx`
- [Pages](https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/pages): ui screens · Role-specific screens for dashboard, HR workflows, and self-service · `frontend/src/pages`
- [UI Components](https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/components): shared ui · Reusable dialogs, layout, and payroll modals · `frontend/src/components`
- [Auth Context](https://github.com/gustavo4681501/porceramica-hrms/blob/main/frontend/src/context/AuthContext.jsx): client state · Client-side session and auth state · `frontend/src/context/AuthContext.jsx`
- [API Client](https://github.com/gustavo4681501/porceramica-hrms/tree/main/frontend/src/api): http client · Thin frontend wrapper around backend endpoints · `frontend/src/api`

### Backend API

FastAPI application with layered domain modules

- [API Entry](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/main.py): fastapi app · Application bootstrap and router wiring · `backend/app/main.py`
- [Auth Layer](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/auth.py): auth service · Login, token handling, and role checks · `backend/app/routers/auth.py`
- [Employees](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/employees.py): hr domain · Employee records and management workflows · `backend/app/routers/employees.py`
- [Payroll](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/payroll.py): payroll domain · Payroll drafts, runs, and finalization · `backend/app/routers/payroll.py`
- [Vacations](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/vacations.py): workflow domain · Vacation requests and approvals · `backend/app/routers/vacations.py`
- [Loans](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/loans.py): hr domain · Employee loan balances and deductions · `backend/app/routers/loans.py`
- [Reports](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/app/routers/reports.py): analytics · Cross-domain summaries and dashboard data · `backend/app/routers/reports.py`
- [Services](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/services): business logic · Domain orchestration for HR and payroll flows · `backend/app/services`
- [Models](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/models): orm entities · Database entities for users and HR records · `backend/app/models`
- [Schemas](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/schemas): contracts · Request and response validation models · `backend/app/schemas`
- [Core](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/core): infrastructure · Config, database, security, and exceptions · `backend/app/core`
- [Utils](https://github.com/gustavo4681501/porceramica-hrms/tree/main/backend/app/utils): shared logic · Payroll calculation, PDFs, and email delivery · `backend/app/utils`

### Runtime & Data

Compose services and persistent/external infrastructure

- [PostgreSQL](https://github.com/gustavo4681501/porceramica-hrms/blob/main/docker-compose.yml): database · Primary relational persistence store · `docker-compose.yml`
- [MailCatcher](https://github.com/gustavo4681501/porceramica-hrms/blob/main/docker-compose.yml): mail service · Local outbound email inspection service · `docker-compose.yml`
- [Seed Data](https://github.com/gustavo4681501/porceramica-hrms/blob/main/backend/seed.py): bootstrap · Initial database population and reset lifecycle · `backend/seed.py`

## Connections

- React App → Pages: renders · App routes to business screens
- React App → UI Components: uses · Shared UI building blocks
- React App → Auth Context: reads session · Client auth state drives access and role UI
- Pages → API Client: calls · Screens fetch and mutate data through API client
- Auth Context → API Client: auth header · Auth context feeds authenticated requests
- API Client → API Entry: HTTP · Frontend talks to FastAPI endpoints
- API Entry → Auth Layer: mounts · Auth router is part of the API surface
- API Entry → Employees: mounts · Employee endpoints
- API Entry → Payroll: mounts · Payroll endpoints
- API Entry → Vacations: mounts · Vacation workflow endpoints
- API Entry → Loans: mounts · Loan endpoints
- API Entry → Reports: mounts · Reporting endpoints
- Auth Layer → Services: delegates · Auth logic is implemented in services
- Employees → Services: delegates · Employee router stays thin
- Payroll → Services: delegates · Payroll orchestration lives in services
- Vacations → Services: delegates · Approval workflow logic lives in services
- Loans → Services: delegates · Loan business rules live in services
- Reports → Services: aggregates · Reports combine multiple domain sources
- Services → Models: persists · Services read and write ORM entities
- Services → Schemas: validates · Services consume contract models from routers
- Services → Utils: uses · Shared calculation, PDF, and email helpers
- Utils → MailCatcher: sends mail · Email delivery is inspected via MailCatcher
- Core → PostgreSQL: connects · Database session and settings point to PostgreSQL
- Models → PostgreSQL: stores · ORM entities persist into PostgreSQL
- Seed Data → PostgreSQL: loads · Initial data and reset lifecycle populate the database
