You can join in the development (Open Source). Let's Go!!!
This project implements Clean Architecture principles with the Controller–Service–Repository pattern. This approach emphasizes clear separation of responsibilities across different layers in Golang applications. The architecture helps keep the codebase clean, testable, and scalable by dividing application logic into distinct modules with well-defined boundaries.
>= go 1.20>= version 15.0bash
git clone https://github.com/Caknoooo/go-gin-clean-starter.gitbash
cd go-gin-clean-starterbash
cp .env.example .envbash
make depThere are two ways to run the application:
.env with your PostgreSQL credentials:
bash
DB_HOST=localhost
DB_USER=postgres
DB_PASS=your_password
DB_NAME=your_database
DB_PORT=5432bash
make init-dockerbash
make migrate-seed-dockerhttp://localhost:<port>Docker Migration Commands:
make migrate-docker # Run migrations in Docker
make migrate-status-docker # Show migration status in Docker
make migrate-rollback-docker # Rollback last batch in Docker
make migrate-rollback-batch-docker batch=<number> # Rollback batch in Docker
make migrate-rollback-all-docker # Rollback all in Docker
make migrate-create-docker name=<name> # Create migration in Docker
.env with your PostgreSQL credentials:
bash
DB_HOST=localhost
DB_USER=postgres
DB_PASS=your_password
DB_NAME=your_database
DB_PORT=5432bash
make migrate # Run migrations
make seed # Run seeders (optional)
make migrate-seed # Run Migrations + Seeder
make run # Start the applicationThe project includes a comprehensive Makefile with the following commands:
make dep # Install and tidy dependencies
make run # Run the application locally
make build # Build the application binary
make run-build # Build and run the application
make migrate # Run all pending migrations
make migrate-status # Show migration status
make migrate-rollback # Rollback the last batch
make migrate-rollback-batch batch=<number> # Rollback specific batch
make migrate-rollback-all # Rollback all migrations
make migrate-create name=<migration_name> # Create new migration file
Migration Examples:
make migrate # Run migrations
make migrate-status # Check migration status
make migrate-rollback # Rollback last batch
make migrate-rollback-batch batch=2 # Rollback batch 2
make migrate-rollback-all # Rollback all migrations
make migrate-create name=create_posts_table # Create migration with entity
Note: When creating a migration with format create_*_table, the system will automatically:
- Create the entity file in database/entities/
- Add the entity to the migration file
- Add the entity to database/migration.go AutoMigrate section
make module name=<module_name> # Generate a new module with all necessary files
Example:
make module name=product
This command will automatically create a complete module structure including:
- Controller (product_controller.go)
- Service (product_service.go)
- Repository (product_repository.go)
- DTO (product_dto.go)
- Validation (product_validation.go)
- Routes (routes.go)
- Test files for all components
- Query directory (for custom queries)
You can run migrations, seed the database, and execute scripts while keeping the application running:
go run cmd/main.go --migrate:run --seed --run --script:example_script
Available flags:
- --migrate or --migrate:run: Apply all pending migrations
- --migrate:status: Show migration status
- --migrate:rollback: Rollback the last batch
- --migrate:rollback <batch_number>: Rollback specific batch
- --migrate:rollback:all: Rollback all migrations
- --migrate:create:<migration_name>: Create new migration file
- --seed: Seed the database with initial data
- --script:example_script: Run the specified script (replace example_script with your script name)
- --run: Keep the application running after executing the commands above
go run cmd/main.go --migrate:run # Run all pending migrations
go run cmd/main.go --migrate:status # Show migration status
go run cmd/main.go --migrate:rollback # Rollback last batch
go run cmd/main.go --migrate:rollback 2 # Rollback batch 2
go run cmd/main.go --migrate:rollback:all # Rollback all migrations
go run cmd/main.go --migrate:create:create_posts_table # Create migration
Migration System Features:
- Batch-based migrations: Similar to Laravel, migrations are grouped in batches
- Automatic entity creation: When creating migration with format create_*_table, the system will:
- Automatically create entity file in database/entities/
- Add entity to migration file's AutoMigrate
- Add entity to database/migration.go AutoMigrate section
- Rollback support: Rollback by batch or rollback all migrations
- Status tracking: View which migrations have been run and their batch numbers
go run cmd/main.go --seed
This command will populate the database with initial data using the seeders defined in your application.
go run cmd/main.go --script:example_script
Replace example_script with the actual script name in script.go at the script folder.
Note: If you need the application to continue running after performing migrations, seeding, or executing a script, always append the
--runoption.
The application includes a built-in logging system that allows you to monitor and track system queries. You can access the logs through a modern, user-friendly interface.
To view the logs: 1. Make sure the application is running 2. Open your browser and navigate to:
http://your-domain/logs
Explore the available endpoints and their usage in the Postman Documentation. This documentation provides a comprehensive overview of the API endpoints, including request and response examples.
We welcome contributions! The repository includes templates for issues and pull requests to standardize contributions and improve the quality of discussions and code reviews.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
$ claude mcp add go-gin-clean-starter \
-- python -m otcore.mcp_server <graph>