# joaotux/pdv architecture

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

- Interactive diagram: https://gitdiagram.com/joaotux/pdv
- Repository: https://github.com/joaotux/pdv

## Overview

1. **Overall shape**
   - This is a Spring-based monolithic ERP/PDV application.
   - It follows a classic server-rendered MVC architecture: browser requests hit Spring controllers, which delegate to services, which call repositories, which persist to MySQL via Hibernate/JPA.

2. **Presentation layer**
   - The user interface is built with **Thymeleaf** templates under `src/main/resources/templates`.
   - Page fragments are organized by business area: venda, caixa, produto, pessoa, nota fiscal, tributação, usuário, etc.
   - Static assets live in `src/main/resources/static` and include CSS, JavaScript, masks/validation scripts, images, and icons.

3. **Web/API controllers**
   - Controllers under `net.originmobi.pdv.controller` are the main entry points for business features such as sales, cash register, payments, people, products, tax rules, user/group management, and reports.
   - The controllers are organized by domain rather than by technical layer, which makes each module relatively self-contained.
   - There is also a `relatorios` package with dedicated report controllers, separate from the CRUD-oriented controllers.

4. **Business/service layer**
   - The `service` package contains most of the business logic and orchestration.
   - Services typically sit between controllers and repositories and encapsulate domain operations like sales handling, cash movements, receivables/payables, product stock updates, user permissions, and invoice/tax processing.
   - A notable boundary is the **NFe/invoice subdomain**, which has its own service classes under `service/notafiscal`, indicating more specialized processing than standard CRUD.

5. **Persistence layer**
   - The `repository` package contains the data access interfaces for entities like `Produto`, `Venda`, `Caixa`, `Receber`, `Pagar`, `NotaFiscal`, `Usuario`, and many support tables.
   - There are dedicated repository subpackages for `cartao` and `notafiscal`, reflecting separate subdomains with their own persistence concerns.
   - The presence of Hibernate in the README and repository interfaces implies Spring Data JPA-style persistence over MySQL.

6. **Domain model**
   - The `model` package contains the core entities and relationships for the ERP: products, people, companies, addresses, tax configurations, sales, payments, cash movements, accounts payable/receivable, invoices, and card transactions.
   - The model is broad and business-heavy; it is not a thin CRUD schema.
   - Several related value-like entities and enumerations capture operational states such as sale status, cash movement type, product control flags, card status, and invoice type.

7. **Subdomain boundaries**
   - The code is split into business areas that map well to an architecture diagram:
     - **Venda**: sales and sold items
     - **Caixa**: cash register opening/closing and movements
     - **Pagar/Receber**: financial obligations and collections
     - **Cartão**: card terminals and card settlements
     - **Nota Fiscal**: invoice generation and tax composition
     - **Tributação**: tax rules and regimes
     - **Cadastro**: products, people, suppliers, categories, groups, users
   - These areas share infrastructure but keep their own controllers/services/repositories.

8. **Security and access control**
   - The `security` package contains Spring Security integration, including a custom `UserDetailsService` and a user principal wrapper.
   - Permissions are domain-driven: users belong to groups, and groups have permissions.
   - This means authorization is part of the business model, not just a technical add-on.

9. **Reporting and document generation**
   - Report generation is handled in the `relatorios` package, with `.jrxml` templates stored under `resources/relatorios`.
   - This suggests JasperReports-style PDF/report output for operational views like cash and sales reports.
   - XML/NFe support is also explicit in `xml/nfe`, where invoice XML generation, signing, and conversion are isolated from the rest of the app.

10. **Infrastructure and startup**
   - `PdvApplication.java` is the Spring Boot entry point.
   - Database schema initialization is managed with **Flyway** migrations in `resources/db/migration`, which means schema and seed data are versioned with the codebase.
   - `application.properties` is the main runtime configuration point, including MySQL connection settings.

11. **Supporting utilities and state**
   - `utilitarios` contains low-level helpers such as JDBC connection handling and date utilities.
   - `singleton/Aplicacao.java` suggests there is some globally shared application state or bootstrap context beyond standard Spring bean usage.
   - These are cross-cutting utilities rather than domain modules.

12. **Typical request/data flow**
   - A user action in a Thymeleaf page triggers a controller request.
   - The controller delegates to one or more services for validation and business rules.
   - Services load/update entities through repositories, often involving multiple related models such as sale + items + stock + cash movement.
   - Results are rendered back to the same server-side templates, or exported through report/XML generation paths.

13. **Notable architectural traits**
   - The repo is strongly business-domain oriented, with significant overlap between operational finance, sales, stock, and fiscal concerns.
   - It is a single deployable application rather than a distributed system.
   - The main architectural boundaries are by subdomain and by layer, with security, reporting, and fiscal document generation as important cross-cutting concerns.

Main entry points: [`src/main/java/net/originmobi/pdv/service`](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service) (Services), [`src/main/java/net/originmobi/pdv/repository`](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository) (Repositories), [`src/main/java/net/originmobi/pdv/controller`](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/controller) (MVC Layer), [`src/main/java/net/originmobi/pdv/model`](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/model) (Domain Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_presentation["Presentation"]
  node_n_web["MVC Layer<br/>web controllers"]
  node_n_templates["Thymeleaf<br/>server views"]
  node_n_static["Static UI<br/>assets"]
end

subgraph group_grp_domain["Domain"]
  node_n_services["Services"]
  node_n_sales["Venda<br/>sales service<br/>[VendaService.java]"]
  node_n_cash["Caixa<br/>cash service<br/>[CaixaService.java]"]
  node_n_finance["Finance<br/>accounts services"]
  node_n_tax["Fiscal<br/>tax services"]
  node_n_prod["Cadastro<br/>master data services"]
  node_n_models[("Domain Model<br/>entities")]
end

subgraph group_grp_persistence["Persistence"]
  node_n_repo["Repositories<br/>data access"]
  node_n_repo_nf["NFe Repos<br/>invoice repositories"]
  node_n_repo_cartao["Card Repos"]
end

subgraph group_grp_fiscal["Fiscal & Reports"]
  node_n_reports["Reports<br/>report controllers"]
  node_n_xml["NFe XML<br/>xml generation"]
end

subgraph group_grp_infra["Infrastructure"]
  node_n_app(("PdvApp<br/>Spring Boot entry"))
  node_n_security["Security<br/>auth config"]
  node_n_resources["Runtime Config<br/>config and migrations"]
  node_n_utils["Utilities<br/>shared helpers"]
end

node_n_app -->|"starts"| node_n_web
node_n_web -->|"renders"| node_n_templates
node_n_web -->|"delegates"| node_n_services
node_n_web -->|"opens reports"| node_n_reports
node_n_security -->|"protects"| node_n_web
node_n_services -->|"uses"| node_n_models
node_n_services -->|"persists via"| node_n_repo
node_n_services -->|"specializes"| node_n_tax
node_n_services -->|"coordinates"| node_n_finance
node_n_services -->|"manages"| node_n_prod
node_n_sales -->|"loads/saves"| node_n_repo
node_n_cash -->|"loads/saves"| node_n_repo
node_n_tax -->|"persists"| node_n_repo_nf
node_n_tax -->|"generates"| node_n_xml
node_n_finance -->|"persists via"| node_n_repo
node_n_prod -->|"persists via"| node_n_repo
node_n_models -->|"mapped by"| node_n_repo
node_n_repo -->|"initialized by"| node_n_resources
node_n_reports -->|"templates"| node_n_resources
node_n_security -->|"auth model"| node_n_models
node_n_utils -->|"supports"| node_n_services
node_n_web -->|"binds"| node_n_models
node_n_repo_cartao -->|"stores"| node_n_models

click node_n_app "https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/PdvApplication.java"
click node_n_web "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/controller"
click node_n_reports "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/relatorios"
click node_n_templates "https://github.com/joaotux/pdv/tree/master/src/main/resources/templates"
click node_n_static "https://github.com/joaotux/pdv/tree/master/src/main/resources/static"
click node_n_security "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/security"
click node_n_services "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service"
click node_n_sales "https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/service/VendaService.java"
click node_n_cash "https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/service/CaixaService.java"
click node_n_finance "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service"
click node_n_tax "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service/notafiscal"
click node_n_prod "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service"
click node_n_models "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/model"
click node_n_repo "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository"
click node_n_repo_nf "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository/notafiscal"
click node_n_repo_cartao "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository/cartao"
click node_n_xml "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/xml/nfe"
click node_n_resources "https://github.com/joaotux/pdv/tree/master/src/main/resources"
click node_n_utils "https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/utilitarios"

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_n_web,node_n_templates,node_n_static toneBlue
class node_n_services,node_n_sales,node_n_cash,node_n_finance,node_n_tax,node_n_prod,node_n_models toneAmber
class node_n_repo,node_n_repo_nf,node_n_repo_cartao toneMint
class node_n_reports,node_n_xml toneRose
class node_n_app,node_n_security,node_n_resources,node_n_utils toneIndigo
```

## Components

### Presentation

Server-rendered MVC UI, controllers, and static assets

- [MVC Layer](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/controller): web controllers · Primary Spring MVC entry points for business features · `src/main/java/net/originmobi/pdv/controller`
- [Thymeleaf](https://github.com/joaotux/pdv/tree/master/src/main/resources/templates): server views · Rendered pages and fragments organized by business area · `src/main/resources/templates`
- [Static UI](https://github.com/joaotux/pdv/tree/master/src/main/resources/static): assets · CSS, JavaScript, images, and client-side validation helpers · `src/main/resources/static`

### Domain

Core business services and entities

- [Services](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service): business services · Domain orchestration and business rules across sales, finance, stock, and users · `src/main/java/net/originmobi/pdv/service`
- [Venda](https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/service/VendaService.java): sales service · Sale lifecycle, sold items, and stock-linked sales processing · `src/main/java/net/originmobi/pdv/service/VendaService.java`
- [Caixa](https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/service/CaixaService.java): cash service · Cash register opening, closing, and movements · `src/main/java/net/originmobi/pdv/service/CaixaService.java`
- [Finance](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service): accounts services · Payables, receivables, installments, and transfers · `src/main/java/net/originmobi/pdv/service`
- [Fiscal](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service/notafiscal): tax services · Tributação, CFOP, regime, and invoice tax composition · `src/main/java/net/originmobi/pdv/service/notafiscal`
- [Cadastro](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/service): master data services · Products, people, companies, categories, images, and related registries · `src/main/java/net/originmobi/pdv/service`
- [Domain Model](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/model): entities · Business entities for sales, finance, tax, users, and invoices · `src/main/java/net/originmobi/pdv/model`

### Persistence

Spring Data repositories and database access

- [Repositories](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository): data access · Spring Data repositories for JPA persistence · `src/main/java/net/originmobi/pdv/repository`
- [NFe Repos](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository/notafiscal): invoice repositories · Dedicated persistence for fiscal document subdomain · `src/main/java/net/originmobi/pdv/repository/notafiscal`
- [Card Repos](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/repository/cartao): card repositories · Persistence for card settlement and machine data · `src/main/java/net/originmobi/pdv/repository/cartao`

### Fiscal & Reports

Invoice/XML/report generation and special fiscal workflows

- [Reports](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/relatorios): report controllers · Dedicated report endpoints and generation orchestration · `src/main/java/net/originmobi/pdv/relatorios`
- [NFe XML](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/xml/nfe): xml generation · Invoice XML creation, signing, and conversion utilities · `src/main/java/net/originmobi/pdv/xml/nfe`

### Infrastructure

Security, bootstrap, shared utilities, and startup

- [PdvApp](https://github.com/joaotux/pdv/blob/master/src/main/java/net/originmobi/pdv/PdvApplication.java): Spring Boot entry · Application bootstrap and main entry point · `src/main/java/net/originmobi/pdv/PdvApplication.java`
- [Security](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/security): auth config · Spring Security integration and user principal handling · `src/main/java/net/originmobi/pdv/security`
- [Runtime Config](https://github.com/joaotux/pdv/tree/master/src/main/resources): config and migrations · Application properties, Flyway migrations, and report templates · `src/main/resources`
- [Utilities](https://github.com/joaotux/pdv/tree/master/src/main/java/net/originmobi/pdv/utilitarios): shared helpers · JDBC and date helpers plus shared singleton state · `src/main/java/net/originmobi/pdv/utilitarios`

## Connections

- PdvApp → MVC Layer: starts · Bootstraps the MVC application and request handling
- MVC Layer → Thymeleaf: renders · Controllers return Thymeleaf views
- MVC Layer → Services: delegates · Web layer hands off business operations to services
- MVC Layer → Reports: opens reports · Report endpoints trigger document generation
- Security → MVC Layer: protects · Secures controller access through Spring Security
- Services → Domain Model: uses · Services orchestrate the core entities
- Services → Repositories: persists via · Business logic reads and writes through repositories
- Services → Fiscal: specializes · Fiscal services handle invoice and tax workflows
- Services → Finance: coordinates · Finance workflows span receivables, payables, and transfers
- Services → Cadastro: manages · Master data services maintain catalog and registry data
- Venda → Repositories: loads/saves · Sale processing persists sales and items
- Caixa → Repositories: loads/saves · Cash movements and register state are persisted
- Fiscal → NFe Repos: persists · Invoice persistence is isolated in the fiscal repository set
- Fiscal → NFe XML: generates · Invoice services feed XML signing and conversion
- Finance → Repositories: persists via · Accounts and transfers use the shared data layer
- Cadastro → Repositories: persists via · Product and registry services use repositories
- Domain Model → Repositories: mapped by · Entities are the JPA persistence model
- Repositories → Runtime Config: initialized by · Schema and seed data come from Flyway migrations
- Reports → Runtime Config: templates · Report layouts are stored as JRXML resources
- Security → Domain Model: auth model · Users, groups, and permissions are part of the domain model
- Utilities → Services: supports · Cross-cutting helpers are used across business logic
- MVC Layer → Domain Model: binds · Controllers bind form data to domain entities
- Card Repos → Domain Model: stores · Card settlement data is persisted through dedicated repositories
