The Ferreandina frontend communicates with the backend through a clean, typed service layer. A genericDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/ferreandina-nosql/llms.txt
Use this file to discover all available pages before exploring further.
Service<T> class defined in src/services/service.ts wraps Axios and exposes five standard CRUD methods. Every resource then has its own class extending Service<T> — parameterised with the resource’s TypeScript model — and exports a pre-instantiated singleton so pages can import and call it directly without ever managing an Axios instance themselves.
Axios Configuration
The shared Axios instance lives insrc/services/axios.config.ts. It reads the backend base URL from the VITE_API_URL environment variable (set in your .env file) and falls back to http://localhost:8080/ when the variable is absent. The Content-Type header is set to application/json globally so every request is serialised correctly without per-call configuration.
Set
VITE_API_URL in app/fr/.env to point at your running backend (for example http://localhost:7070/). Vite inlines env variables that start with VITE_ at build time, so the fallback is only used during local development when the file is missing.Base Service Class
src/services/service.ts contains the generic Service<T> class. It accepts an endpoint string in its constructor (the resource path segment, e.g. "branches") and uses it to build every URL. All methods return a Promise<ReturningService> — a normalised envelope that pages can check for error: true before trying to use data.
| Method | HTTP | URL pattern | Returns |
|---|---|---|---|
get_all() | GET | /{endpoint} | Promise<ReturningService> — data is the full array |
get_by_id(id) | GET | /{endpoint}/{id} | Promise<ReturningService> — data is response.data.data[0] |
post(document) | POST | /{endpoint} | Promise<ReturningService> — data is the created document |
update(id, document) | PATCH | /{endpoint}/{id} | Promise<ReturningService> — data is the raw response body |
delete(id) | DELETE | /{endpoint}/{id} | Promise<ReturningService> — data is the raw response body |
try/catch. On failure it returns { error: true, status: <HTTP status or 500>, data: null } so callers never need to handle a thrown exception — they only need to inspect the error flag.
ReturningService Model
src/models/ReturningService.model.ts defines the envelope that every service method resolves to:
| Field | Type | Description |
|---|---|---|
status | number | HTTP status code returned by the server (or 500 on network error) |
data | any | The unwrapped payload — an array for get_all, a single object for get_by_id, or the server response body for mutations |
message | string (optional) | Human-readable message from the server (present on some endpoints) |
error | boolean (optional) | true when the request failed; false (or absent) on success |
Resource Services
Each resource in the application has its own service file that extendsService<T> with the appropriate model type and passes the API endpoint string to the parent constructor. The file also exports a singleton instance, which is the object pages import and call.
Here is src/services/branch.service.ts as a representative example:
branch.service.ts
Endpoint:
branches · Model: Branchcategory.service.ts
Endpoint:
categories · Model: Categorycustomer.service.ts
Endpoint:
customers · Model: Customerproduct.service.ts
Endpoint:
products · Model: Productsupplier.service.ts
Endpoint:
suppliers · Model: SupplierSupplie.service.ts
Endpoint:
supplies · Model: Supplieworker.service.ts
Endpoint:
workers · Model: Workerprice_change.service.ts
Endpoint:
price_changes · Model: PriceChangeUsage Example
The following shows how a page component imports a service singleton, callsget_all(), and stores the result in local state:
get_by_id, post, update, and delete:
TypeScript Models
Each service is parameterised with a TypeScriptinterface that describes the shape of the resource document. This gives full type safety on the post and update call sites — TypeScript will warn if a required field is missing or has the wrong type.
The Branch model is a good example of how models are defined in src/models/:
?) because the same interface is used for both full documents returned by the API and partial update payloads sent to it. The other model interfaces follow the same convention:
| Model file | Key fields |
|---|---|
Branch.model.ts | id, name, city, direction, products, workers, is_main, image |
Category.model.ts | id, name, description, image |
Customer.model.ts | id, alias, ni, category, phone |
Product.model.ts | id, name, description, price, category_id, quantity, unitary_weight, sould_out_date, supplier, image |
Supplier.model.ts | id, name, email, phone, direction, image |
Supplie.model.ts | id, supplier, products, defective_quantity, entry_date |
Worker.model.ts | id, name, age, speciality, weight, email, phone, salary, image |
PriceChange.model.ts | id, productid, changes |