gohorsejobs/backend/internal
Tiago Yamamoto 3a26af3df5 fix: global document and phone handling — remove Brazil-specific formatting
Frontend (jobs/new):
- Replace isValidCNPJ (checksum algorithm) with isValidDocument: accepts
  any tax document with 5–30 alphanumeric chars (CNPJ, EIN, VAT, etc.)
- Add cleanPhone(): strips formatting chars (dashes, spaces, parens) and
  keeps only digits + optional leading '+'; replaces cleanDigits+prepend
- Phone sent as '+5511999998888' if user typed '+55...', or '11999998888'
  if no country code was provided — no '+' blindly prepended anymore
- Company document sent stripped of all non-alphanumeric before API call
- Update label placeholder from '00.000.000/0000-00' to 'CNPJ, EIN, VAT...'
- Rename error key invalidCnpj → invalidDocument in all 3 locales (pt, en, es)

Backend (create_company use case):
- Add SanitizePhone() to utils/sanitizer.go: strips all non-digit chars
  except a leading '+'; '(11) 99999-8888' → '11999998888'
- Apply SanitizePhone to input.Phone before persisting to DB

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 12:46:54 -06:00
..
api feat: implement full auth system with HTTPOnly cookies + JWT, fix migrations to UUID v7, remove mock data from frontend 2026-02-16 05:20:46 -06:00
core fix: global document and phone handling — remove Brazil-specific formatting 2026-02-22 12:46:54 -06:00
database chore: commit pending changes 2026-02-15 16:03:40 +00:00
dto backend: suportar workMode em vagas e reforçar schema 2026-02-15 13:36:32 -03:00
handlers fix(jobs): enforce CreateJob validation and sanitize DB constraint errors 2026-02-22 12:26:14 -06:00
infrastructure fix: resolve remaining merge conflicts 2026-02-14 17:21:10 +00:00
middleware feat: implement full auth system with HTTPOnly cookies + JWT, fix migrations to UUID v7, remove mock data from frontend 2026-02-16 05:20:46 -06:00
models feat(backend): add missing storage routes and job datePosted support 2026-02-14 21:16:12 -03:00
router feat: implement full auth system with HTTPOnly cookies + JWT, fix migrations to UUID v7, remove mock data from frontend 2026-02-16 05:20:46 -06:00
services feat: implement full auth system with HTTPOnly cookies + JWT, fix migrations to UUID v7, remove mock data from frontend 2026-02-16 05:20:46 -06:00
utils fix: global document and phone handling — remove Brazil-specific formatting 2026-02-22 12:46:54 -06:00
README.md docs: complete project documentation overhaul 2025-12-09 19:36:36 -03:00

Internal - Backend Core

Este diretório contém toda a lógica interna do backend, seguindo princípios de Clean Architecture.


📁 Estrutura de Módulos

Diretório Camada Responsabilidade
api/ Interface Handlers e middlewares (Clean Arch)
core/ Domain Entidades, ports e use cases (DDD)
database/ Infrastructure Conexão GORM com PostgreSQL
dto/ Interface Data Transfer Objects (request/response)
handlers/ Interface Controllers HTTP (legacy)
infrastructure/ Infrastructure Implementações de ports
middleware/ Interface Middlewares de segurança
models/ Infrastructure Modelos GORM
router/ Interface Configuração de rotas
services/ Application Lógica de negócios (legacy)
utils/ Shared Utilitários (JWT, Sanitizer)

🏗️ Fluxo de Requisição

HTTP Request
     │
     ▼
┌─────────────┐
│ Middleware  │  (Auth, CORS, Rate Limit, Security Headers)
└─────────────┘
     │
     ▼
┌─────────────┐
│  Router     │  (router/router.go)
└─────────────┘
     │
     ▼
┌─────────────┐
│  Handler    │  (api/handlers/ ou handlers/)
└─────────────┘
     │
     ▼
┌─────────────┐
│  UseCase    │  (core/usecases/)
└─────────────┘
     │
     ▼
┌─────────────┐
│ Repository  │  (infrastructure/persistence/)
└─────────────┘
     │
     ▼
┌─────────────┐
│  Database   │  (PostgreSQL via GORM)
└─────────────┘

📦 Módulos Detalhados

api/

Implementação Clean Architecture dos handlers e middlewares.

  • handlers/ - Controllers HTTP novos
  • middleware/ - Auth com JWT Service

core/

Camada de domínio puro seguindo DDD.

  • domain/entity/ - Entidades sem dependências externas
  • ports/ - Interfaces de repositórios e serviços
  • usecases/ - Casos de uso (Login, CreateUser, etc.)

middleware/

Middlewares de segurança aplicados globalmente.

  • auth.go - Validação JWT + RBAC
  • cors.go - Whitelist de origens
  • rate_limit.go - 100 req/min por IP
  • security_headers.go - Headers OWASP

utils/

Utilitários compartilhados.

  • jwt.go - Geração e validação de tokens
  • sanitizer.go - Sanitização de inputs (XSS prevention)