A Backend Repository for Nutrigrow Project. This backend is built with Go, Gin, and GORM, following a Clean Architecture approach. It provides a robust API for managing user data, stunting records, news, food recipes, and their ingredients.
- User Management: Register, Login, Refresh Token, User Profile (Me), Update/Delete User, Email Verification.
- Stunting Records: Create, Retrieve (by ID, by User ID, latest by User ID), Update, Delete stunting records.
- Stunting Prediction: API endpoint to predict stunting status using an external ML model.
- News Management: Create, Retrieve (by ID, by Category, All with Pagination), Update, Delete news articles.
- News Category Management: Create, Retrieve (by ID, by Name, All), Update, Delete news categories.
- Food Recipes Management: Create, Retrieve (by ID, by Name, All with Pagination, by Ingredient), Update, Delete food recipes.
- Ingredient Management: Create, Retrieve (by ID, by Name, All with Pagination), Update, Delete ingredients.
- Database Migrations & Seeding: Tools to manage database schema and populate initial data.
- Authentication: JWT-based authentication for secure API access.
- Logging: Built-in system for monitoring and tracking system queries with a web interface.
- Go Version
>= go 1.20
- PostgreSQL Version
>= version 15.0
- Docker & Docker Compose (for Dockerized setup)
- Clone the repository
git clone https://github.com/Revprm/Nutrigrow-Backend.git
- Navigate to the project directory:
cd Nutrigrow-Backend
- Copy the example environment file and configure it:
cp .env.example .env
There are 2 ways to do running
- Build Docker
make up
- Run Initial UUID V4 for Auto Generate UUID
make init-uuid
- Run Migration and Seeder
make migrate-seed
- Configure
.env
with your PostgreSQL credentials:
DB_HOST=localhost
DB_USER=postgres
DB_PASS=
DB_NAME=
DB_PORT=5432
- Open the terminal and follow these steps:
- If you haven't downloaded PostgreSQL, download it first.
- Run:
psql -U postgres
- Create the database according to what you put in
.env
=> if using uuid-ossp or auto generate (check file /entity/user.go):CREATE DATABASE your_database; \c your_database CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; // remove default:uuid_generate_v4() if you not use you can uncomment code in user_entity.go \q
- Run the application:
go run main.go
To run migrations and seed the database while keeping the application running, use the following command:
go run main.go --migrate --seed --run
--migrate
will apply all pending migrations.--seed
will seed the database with initial data.--run
will ensure the application continues running after executing the commands above.
To migrate the database schema
go run main.go --migrate
This command will apply all pending migrations to your PostgreSQL database specified in .env
To seed the database with initial data:
go run main.go --seed
This command will populate the database with initial data using the seeders defined in your application.
You can explore the available API endpoints and their usage through the Postman Documentation: