- Add comprehensive root README with badges, architecture diagram, and setup guide - Update backend README with security middlewares and endpoint documentation - Update frontend README with design system and page structure - Update seeder-api README with generated data and credentials - Add internal module READMEs (middleware, handlers, components) - Document Clean Architecture layers and request flow - Add environment variables reference table
128 lines
3.5 KiB
Markdown
Executable file
128 lines
3.5 KiB
Markdown
Executable file
# Backend - GoHorse Jobs API
|
|
|
|
[](https://golang.org/)
|
|
[](https://postgresql.org/)
|
|
|
|
API REST desenvolvida em Go seguindo princípios de **Clean Architecture** e **DDD**.
|
|
|
|
---
|
|
|
|
## 🏗️ Arquitetura
|
|
|
|
```
|
|
internal/
|
|
├── api/ # Clean Architecture Layer
|
|
│ ├── handlers/ # HTTP Handlers (Controllers)
|
|
│ └── middleware/ # Auth, CORS, Rate Limiting
|
|
│
|
|
├── core/ # Domain Layer (DDD)
|
|
│ ├── domain/entity/ # Entidades puras (sem deps externas)
|
|
│ ├── ports/ # Interfaces (Repository, Service)
|
|
│ └── usecases/ # Casos de uso (Business Logic)
|
|
│
|
|
├── infrastructure/ # Infrastructure Layer
|
|
│ ├── auth/ # JWT Service implementation
|
|
│ └── persistence/ # Repository implementations
|
|
│
|
|
├── handlers/ # Legacy controllers
|
|
├── middleware/ # Security middlewares
|
|
├── models/ # GORM models
|
|
├── services/ # Business logic (legacy)
|
|
└── utils/ # Helpers (JWT, Sanitizer)
|
|
```
|
|
|
|
---
|
|
|
|
## 🔒 Segurança
|
|
|
|
### Middlewares Implementados
|
|
|
|
| Middleware | Arquivo | Descrição |
|
|
|------------|---------|-----------|
|
|
| **Auth** | `middleware/auth.go` | Validação JWT + RBAC |
|
|
| **CORS** | `middleware/cors.go` | Whitelist de origens via `CORS_ORIGINS` |
|
|
| **Rate Limiting** | `middleware/rate_limit.go` | 100 req/min por IP |
|
|
| **Security Headers** | `middleware/security_headers.go` | OWASP headers (XSS, CSP, etc.) |
|
|
|
|
### Validação de JWT
|
|
|
|
O servidor valida no boot que `JWT_SECRET` tenha pelo menos 32 caracteres. Em produção (`ENV=production`), o servidor **não inicia** com secrets fracos.
|
|
|
|
---
|
|
|
|
## 📡 Endpoints
|
|
|
|
### Públicos
|
|
|
|
| Método | Endpoint | Descrição |
|
|
|--------|----------|-----------|
|
|
| `GET` | `/health` | Health check |
|
|
| `GET` | `/swagger/*` | Documentação Swagger |
|
|
| `POST` | `/api/v1/auth/login` | Autenticação |
|
|
| `POST` | `/api/v1/companies` | Registro de empresa |
|
|
| `GET` | `/jobs` | Listar vagas |
|
|
|
|
### Protegidos (JWT Required)
|
|
|
|
| Método | Endpoint | Roles | Descrição |
|
|
|--------|----------|-------|-----------|
|
|
| `GET` | `/api/v1/users` | `superadmin`, `companyAdmin` | Listar usuários |
|
|
| `POST` | `/api/v1/users` | `superadmin`, `companyAdmin` | Criar usuário |
|
|
| `DELETE` | `/api/v1/users/{id}` | `superadmin` | Deletar usuário |
|
|
| `POST` | `/jobs` | `companyAdmin`, `recruiter` | Criar vaga |
|
|
|
|
---
|
|
|
|
## 🚀 Desenvolvimento
|
|
|
|
### Executar
|
|
|
|
```bash
|
|
# Copie o .env
|
|
cp .env.example .env
|
|
|
|
# Execute
|
|
go run ./cmd/api
|
|
```
|
|
|
|
### Testes
|
|
|
|
```bash
|
|
# Todos os testes
|
|
go test ./...
|
|
|
|
# Com verbose
|
|
go test -v ./internal/middleware/... ./internal/utils/...
|
|
```
|
|
|
|
### Regenerar Swagger
|
|
|
|
```bash
|
|
swag init -g cmd/api/main.go --parseDependency --parseInternal
|
|
```
|
|
|
|
---
|
|
|
|
## 🐳 Docker
|
|
|
|
```bash
|
|
# Build
|
|
docker build -t gohorse-backend .
|
|
|
|
# Run
|
|
docker run -p 8080:8080 --env-file .env gohorse-backend
|
|
```
|
|
|
|
**Imagem otimizada:** ~73MB (Alpine + non-root user)
|
|
|
|
---
|
|
|
|
## 📁 Arquivos Importantes
|
|
|
|
| Arquivo | Descrição |
|
|
|---------|-----------|
|
|
| `cmd/api/main.go` | Entrypoint da aplicação |
|
|
| `internal/router/router.go` | Configuração de todas as rotas |
|
|
| `internal/database/database.go` | Conexão GORM com PostgreSQL |
|
|
| `migrations/*.sql` | Migrations do banco de dados |
|
|
| `docs/swagger.json` | Documentação OpenAPI gerada |
|