This project is a backend service that allows users to upload, validate, and list measurements (such as water and gas readings) linked to customers. The service interacts with Google Gemini AI for image data processing and saves the results into a PostgreSQL database using Prisma ORM.
- Upload Measurements: Accepts an image in base64 format, processes it with Google Gemini AI, and saves the extracted data.
- Validate Measurements: Confirms the validity of a measurement reading.
- List Measurements: Retrieves all measurements associated with a customer, with optional filtering by measurement type.
- Customers Table: Stores information about customers.
- Measurements Table: Stores measurement data (e.g., water, gas) linked to a customer.
The database is defined using Prisma. Below is the schema:
enum MeasurementType {
WATER
GAS
}
model Customer {
id String @id @default(uuid())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
measurements Measurement[] @relation("CustomerMeasurements")
@@map ("customers")
}
model Measurement {
id String @id @default(uuid())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
measurementTime DateTime @map("measurement_time")
measurementType MeasurementType @map("measurement_type")
value Decimal @map("value")
hasConfirmedMeasurement Boolean @map("has_confirmed_measurement")
imageUrl String? @map("image_url")
customer Customer @relation(fields: [customerId], references: [id], name: "CustomerMeasurements")
customerId String @map("customer_id")
@@map ("measurements")
}-
Clone the repository:
git clone https://github.com/renanbianchi/ai-backend.git
-
Install dependencies:
cd project-folder npm install -
Set up your
.envfile:Create a
.envfile at the root of the project and define the necessary environment variables:DATABASE_URL=postgresql://username:password@host:port/database
-
Run the Prisma migrations to set up your database schema:
npx prisma migrate dev
-
Start the application:
npm start
To run the database inside a Docker container, use the following commands:
-
Pull the PostgreSQL image:
docker pull postgres
-
Start a PostgreSQL container:
docker run --name project-db -e POSTGRES_PASSWORD=yourpassword -p 5432:5432 -d postgres
-
Set your
.envto usehost.docker.internalas the host if you're using Docker for your database:DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres
After starting the server, you can access the API documentation by navigating to:
http://localhost:3002/api-docs