How mik3si7va/baths works
1. What this repo is
- The main system is a clinic/spa management platform for banhos e tosquias.
- It is split into three cooperating runtimes: a React frontend, a Node/Express + Prisma backend, and a Camunda 7 workflow layer with external-task workers.
- The operational focus is on clientes/animais, agendamentos, faturação, salas, serviços, funcionários, and contas/auth.
2. Top-level runtime topology
- docker-compose.yml and the root npm scripts orchestrate the local stack.
- The backend talks to Postgres through Prisma.
- Camunda runs separately and is deployed with BPMN definitions from camunda/workflows/.
- The frontend runs as a browser SPA and consumes the backend REST API.
- The repo’s local flow is: browser → frontend → backend/API → Postgres, with Camunda/workers handling the process orchestration side path.
3. Backend architecture
- The backend lives in backend/ and is a classic Express REST API.
- backend/src/server.js is the main entry point, exposing the HTTP routes and Swagger docs.
- backend/src/repositories/ is the main boundary to persistence; each repository encapsulates a business area such as agendamentos, clientes, contas, faturas, funcionários, salas, serviços, perfil, auth, and Camunda integration.
- backend/src/domain/ contains shared business concepts: entities and enums like Sala, TipoServico, RegraPreco, DiaSemanaEnum, PorteEnum, and TipoFuncionarioEnum.
- backend/src/services/emailService.js is the outbound email boundary used for invitation/password-reset style communication.
4. Persistence and database lifecycle
- Persistence is Postgres + Prisma.
- backend/prisma/schema.prisma, migrations, and seed.js define the data model and bootstrap data.
- The README and migration history show a mature schema that has evolved around:
- users/funcionários/auth
- clientes and animais
- agendamentos and their state transitions
- pagamentos and faturas
- salas, serviços, and pricing rules
- password reset tokens
- Database setup is intentionally scripted (db:full, migrations, seed), which means the architecture expects a reproducible local/CI database state rather than ad hoc manual setup.
5. Workflow orchestration with Camunda
- The critical business flows are not implemented only in the API; they are orchestrated in Camunda BPMN.
- Main workflows are in camunda/workflows/, notably:
- agendamento.bpmn
- gestao_agendamento.bpmn
- subprocesses for service preparation, solution generation, reservation handling, and invoicing
- a DMN file for service ordering
- This makes workflow state a first-class architectural concern: the system separates business process orchestration from pure CRUD persistence.
6. Camunda worker layer
- camunda/workers/ implements external task workers.
- The workers/ subfolders are organized by process area: agendamento, reservas, fatura, email, solucoes, precoEServico.
- Each worker file is numbered to mirror BPMN execution order, which makes the diagramming relationship between BPMN steps and implementation explicit.
- Worker services in camunda/workers/services/ encapsulate domain logic and DB access; they are the bridge between process tasks and the application data model.
- Supporting utilities handle Camunda client communication, DB access, logging, and scheduling/horário logic.
7. Frontend architecture
- The root frontend/ is a React SPA (Create React App style structure).
- The UI is organized by feature pages under frontend/src/pages/:
- home, login, perfil
- clientes, contas, funcionários
- agendamentos, calendar
- faturas, salas, serviços, pesquisa, password recovery
- Shared UI lives in frontend/src/components/ and frontend/src/layouts/.
- frontend/src/routes.jsx is the route map and contains the access-control boundaries.
8. Authentication, session, and role boundaries
- The frontend has an AuthContext and guarded routes (PrivateRoute / admin guards in the route layer).
- The README says the authenticated session is stored in localStorage.
- There are distinct roles in the system, at least administrador and funcionário, and the frontend routes reflect that separation.
- Account management is not just login/logout: /contas also supports invitation flows that create password-definition tokens and email them to staff.
9. User-facing data flows
- CRUD-heavy flows such as clientes, animais, salas, serviços, funcionários, and faturas are driven from the React pages to the backend REST API.
- Scheduling is the most workflow-heavy path: the UI initiates a booking, Camunda coordinates reservation/validation/solution steps, and the backend persists the resulting state.
- Faturação has a similar split: the process layer coordinates invoice generation and payment registration, while the backend/database hold the persisted business record.
- The frontend includes helper utilities for calendar presentation, client filtering, and Camunda-related UI support.
10. Notifications and email
- Email is an outbound integration point from the backend and from workflow workers.
- The README shows SMTP/Mailtrap-style configuration and a DISABLE_EMAILS switch for local development.
- This is used especially for invitation emails and workflow notifications such as confirmations, cancellations, reschedules, no-shows, and invoice delivery.
11. Testing and quality gates
- The backend uses Jest with both repository tests and API tests against a real database.
- The frontend uses Jest + Testing Library for isolated component/page tests.
- There is also Cypress coverage in the frontend for at least the salas flow.
- CI is GitHub Actions with separate lint/test/build stages for backend and frontend, which means the repo treats both halves as independently verifiable deliverables.
12. Secondary subtree
- AppClient/ is a smaller, separate backend/frontend pair with its own minimal auth-focused React app and server.
- It looks like a pared-down or legacy client stack rather than the main product architecture described by the README.
- If you draw the architecture for the active system, keep the root-level backend/, frontend/, and camunda/ as the primary diagram and treat AppClient/ as an auxiliary/older subtree unless you specifically need to document it.
Main entry points: server.js API server · repositories Repositories · docker-compose.yml Compose · routes.jsx Route map
Components 21
Main stack
Primary clinic/spa management system
- Compose · Local stack and service startup
docker-compose.yml
Backend API
Express + Prisma service
- API server · HTTP server and route wiring
backend/src/server.js - Repositories · Business-area repositories for CRUD and integration
backend/src/repositories - Domain model · Shared entities and enums for core clinic concepts
backend/src/domain - Prisma DB · Schema, migrations, seed, and DB lifecycle
backend/prisma - Email service · SMTP-style email boundary for invites and notifications
backend/src/services/emailService.js
Workflow layer
Camunda BPMN and external-task workers
- BPMN flows · Scheduling and invoicing process models
camunda/workflows - DMN rules · Service ordering and related workflow decisions
camunda/workflows/ordenar_servicos.dmn - Workers · Worker runtime entry and process subscriptions
camunda/workers/index.js - Booking tasks · Creates and updates agendamento state across process steps
camunda/workers/workers/agendamento - Reservation tasks · Temporary and process reservations plus availability checks
camunda/workers/workers/reservas - Invoice tasks · Invoice generation and payment registration
camunda/workers/workers/fatura - Email tasks · Workflow-driven confirmation, cancellation, and invoice emails
camunda/workers/workers/email - Solution tasks · Generates and orders candidate scheduling solutions
camunda/workers/workers/solucoes - Pricing tasks · Builds service lists and price/duration summaries
camunda/workers/workers/precoEServico
Frontend SPA
React client application
- Route map · Access control and page navigation boundaries
frontend/src/routes.jsx - Auth context · LocalStorage-backed session and protected routes
frontend/src/contexts - Feature pages · Customers, appointments, invoices, rooms, services, accounts, profile
frontend/src/pages - Shared UI · Reusable dialogs, cards, calendar and forms
frontend/src/components - UI helpers · Calendar, client filtering, and Camunda helper utilities
frontend/src/utils
Auxiliary client
Smaller legacy or secondary app
- AppClient · Smaller secondary client stack with its own frontend/backend
AppClient
Connections 23
- Compose → API server: starts · Launches backend service in the local stack
- Compose → Workers: starts · Launches workflow worker runtime
- Compose → Route map: starts · Launches browser SPA
- API server → Repositories: uses · Routes delegate persistence and business operations
- API server → Domain model: shares model · API uses common business types and enums
- API server → Email service: sends mail · Invitations and password/reset notifications
- Repositories → Prisma DB: persists to · Repositories read and write Prisma/Postgres data
- Domain model → Prisma DB: migrates to · Domain concepts are reflected in the database schema
- Route map → Auth context: guards · Route access is filtered by auth state and role
- Route map → Feature pages: routes to · Maps URLs to feature pages
- Feature pages → Shared UI: composes · Pages reuse shared UI primitives
- Feature pages → UI helpers: uses · Pages rely on calendar and filtering helpers
- Auth context → API server: calls API · Authenticated UI consumes REST endpoints
- API server → Workers: integrates · Backend exposes data and task integration points for workflows
- Workers → BPMN flows: executes · Workers subscribe to BPMN external tasks
- BPMN flows → DMN rules: consults · Workflow decisions use service-ordering rules
- Booking tasks → Repositories: writes agendamentos · Booking process persists scheduling state
- Reservation tasks → Repositories: checks rooms · Reservation tasks validate and release availability
- Invoice tasks → Repositories: writes faturas · Invoicing process persists billing records
- Email tasks → Email service: delivers · Workflow notifications use outbound mail integration
- Solution tasks → Pricing tasks: depends on · Solution generation uses pricing/duration summaries
- Pricing tasks → Repositories: reads services · Price and service workers consult persisted catalog data
- AppClient → API server: separate stack · Secondary app is distinct from the main product architecture