How gustavo4681501/porceramica-hrms works
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: services Services · main.py API Entry · App.jsx React App · api API Client
Components 20
Frontend SPA
React/Vite client for admin and employee self-service
- React App · Main Vite-powered single-page application
frontend/src/App.jsx - Pages · Role-specific screens for dashboard, HR workflows, and self-service
frontend/src/pages - UI Components · Reusable dialogs, layout, and payroll modals
frontend/src/components - Auth Context · Client-side session and auth state
frontend/src/context/AuthContext.jsx - API Client · Thin frontend wrapper around backend endpoints
frontend/src/api
Backend API
FastAPI application with layered domain modules
- API Entry · Application bootstrap and router wiring
backend/app/main.py - Auth Layer · Login, token handling, and role checks
backend/app/routers/auth.py - Employees · Employee records and management workflows
backend/app/routers/employees.py - Payroll · Payroll drafts, runs, and finalization
backend/app/routers/payroll.py - Vacations · Vacation requests and approvals
backend/app/routers/vacations.py - Loans · Employee loan balances and deductions
backend/app/routers/loans.py - Reports · Cross-domain summaries and dashboard data
backend/app/routers/reports.py - Services · Domain orchestration for HR and payroll flows
backend/app/services - Models · Database entities for users and HR records
backend/app/models - Schemas · Request and response validation models
backend/app/schemas - Core · Config, database, security, and exceptions
backend/app/core - Utils · Payroll calculation, PDFs, and email delivery
backend/app/utils
Runtime & Data
Compose services and persistent/external infrastructure
- PostgreSQL · Primary relational persistence store
docker-compose.yml - MailCatcher · Local outbound email inspection service
docker-compose.yml - Seed Data · Initial database population and reset lifecycle
backend/seed.py
Connections 25
- 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