This folder contains a lightweight Node.js service configured with Prisma to manage the database that matches ExistingDB/New_db_schema.sql.
-
Duplicate
.env.exampleinto.envand update the variables with your Postgres connection strings and API secrets:cp backend/.env.example backend/.env # edit backend/.env to match your credentialsℹ️ Prisma requires the shadow database to point to a different schema than the main connection. For local development you can reuse the same database instance by targeting another schema, e.g.
DATABASE_URL=...schema=publicandSHADOW_DATABASE_URL=...schema=shadow. Be sure to create that schema beforehand:CREATE SCHEMA IF NOT EXISTS shadow;
-
Install dependencies:
cd backend npm install -
Generate the Prisma client:
npm run prisma:generate
-
(Optional, but recommended for local QA) seed a cooperative, workers, materials and demo measurements:
npm run prisma:seed
The seed script is idempotent and can be executed multiple times. It creates a demo worker (
coletor@example.com/senha123) that can be used by the mobile app.
-
To create/update the database structure defined in
prisma/schema.prismarun:npm run prisma:push
This mirrors the tables described in
ExistingDB/New_db_schema.sql. -
If the database already contains the tables and you only want to inspect them, use:
npx prisma db pull
-
You can inspect and seed data through Prisma Studio:
npm run prisma:studio
Start the HTTP server with live-reload:
npm run devThe API listens on PORT (default 3333). A quick smoke test:
curl http://localhost:3333/healthYou can now authenticate with the seeded worker (CPF 00000000000):
curl -X POST http://localhost:3333/auth/login \\
-H 'Content-Type: application/json' \\
-d '{"cpf":"00000000000","password":"senha123"}'The response returns a JWT token that the mobile app reuses for protected routes.