This project is a Health Tracker API that allows users to manage food entities and meals while maintaining detailed logs and error handling. It uses Go with a clean and scalable structure.
- Food entity CRUD operations.
- Logging using
zap
. - CI pipeline for linting and testing with
golangci-lint
. - Robust error handling.
- Follows clean code principles with separated concerns (repository, service, handler).
- Docker setup for Postgres and Redis.
.
├── Makefile
├── cmd
│ └── main.go # Application entry point
├── docker-compose.yml # Docker services (PostgreSQL, Redis, etc.)
├── go.mod # Go module dependencies
├── go.sum # Dependency lock file
├── internal # Main application code
│ ├── app
│ │ └── food # Food module
│ │ ├── factory.go # Factory for initializing the handler
│ │ ├── handler.go # Handles HTTP interactions
│ │ ├── model.go # Defines the Food struct
│ │ ├── repository.go # Database operations for Food
│ │ ├── routes.go # Routes for Food endpoints
│ │ └── service.go # Business logic for Food
│ └── infra
│ ├── config # Configuration management
│ │ └── config.go
│ ├── db # Database connection setup
│ │ └── db.go
│ ├── errors # Custom error handling
│ │ ├── errors.go
│ │ └── http_errors.go
│ ├── logger # Logging setup using zap
│ │ └── logger.go
│ └── middleware # HTTP middleware
│ ├── json.go # JSON response middleware
│ ├── logging.go # Request logging middleware
│ └── recovery.go # Error recovery middleware
├── logs
│ └── app.log # Log output file
├── migrations # Database migrations
│ ├── 000001_init_schema.down.sql
│ └── 000001_init_schema.up.sql
├── pkg # Reserved for reusable libraries
└── tmp # Temporary files (e.g., Air logs)
├── air.log
└── main
- Go 1.23+ installed.
- Docker and Docker Compose installed.
- Air.
- golang-migrate.
git clone https://github.com/your-repo/health-tracker-api.git
cd health-tracker-api
Create a .env
file in the root directory:
# Environment
ENV=DEV
# Application
APP_PORT=1221
# Database
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=postgres
DB_HOST=localhost
DB_PORT=5432
-
Start PostgreSQL and Redis services:
docker compose up -d
-
Apply database migrations:
make migrate-up
-
Start the application:
make run
-
Start the application in dev mode:
make dev
-
Run linting:
make lint
- Start PostgreSQL and Redis locally.
- Apply database migrations:
make migrate-up
- Run the application:
go run cmd/main.go
- GET
/health
- Returns the health status of the API.
-
GET
/foods
- Query food items with optional
limit
andoffset
.
- Query food items with optional
-
POST
/foods
- Add a new food item (requires JSON payload).
-
GET
/foods/{id}
- Retrieve a food item by its ID.
-
PUT
/foods/{id}
- Update an existing food item by its ID.
-
DELETE
/foods/{id}
- Delete a food item by its ID.
-
Install Air:
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s
-
Run the application with hot reload:
air
To be implemented.
-
Prepare the
develop
Branch- Ensure
develop
is up to date:git checkout develop git pull origin develop
- Run final checks:
make lint make test
- Update
README.md
andCHANGELOG.md
if needed.
- Ensure
-
Create a Pull Request
- Push the latest changes:
git push origin develop
- Open a PR from
develop
tomain
:- Title:
Release vX.Y.Z
- Description: Include features, fixes, and testing status.
- Title:
- Request reviews and wait for approval.
- Push the latest changes:
-
Merge the PR
- Merge the PR into
main
using GitHub. - Pull the latest changes locally:
git checkout main git pull origin main
- Merge the PR into
-
Tag the Release
- Create a tag for the release:
git tag -a vX.Y.Z -m "Release version X.Y.Z" git push origin vX.Y.Z
- Update the GitHub Releases section with details of the release.
- Create a tag for the release:
-
Deployment
- If ready, deploy the release to production.
- Automate this step using GitHub Actions or a similar CI/CD tool.
-
Next Development Cycle
- Switch back to
develop
:git checkout develop
- Create a new branch for the next feature or fix:
git checkout -b feature/next-feature
- Switch back to
This project is licensed under the MIT License. See the LICENSE
file for details.