Skip to content

Commit 445d257

Browse files
committed
feat: init
0 parents  commit 445d257

23 files changed

Lines changed: 3770 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 10
8+
labels:
9+
- "dependencies"
10+
commit-message:
11+
prefix: "deps: "
12+
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"
17+
open-pull-requests-limit: 5
18+
labels:
19+
- "dependencies"
20+
commit-message:
21+
prefix: "ci: "

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Node CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node 24
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '24'
22+
cache: 'npm'
23+
cache-dependency-path: node/package-lock.json
24+
25+
- name: Install dependencies
26+
working-directory: node
27+
run: npm ci
28+
29+
- name: Check types
30+
working-directory: node
31+
run: npm run check-types
32+
33+
- name: Build
34+
working-directory: node
35+
run: npm run build
36+
37+
- name: Run tests
38+
working-directory: node
39+
run: npm test

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# Coverage
8+
coverage/
9+
10+
# TypeScript incremental cache
11+
*.tsbuildinfo
12+
13+
# Logs
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
pnpm-debug.log*
18+
19+
# Environment files
20+
.env
21+
.env.*
22+
!.env.example

README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Usuarios API Node
2+
3+
Exemplo do mesmo CRUD implementado em Node.js com Fastify, TypeScript, Swagger, persistencia em memoria, testes automatizados e arquitetura Ports and Adapters.
4+
5+
## Tecnologias
6+
7+
- Node.js 24
8+
- TypeScript 5
9+
- Fastify 5
10+
- Zod 4
11+
- Swagger UI
12+
- Vitest 4
13+
14+
## Pre-requisitos
15+
16+
- Windows com PowerShell
17+
- Node.js 24+
18+
- npm 11+
19+
20+
Para validar a instalacao:
21+
22+
```powershell
23+
node --version
24+
npm --version
25+
```
26+
27+
## Arquitetura
28+
29+
Estrutura do projeto:
30+
31+
```text
32+
src/
33+
|-- adapters
34+
| |-- inbound/http
35+
| `-- outbound/repositories
36+
|-- application
37+
| `-- services
38+
|-- domain
39+
| `-- ports
40+
`-- main.ts
41+
42+
tests/
43+
|-- integration/http
44+
`-- unit/application
45+
```
46+
47+
Responsabilidades:
48+
49+
- `domain`: entidade, erros e contrato do repositorio
50+
- `application`: comando de entrada e servico de negocio
51+
- `adapters/outbound`: persistencia em memoria
52+
- `adapters/inbound/http`: schemas Zod e rotas HTTP
53+
- `main.ts`: bootstrap do servidor
54+
55+
## Modelo de dominio
56+
57+
- `id: int`
58+
- `nome: string`
59+
- `dtNascimento: date`
60+
- `status: bool`
61+
- `telefones: string[]`
62+
63+
## Como rodar
64+
65+
Na pasta `node`:
66+
67+
### 1. Instalar dependencias
68+
69+
```powershell
70+
npm install
71+
```
72+
73+
### 2. Rodar em modo desenvolvimento
74+
75+
```powershell
76+
npm run dev
77+
```
78+
79+
### 3. Acessar a aplicacao
80+
81+
- API: `http://127.0.0.1:8000`
82+
- Swagger UI: `http://127.0.0.1:8000/docs`
83+
84+
### 4. Build e execucao compilada
85+
86+
```powershell
87+
npm run build
88+
npm start
89+
```
90+
91+
## Como testar
92+
93+
```powershell
94+
npm test
95+
```
96+
97+
Resultado esperado no estado atual do projeto:
98+
99+
- testes unitarios do servico
100+
- testes de integracao HTTP
101+
- 9 testes passando
102+
103+
## Como validar tipos
104+
105+
```powershell
106+
npm run check-types
107+
```
108+
109+
## Endpoints
110+
111+
- `GET /health/live`
112+
- `GET /health/ready`
113+
- `POST /usuarios`
114+
- `GET /usuarios`
115+
- `GET /usuarios/{usuarioId}`
116+
- `PUT /usuarios/{usuarioId}`
117+
- `DELETE /usuarios/{usuarioId}`
118+
119+
## Exemplo de payload
120+
121+
```json
122+
{
123+
"id": 1,
124+
"nome": "Carlos",
125+
"dtNascimento": "1992-03-14",
126+
"status": true,
127+
"telefones": [
128+
"11911112222",
129+
"1122223333"
130+
]
131+
}
132+
```
133+
134+
## CI
135+
136+
O workflow fica em `.github/workflows/ci.yml` e executa:
137+
138+
- instalacao com `npm ci`
139+
- checagem de tipos
140+
- build
141+
- testes
142+
143+
## Observacoes
144+
145+
- A persistencia e totalmente em memoria.
146+
- Ao reiniciar a aplicacao, os dados sao perdidos.
147+
- A API usa validacao via Zod e gera Swagger a partir dos schemas.
148+
149+
## Comandos uteis
150+
151+
```powershell
152+
npm install
153+
npm run dev
154+
npm run check-types
155+
npm run build
156+
npm test
157+
```

0 commit comments

Comments
 (0)