CopilotGitHubcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>rmcampos
2ed9969f33 Prevent duplicate Customer and POS creation (#49)
* Initial plan

* Prevent duplicate Customer and POS creation

- Backend: Check for duplicate name (case-insensitive) and phone on Customer create/update
- Backend: Check for duplicate phone on CustomerPos create/update
- All uniqueness checks are wrapped in Prisma transactions with throw/catch pattern
- Soft-deleted records (disabledAt != null) are excluded from checks
- Returns 409 Conflict with specific field error messages
- Frontend: Show backend error message directly in customer save toast

* Address code review feedback: use helper, fix disabledAt filter, standardize error handling

- Extract conflictError() helper to avoid repeated Object.assign pattern
- Fix document duplicate check to also filter by disabledAt: null (consistent with name/phone)
- Standardize all POS routes to use try-catch instead of .catch()

* Add missing document check on Customer create and address check on CustomerPos create/update

- Customer POST: explicitly check for duplicate document inside transaction
- CustomerPos POST/PUT: add address uniqueness check (case-insensitive) alongside phone check
- All checks respect soft-delete (disabledAt: null)

* feat: filter customer address

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Ricardo Campos <ricardompcampos@gmail.com>
2026-05-27 09:51:06 -03:00

Polpa Gestão

A full-stack business management web application for managing customers, points-of-sale (POS), products, sales, and delivery routes.

Features

Customer & POS Management

Manage your customer database including personal and business details (CPF/CNPJ), phone numbers, and multiple points-of-sale per customer. Each customer can have one or more POS locations, making it easy to track deliveries to different addresses.

Products

Maintain a product catalog with pricing, cost, and stock information. Products are linked to sales so inventory levels are always up to date.

Sales

Record and track sales transactions with support for delivery status, payment methods, due dates, and additional comments. Each sale can include multiple products, and the status can be updated as orders are processed and delivered.

Routes

Define delivery routes organized by day of the week and assign customer POS locations to them. This makes it easy to plan and track distribution for each day.

Dashboard & Authentication

A dashboard provides analytics and reporting. The application includes user management with role-based access control secured by JWT authentication.

Tech Stack

Layer Technology
Frontend React 19, TypeScript, Vite, Bootstrap 5
Backend Node.js 22, Fastify 5, TypeScript
Database PostgreSQL 15 with Prisma ORM
Containerization Docker, Docker Compose
CI/CD GitHub Actions → GitHub Container Registry
Deployment Terraform

Running Locally with Docker

The entire application stack (database, backend API, and frontend) can be started with a single command using Docker Compose.

Prerequisites: Docker and Docker Compose installed.

Start all services:

docker compose up

This command will:

  1. Start a PostgreSQL 15 database on port 5432
  2. Run Prisma migrations automatically to set up the database schema
  3. Start the Fastify backend API on port 3000
  4. Start the React frontend (via Nginx) on port 5173

Access the application:

Service URL
Frontend http://localhost:5173
Backend API http://localhost:3000
Database localhost:5432 (user: admin, password: adminpassword, db: polpa_gestao)

Optional environment variables:

To enable CPF/CNPJ document validation and POS geocoding, set these variables before starting:

VITE_CPF_CNPJ_API_TOKEN=your_token_here \
VITE_GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here \
GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here \
docker compose up

Stop all services:

docker compose down

Database data is persisted in a Docker volume (pgdata) and will survive container restarts. To also remove the volume when stopping, run docker compose down -v.

Deployment

The application is deployed using Terraform. The infrastructure-as-code configuration can be found in the following public repository:

https://github.com/RMCampos/personal-projects-iaac/blob/main/polpa-gestao/main.tf

Docker images are built and published to the GitHub Container Registry automatically via GitHub Actions on every push:

  • ghcr.io/rmcampos/polpa-gestao/backend:latest
  • ghcr.io/rmcampos/polpa-gestao/frontend:latest
S
Description
[k3s] Node.js fullstack REST+App for managing a small business
Readme
2.6 MiB
Languages
TypeScript 96.1%
HCL 1.5%
CSS 1.3%
Shell 0.5%
Dockerfile 0.3%
Other 0.3%