mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
A release-readiness QA pass over the whole product. The commits split into defects a user would hit and gates that were reporting green while measuring nothing. ## Fixes that change behaviour Rate limiting was bypassable on every install: TRUST_PROXY defaulted to true, so request.ip came from a client-set header and a forged X-Forwarded-For got past the login limiter. The default is now a private-network trust list. A transient Postgres outage stranded in-flight jobs, leaving finished output on disk with no row pointing at it. A reconciler now resolves those rows and adopts the bytes rather than dropping the work. A Redis connection that moved to a new address wedged every read-blocked consumer, so completions stopped signalling while health still answered 200. Socket timeouts plus subscriber pings recover it. Installing more than one AI bundle left the shared venv multi-versioned and silently broke three tools. The installer now reconciles distributions to one version each. Converting an image to JXL at quality 1 through 4 returned a 500, because libjxl 0.7 rejects the distance those values compute. The quality is floored at what the encoder honours. A missing ffmpeg was also reported to the user as a corrupt upload; it now says the engine is unavailable. RAW uploads reached an unpatched LibRaw on arm64, so it is built from source at 0.22.2, and the release scan was split so it can fail on an unfixed critical instead of hiding it behind ignore-unfixed. ## Gates that could not fail Two mutation lanes ran zero mutants because Stryker crawled the gitignored docs build; coverage discarded its whole report on any failing test; the lint gate skipped root tests, scripts, and two workspaces; and several generated matrices counted a host missing ffmpeg as a passing tool. Each now measures what it claims. Full evidence and the outstanding release items are tracked locally and are not part of this branch.
247 lines
9.2 KiB
Markdown
247 lines
9.2 KiB
Markdown
---
|
|
description: "Configuração de ambiente de desenvolvimento local, comandos, convenções de código e como adicionar uma nova ferramenta ao SnapOtter."
|
|
i18n_source_hash: 56acc1bf9a9b
|
|
i18n_provenance: machine
|
|
i18n_output_hash: 3c036b74e396
|
|
i18n_hash_version: 2
|
|
---
|
|
|
|
# Guia do desenvolvedor {#developer-guide}
|
|
|
|
Como configurar um ambiente de desenvolvimento local e contribuir com código para o SnapOtter.
|
|
|
|
## Pré-requisitos {#prerequisites}
|
|
|
|
- [Node.js](https://nodejs.org/) 22.22+
|
|
- [pnpm](https://pnpm.io/) 9+ (`corepack enable && corepack prepare pnpm@latest --activate`)
|
|
- [Docker](https://www.docker.com/) (necessário para Postgres + Redis locais, builds de contêiner e recursos de IA)
|
|
- Git
|
|
|
|
Python 3.11+ só é necessário se você estiver trabalhando no sidecar de IA/ML (remoção de fundo, upscaling, OCR).
|
|
|
|
## Configuração {#setup}
|
|
|
|
```bash
|
|
git clone https://github.com/snapotter-hq/snapotter.git
|
|
cd snapotter
|
|
docker compose -f docker-compose.dev.yml up -d # start Postgres + Redis
|
|
pnpm install
|
|
pnpm dev
|
|
```
|
|
|
|
Isso inicia dois servidores de desenvolvimento:
|
|
|
|
| Serviço | URL | Observações |
|
|
|----------|--------------------------|------------------------------------|
|
|
| Frontend | http://localhost:1351 | Servidor de dev Vite, faz proxy de /api |
|
|
| Backend | http://localhost:13490 | API Fastify (acessada via proxy) |
|
|
|
|
Abra http://localhost:1351 no seu navegador. Faça login com `admin` / `admin`. Você será solicitado a alterar a senha no primeiro login.
|
|
|
|
## Estrutura do projeto {#project-structure}
|
|
|
|
```
|
|
apps/
|
|
api/ Fastify backend
|
|
web/ Vite + React frontend
|
|
docs/ VitePress documentation (this site)
|
|
packages/
|
|
shared/ Constants, types, i18n strings
|
|
image-engine/ Sharp-based image operations
|
|
media-engine/ FFmpeg spawn + progress parsing
|
|
doc-engine/ qpdf, LibreOffice, ghostscript wrappers
|
|
ai/ Python sidecar bridge for ML models
|
|
tests/
|
|
unit/ Vitest unit tests
|
|
integration/ Vitest integration tests (full API)
|
|
e2e/ Playwright end-to-end specs
|
|
fixtures/ Small test images
|
|
```
|
|
|
|
## Comandos {#commands}
|
|
|
|
```bash
|
|
pnpm dev # start frontend + backend
|
|
pnpm build # build all workspaces
|
|
pnpm typecheck # TypeScript check across monorepo
|
|
pnpm lint # Biome lint + format check
|
|
pnpm lint:fix # auto-fix lint + format
|
|
pnpm test # unit + integration tests
|
|
pnpm test:unit # unit tests only
|
|
pnpm test:integration # integration tests only
|
|
pnpm test:e2e # Playwright e2e tests
|
|
pnpm test:coverage # tests with coverage report
|
|
```
|
|
|
|
## Convenções de código {#code-conventions}
|
|
|
|
- Aspas duplas, ponto e vírgula, indentação de 2 espaços (imposto pelo Biome)
|
|
- Módulos ES em todos os workspaces
|
|
- [Conventional commits](https://www.conventionalcommits.org/) para semantic-release
|
|
- Zod para toda validação de entrada da API
|
|
- Sem modificações nos arquivos de configuração do Biome, do TypeScript ou do editor. Corrija o código, não o linter.
|
|
|
|
## Banco de dados {#database}
|
|
|
|
PostgreSQL 17 via Drizzle ORM (pg-core). O desenvolvimento local requer Postgres e Redis em execução - inicie-os com:
|
|
|
|
```bash
|
|
docker compose -f docker-compose.dev.yml up -d
|
|
```
|
|
|
|
Isso lhe dá o Postgres na porta 5432 e o Redis na porta 6379. Depois gere e aplique as migrações:
|
|
|
|
```bash
|
|
cd apps/api
|
|
npx drizzle-kit generate # generate a migration from schema changes
|
|
npx drizzle-kit migrate # apply pending migrations
|
|
```
|
|
|
|
O esquema é definido em `apps/api/src/db/schema.ts`. Tabelas: users, sessions, settings, jobs, apiKeys, pipelines, teams, userFiles, roles, auditLog.
|
|
|
|
## Adicionando uma nova ferramenta {#adding-a-new-tool}
|
|
|
|
Toda ferramenta segue o mesmo padrão. Aqui está um exemplo mínimo.
|
|
|
|
### 1. Rota do backend {#_1-backend-route}
|
|
|
|
Crie `apps/api/src/routes/tools/my-tool.ts`:
|
|
|
|
```ts
|
|
import { z } from "zod";
|
|
import type { FastifyInstance } from "fastify";
|
|
import { createToolRoute } from "../tool-factory.js";
|
|
|
|
const settingsSchema = z.object({
|
|
intensity: z.number().min(0).max(100).default(50),
|
|
});
|
|
|
|
export function registerMyTool(app: FastifyInstance) {
|
|
createToolRoute(app, {
|
|
toolId: "my-tool",
|
|
settingsSchema,
|
|
async process(inputBuffer, settings, filename) {
|
|
// Use sharp or other libraries to process the image
|
|
const sharp = (await import("sharp")).default;
|
|
const result = await sharp(inputBuffer)
|
|
// ... your processing logic
|
|
.toBuffer();
|
|
|
|
return {
|
|
buffer: result,
|
|
filename: filename.replace(/\.[^.]+$/, ".png"),
|
|
contentType: "image/png",
|
|
};
|
|
},
|
|
});
|
|
}
|
|
```
|
|
|
|
Então registre-a em `apps/api/src/routes/tools/index.ts`.
|
|
|
|
### 2. Componente de configurações do frontend {#_2-frontend-settings-component}
|
|
|
|
Crie `apps/web/src/components/tools/my-tool-settings.tsx`:
|
|
|
|
```tsx
|
|
import { useState } from "react";
|
|
import { useToolProcessor } from "@/hooks/use-tool-processor";
|
|
import { useFileStore } from "@/stores/file-store";
|
|
|
|
export function MyToolSettings() {
|
|
const { files } = useFileStore();
|
|
const { processFiles, processing, error, downloadUrl } =
|
|
useToolProcessor("my-tool");
|
|
|
|
const [intensity, setIntensity] = useState(50);
|
|
|
|
const handleProcess = () => {
|
|
processFiles(files, { intensity });
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
{/* your controls here */}
|
|
<button
|
|
type="button"
|
|
onClick={handleProcess}
|
|
disabled={files.length === 0 || processing}
|
|
data-testid="my-tool-submit"
|
|
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50"
|
|
>
|
|
Process
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
```
|
|
|
|
Então registre-o no registro de ferramentas do frontend em `apps/web/src/lib/tool-registry.tsx`:
|
|
|
|
```tsx
|
|
// Add the lazy import
|
|
const MyToolSettings = lazy(() =>
|
|
import("@/components/tools/my-tool-settings").then((m) => ({
|
|
default: m.MyToolSettings,
|
|
})),
|
|
);
|
|
|
|
// Add to the toolRegistry Map
|
|
["my-tool", { displayMode: "before-after", Settings: MyToolSettings }],
|
|
```
|
|
|
|
Modos de exibição: `"side-by-side"`, `"before-after"`, `"live-preview"`, `"no-comparison"`, `"interactive-crop"`, `"interactive-eraser"`, `"no-dropzone"`.
|
|
|
|
### 3. Entrada de i18n {#_3-i18n-entry}
|
|
|
|
Adicione a `packages/shared/src/i18n/en.ts`:
|
|
|
|
```ts
|
|
"my-tool": {
|
|
name: "My Tool",
|
|
description: "Short description of what this tool does",
|
|
},
|
|
```
|
|
|
|
### 4. Testes {#_4-tests}
|
|
|
|
Adicione um atributo `data-testid` ao seu botão de ação (como mostrado acima) para que os testes e2e possam localizá-lo de forma confiável.
|
|
|
|
## Builds do Docker {#docker-builds}
|
|
|
|
Construa a imagem de produção completa localmente:
|
|
|
|
```bash
|
|
docker build -f docker/Dockerfile -t snapotter:latest .
|
|
```
|
|
|
|
Use cache mounts do BuildKit para rebuilds mais rápidos:
|
|
|
|
```bash
|
|
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile -t snapotter:latest .
|
|
```
|
|
|
|
## Domínios de versões de lançamento {#release-version-domains}
|
|
|
|
SnapOtter possui intencionalmente três domínios de versão. Não copie um domínio para outro durante um lançamento:
|
|
|
|
- A versão de lançamento do aplicativo abrange o manifesto raiz, todos os pacotes de espaço de trabalho privado e `APP_VERSION`. Semantic-release fornece esse valor e `pnpm version:sync <version>` atualiza cada espaço de trabalho antes do lançamento do aplicativo.
|
|
- OpenAPI `info.version` é o contrato público estável API-major. Todas as especificações localizadas permanecem em `<major>.0.0` para versões de aplicativos compatíveis e mudam somente quando o contrato API passa para uma nova versão principal.
|
|
- `docker/feature-manifest.json` mantém `imageVersion: 2.0.0` como a época de armazenamento de pacote de recursos legado imutável. Esses caminhos de arquivo v2 não são versões de pacotes de aplicativos. O OCR preciso usa o formato de tempo de execução v3 e registra a origem da versão do aplicativo separadamente.
|
|
|
|
`tests/unit/infra/release-version-policy.test.ts` impõe esses limites. Um novo domínio de versão ou migração deve atualizar esse contrato e o design de migração de artefato relevante juntos.
|
|
Os valores independentes API e do pacote legado residem em `config/release-version-policy.json`; a sincronização de versão do aplicativo nunca deve reescrever esse arquivo de política implicitamente.
|
|
|
|
## Variáveis de ambiente {#environment-variables}
|
|
|
|
Veja o [Guia de configuração](/pt-BR/guide/configuration) para a lista completa. As principais para desenvolvimento:
|
|
|
|
| Variável | Padrão | Descrição |
|
|
|-----------------------------|-----------|------------------------------------------------|
|
|
| `AUTH_ENABLED` | `true` | Habilitar/desabilitar autenticação |
|
|
| `DEFAULT_USERNAME` | `admin` | Nome de usuário admin padrão |
|
|
| `DEFAULT_PASSWORD` | `admin` | Senha admin padrão |
|
|
| `SKIP_MUST_CHANGE_PASSWORD` | `false` | Pular mudança de senha forçada (apenas CI/dev) |
|
|
| `RATE_LIMIT_PER_MIN` | `1000` | Limite de taxa da API por minuto (0 = desabilitado) |
|
|
| `MAX_UPLOAD_SIZE_MB` | `100` | Tamanho máximo de upload em MB (0 = ilimitado) |
|