Agroplus-API is a GraphQL-enabled RESTful API designed to help farmers manage all relevant information about their livestock. It allows users to record, track, and manage animal data, including parentage, vaccination, deworming records, and personal notes.
- Backend: Node.js + Express.js with GraphQL
- ORM: Sequelize
- Database: PostgreSQL
- Container: Docker
- Authentication: JWT with cookies
- Docs: Swagger
- Containerization: Docker
- Architecture: MVC (based on entities)
- Testing: Jest + Supertest
- π§ Register and login a user
- π CRUD operations for animals:
- Include full animal details.
- Define animal parentage (link to mother/father).
- π CRUD for vaccinations.
- π CRUD for deworming treatments.
- π CRUD for notes.
- Full support for GraphQL
- π : Live chat with other users using Socket.io
-
System: JWT access token saved in cookies.
-
Flow:
- User registers.
- On login, a unique
accessTokenis issued and saved in a cookie. - Token has a lifespan of 60 minutes and is stored in the DB for validation.
- Security Note: This implementation ensures simplicity and control via token invalidation by removing it from the DB.
-
Roles: No role-based access control; every user has full access to their data.
-
Important: In GraphQL, the accessToken is implemented in the headers using "Bearer" strategy
The project has been tested in a robust way using Jest + Supertest. The implemented tests were unit tests(services) and E2E tests(endpoints).
api/
βββ index.js
βββ app.js
βββ config/
βββ src/
β βββ graphql/
β β βββ resolvers/
β β β βββ [entity]/ for example: animal/
β β β βββ animal.resolvers.js
β β β βββ index.js
β β βββ schemas/
β β β βββ animal.schemas.graphql
β β β βββ [entity].schemas.graphql
β β βββ resolvers.js (Centralization of resolvers)
β β βββ index.js
β β
β βββ middlewares/
β βββ utils/
β β βββ docs/
β β βββ swagger.js
β βββ store/
β β βββ (DB setup, Sequelize initialization)
β βββ modules/
β βββ animal/
β β βββ animal.controller.js
β β βββ animal.routes.js
β β βββ animal.schema.js
β β βββ animal.service.js
β β βββ animal.repository.js
β βββ user/
β βββ deworming/
β βββ vaccination/
β βββ note/
β βββ routes.js (main router)
/tests/
βββ unit/
β βββ [ServiceName].test.js # Ej: user-service.test.js
β
βββ e2e/
β βββ [entity].e2e.js # Ej: vaccination.e2e.js β all vaccination endpoints
- MVC pattern is followed per module/entity.
- Each module contains all necessary logic (schema, controller, service, repo, route).
- Docker Desktop
- Node.js (v18+ recommended)
- NPM
-
Clone the repo
git clone [email protected]:OscarS05/Agroplus-api.git cd agroplus-api
-
Install dependencies
npm install- Setup environment variables
Copy the.env.examplefile to.envand update it with database values. Use thedocker-compose.ymlfile to get the DB credentials.
cp .env.example .env- Run Docker containers (for DB)
docker-compose up -d- Run migrations to set up DB schema
npm run migrations:run- Start the server
for development:
npm run devHere are example requests and responses for some endpoints:
Description: Creates a new animal record in the database.
Request Body (example):
{
"livestockType": "Bovino",
"animalType": "Vaca",
"breed": "Angus",
"code": "BOV-001",
"sex": "Female",
"father": "d0759f76-a119-4be0-ad33-e93595f56be8"
}Response (example):
{
"message": "Animal was successfully created",
"success": true,
"newAnimal": {
"id": "c36b4f45-35f9-4d77-9669-e55eb7d33405",
"livestockType": "Bovino",
"animalType": "Vaca",
"breed": "Angus",
"code": "BOV-001",
"sex": "Female",
"mother": null,
"father": "OPP-TT1",
"birthDate": null,
"registeredAt": "2025-04-16"
}
}Description: Retrieves the list of all vaccinations associated with animals.
Response (example):
{
"vaccinations": [
{
"id": "065f441b-64ba-411a-97d1-7cbf15443732",
"vaccine": "Ivermectin 0.5%",
"description": "Updated",
"animal": "abc-123",
"registeredAt": "2025-04-16"
}
],
"success": true
}- All endpoints are fully documented using Swagger. Be sure to have the right server when trying on Swagger.
- Production Docs: https://agroplus-api.onrender.com/api-docs
- Local Docs:
http://localhost:4000/api-docs(ensure correct port in.env) Note: Production docs are not currently available
- Development Swagger URL:
http://localhost:4000/api-docs(port may vary depending on your.envconfiguration)
π₯ Demo Video: Watch how to use the API via Swagger
- Author: Oscar Santiago Monsalve
- GitHub: OscarS05
- License: Creative Commons BY-NC 4.0