{"id":31698852,"url":"https://github.com/vmartinscordeiro/projeto_teste","last_synced_at":"2026-04-13T04:32:19.998Z","repository":{"id":317780373,"uuid":"1068812177","full_name":"vmartinscordeiro/Projeto_teste","owner":"vmartinscordeiro","description":"FastAPI + Postgres + Alembic + Docker | React + Vite + Redux + Tests | Dashboard","archived":false,"fork":false,"pushed_at":"2025-10-03T01:24:32.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-03T02:35:02.434Z","etag":null,"topics":["alembic","docker","fastapi","postgresql","react","redux","testing","vite"],"latest_commit_sha":null,"homepage":"https://www.linkedin.com/in/vinicius-cordeiro-356089107/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmartinscordeiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-03T00:20:21.000Z","updated_at":"2025-10-03T01:24:35.000Z","dependencies_parsed_at":"2025-10-03T02:35:08.139Z","dependency_job_id":"93d94d54-3cd3-442a-aed5-ee639e3e561e","html_url":"https://github.com/vmartinscordeiro/Projeto_teste","commit_stats":null,"previous_names":["vmartinscordeiro/projeto_teste"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vmartinscordeiro/Projeto_teste","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmartinscordeiro%2FProjeto_teste","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmartinscordeiro%2FProjeto_teste/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmartinscordeiro%2FProjeto_teste/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmartinscordeiro%2FProjeto_teste/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmartinscordeiro","download_url":"https://codeload.github.com/vmartinscordeiro/Projeto_teste/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmartinscordeiro%2FProjeto_teste/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000702,"owners_count":26082805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alembic","docker","fastapi","postgresql","react","redux","testing","vite"],"created_at":"2025-10-08T19:11:15.642Z","updated_at":"2025-10-08T19:11:41.023Z","avatar_url":"https://github.com/vmartinscordeiro.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Brain Agriculture — Teste Técnico\n\nEste repositório entrega **backend (FastAPI + Postgres + Alembic + Docker)** e **frontend (React + TypeScript + Vite + Redux Toolkit + Tests)**, atendendo aos requisitos do desafio.\n\n![Python 3.11](https://img.shields.io/badge/Python-3.11-blue)\n![FastAPI](https://img.shields.io/badge/FastAPI-API-green)\n![React 18](https://img.shields.io/badge/React-18-61dafb)\n![Vite](https://img.shields.io/badge/Vite-React%20TS-8A2BE2)\n![Docker](https://img.shields.io/badge/Docker-Compose-2496ED)\n![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)\n\n\n\n## ✅ O que foi implementado\n\n- **Regras de negócio**\n  - CRUD de **Produtores** e **Fazendas**.\n  - **Validação de CPF/CNPJ** no backend.\n  - **Consistência de áreas**: agricultável + vegetação ≤ total.\n  - **Safra \u0026 Cultura por fazenda** (relações sazonais: Soja/Milho etc.).\n  - **Dashboard** com:\n    - Total de fazendas.\n    - Total de hectares (área total).\n    - **Gráficos de pizza**: por **UF**, por **Cultura** e por **Uso do Solo**.\n\n- **Backend**\n  - **FastAPI** (Python 3.11) + **SQLAlchemy 2** + **Alembic**.\n  - **Postgres** via Docker Compose.\n  - **OpenAPI** em `/docs` (Swagger) e `/redoc`.\n  - **Observabilidade**: `/metrics` via `prometheus_fastapi_instrumentator` e endpoint `/health`.\n  - **Testes** (pytest) — API básica end-to-end.\n\n- **Frontend**\n  - **React + TypeScript + Vite** (Node 22+).\n  - **Redux Toolkit** (slice de `producers` com testes).\n  - **Recharts** para os gráficos.\n  - **Testes UI** com **Vitest + Testing Library** (inclui ajustes de JSDOM para gráficos).\n\n## 🧱 Arquitetura \u0026 Estrutura\n```\nbrain-ag-test/\n├─ backend/\n│ ├─ app/\n│ │ ├─ api/\n│ │ │ └─ routers/\n│ │ │ ├─ producers.py\n│ │ │ ├─ farms.py\n│ │ │ ├─ farm_crops.py\n│ │ │ └─ dashboard.py\n│ │ ├─ core/config.py\n│ │ ├─ crud/\n│ │ │ ├─ producer.py\n│ │ │ ├─ farm.py\n│ │ │ └─ farm_crop.py\n│ │ ├─ db/\n│ │ │ ├─ base.py\n│ │ │ ├─ session.py\n│ │ │ └─ deps.py\n│ │ ├─ models/\n│ │ │ ├─ producer.py\n│ │ │ ├─ farm.py\n│ │ │ └─ agronomy.py # Season, Crop, FarmCrop\n│ │ ├─ schemas/\n│ │ │ ├─ producer.py\n│ │ │ ├─ farm.py\n│ │ │ └─ farm_crop.py\n│ │ ├─ utils/validators.py # cpf/cnpj e áreas\n│ │ └─ main.py\n│ ├─ alembic/\n│ │ └─ versions/\n│ │ ├─ 0001_init_producers_farms.py\n│ │ └─ 0002_seasons_crops.py\n│ ├─ tests/\n│ │ └─ test_api.py\n│ ├─ Dockerfile\n│ └─ alembic.ini\n├─ frontend/\n│ ├─ src/\n│ │ ├─ pages/\n│ │ │ ├─ Dashboard.tsx\n│ │ │ └─ Producers.tsx\n│ │ ├─ features/producers/\n│ │ │ ├─ slice.ts\n│ │ │ └─ slice.test.ts\n│ │ ├─ services/\n│ │ │ ├─ api.ts\n│ │ │ └─ dashboard.ts\n│ │ ├─ tests/\n│ │ │ ├─ Dashboard.test.tsx\n│ │ │ └─ Producers.test.tsx\n│ │ └─ setupTests.ts\n│ ├─ vite.config.ts\n│ ├─ package.json\n│ └─ tsconfig.json\n├─ docker-compose.yml\n├─ openapi.json\n└─ README.md\n```\n\n## 🚀 Como rodar (local)\n\n### 1) Pré-requisitos\n\n- **Docker Desktop** (com Docker Compose).\n- **Node.js LTS 22+** (usamos 22.20.0).\n- **PowerShell** (Windows) ou seu terminal favorito.\n\n### 2) Backend (API + DB)\n\nNa raiz do projeto:\n\n```powershell\n# subir containers (db + api)\ndocker compose up -d --build\n\n# aplicar migrações do Alembic (se ainda não aplicadas)\ndocker compose exec api bash -lc \"alembic -c alembic.ini upgrade head\"\n\n# verificar saúde\ncurl http://127.0.0.1:8000/health\n# -\u003e {\"status\":\"ok\",\"db\":\"up\",\"env\":\"...\"}\nDocumentação interativa:\n\nSwagger: http://127.0.0.1:8000/docs\n\nReDoc: http://127.0.0.1:8000/redoc\n\nOpenAPI JSON: http://127.0.0.1:8000/openapi.json\n\nMétricas Prometheus: http://127.0.0.1:8000/metrics\n\nEndpoints principais\n\nPOST /producers — cria produtor {cpf_cnpj, name}\n\nGET /producers — lista\n\nGET /producers/{id}, PUT /producers/{id}, DELETE /producers/{id}\n\nPOST /farms — cria fazenda {producer_id, name, city, state, area_total, area_agricultavel, area_vegetacao}\n\nGET /farms — lista (+ filtro producer_id)\n\nGET/PUT/DELETE /farms/{id}\n\nPOST /farm-crops — vincula cultura/safra {farm_id, season, crop}\n\nGET /farm-crops — lista (+ filtros farm_id, season, crop)\n\nGET /dashboard/summary — { total_farms, total_hectares }\n\nGET /dashboard/pie/state\n\nGET /dashboard/pie/crop\n\nGET /dashboard/pie/landuse\n\nExemplos rápidos (PowerShell):\n\n\n\n# criar produtor\n$body = @{ cpf_cnpj = '52998224725'; name = 'João da Silva' } | ConvertTo-Json -Compress\nInvoke-RestMethod -Method Post -Uri \"http://127.0.0.1:8000/producers\" -ContentType \"application/json; charset=utf-8\" -Body ([Text.Encoding]::UTF8.GetBytes($body))\n\n# criar fazenda\n$body = @{\n  producer_id = 1; name='Fazenda Boa Terra'; city='Sorriso'; state='MT';\n  area_total=1000; area_agricultavel=700; area_vegetacao=300\n} | ConvertTo-Json -Compress\nInvoke-RestMethod -Method Post -Uri \"http://127.0.0.1:8000/farms\" -ContentType \"application/json; charset=utf-8\" -Body ([Text.Encoding]::UTF8.GetBytes($body))\n\n3) Frontend (Vite)\ncd frontend\nnpm install\nnpm run dev   # abre em http://127.0.0.1:5173\n\n4) Testes\n# backend\ndocker compose exec api bash -lc \"pytest -q /app/tests\"\n\n# frontend (modo watch; pressione q para sair)\ncd frontend\nnpm run test\nCobertura dos testes UI:\n\nsrc/__tests__/Dashboard.test.tsx (mock dos serviços + checa títulos/cards).\n\nsrc/__tests__/Producers.test.tsx (render e chamada simulada).\n\nsrc/features/producers/slice.test.ts (reducers do Redux).\n\n🔍 Observabilidade\n/health: checagem rápida de DB e ambiente.\n\n/metrics: métricas Prometheus do FastAPI (requests, latências, etc.).\n\n🧩 Decisões \u0026 Notas\nValidação: app/utils/validators.py contém CPF/CNPJ e check de áreas.\n\nModelagem: Season, Crop e FarmCrop permitem registrar culturas por safra.\n\nAlembic: migrações 0001 (produtores, fazendas) e 0002 (safras, culturas, vínculos).\n\nRedux: slice de producers com thunks (fetchProducers, createProducer).\n\nGráficos (Recharts): para testes no JSDOM, setupTests.ts inclui polyfills de ResizeObserver e getBBox.\n\nDica: para salvar o OpenAPI JSON na raiz:\n\ncurl.exe -s http://127.0.0.1:8000/openapi.json -o .\\openapi.json\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmartinscordeiro%2Fprojeto_teste","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmartinscordeiro%2Fprojeto_teste","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmartinscordeiro%2Fprojeto_teste/lists"}