shared-contracts-library
Skill2 starsChanged 4 months agoMITView on GitHub
Regras da lib de contratos compartilhados entre frontend e backend - o que entra, o que nunca entra, barrel, export type e nomenclatura. Use ao criar interface publica, decidir onde um tipo mora ou resolver duplicacao de contrato entre app e API.
In this repository18 other files it gives its agents.
- agents/AGENTS.mdAGENTS.md
- ai-operating-protocolSkill
- angular-feature-architectureSkill
- angular-primeng-auditSkill
- angular-primeng-uiSkill
- angular-testing-patternsSkill
- commit-and-branch-conventionsSkill
- frontend-auth-bootstrapSkill
- generating-backend-moduleSkill
- generating-data-layerSkill
- generating-dumb-createSkill
- generating-dumb-editSkill
- generating-dumb-listSkill
- generating-smart-pageSkill
- monorepo-workspace-standardsSkill
- nestjs-api-standardsSkill
- prisma-migration-disciplineSkill
- rbac-security-auditorSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Import de apps/: a dependencia e unidirecional.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Lib de Contratos Compartilhados
Uma lib de TypeScript puro onde vivem os contratos HTTP publicos, consumida pelos dois lados.
Regra central
Contrato HTTP publico nasce na lib, antes de qualquer model ou DTO local.
Duplicar o shape nos dois lados parece inofensivo no dia 1 e vira divergencia silenciosa no
dia 30: o backend adiciona um campo, o frontend nao sabe, e o bug aparece em producao como
undefined.
O que entra
- Interfaces de request e response de endpoints publicos.
- Enums usados pelos dois lados.
- Tipos utilitarios de resposta: envelope, paginacao, metadados.
- Constantes de contrato: tamanho de pagina default e maximo.
- Tipos de autenticacao e permissao (podem viver numa segunda lib dedicada).
O que nunca entra
- Qualquer import de framework:
@angular/*,@nestjs/*, decorators de framework. A lib precisa compilar e rodar nos dois contextos. - Import de
apps/: a dependencia e unidirecional; o inverso cria ciclo. - Tipo usado por um lado so. Se so o backend usa, e do backend.
- Logica de negocio. E lib de contrato, nao de dominio.
A excecao tolerada e class-validator / class-transformer quando o DTO validado e mesmo
compartilhado. Fora isso, TypeScript puro.
Convencoes
- Interface com prefixo
I:IProduct,IPaginatedResponse. - Toda export publica passa pelo barrel (
src/index.ts). Import por caminho profundo amarra o consumidor a estrutura interna da lib. - Re-export de tipo usa
export type { }(exigencia deisolatedModules). Enum e valor em runtime: re-exportar comexport { }normal.
// tipos
export type { IProduct } from './interfaces/product.interface';
// enum (valor, nao so tipo)
export { OrderStatus } from './enums/order-status.enum';Envelope e paginacao
Manter os wrappers na lib para que os dois lados falem a mesma lingua:
export interface ApiResponse<T> {
message: string;
statusCode: number;
type: 'success' | 'error';
data: T;
}
export interface PaginatedResponse<T> {
items: T[];
meta: IPaginationMeta;
}Checklist ao mexer na lib
- Export nova adicionada ao barrel
export typeusado para tipo,exportnormal para enum- Nenhum import de framework introduzido
- Os dois apps ainda compilam
- O DTO do backend implementa a interface publica em vez de redeclarar campos
- O model do frontend re-exporta da lib em vez de copiar
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

