Backend Project Structure Go
Hi everyone, today I want to share a Go project structure that I have used and found useful. This project structure is suitable for medium and small projects, and even large projects. The way folders and files are organized in this project structure is similar to other programming languages such as NodeJS or Java. This helps everyone to have a more comprehensive and easier understanding when learning about Go. I hope it will be useful and here is my Go project structure.
.
├── cmd/ # Contains executable applications
│ ├── cli/ # Command-line application
│ ├── cronjob/ # Scheduled jobs
│ └── server/ # Server application
│ └── main.go # Run the application
├── config/ # Configuration for applications
│ └── config.yaml # Main configuration file
├── docs/ # Project documentation
├── global/ # Global variables
├── internal/ # Internal packages
│ ├── controller/ # Handle client requests
│ ├── initialize/ # Initialize necessary components
│ ├── middlewares/ # Server middlewares
│ ├── models/ # Structs representing data
│ ├── repo/ # Query data from the database
│ ├── routers/ # Define routes for the server
│ ├── service/ # Handle business logic
├── migrations/ # Database migration scripts
├── pkg/ # Reusable packages
│ ├── logger/ # Logging for the application
│ ├── response/ # Handle response to the client
│ ├── setting/ # Application settings
│ └── utils/ # Utility functions
├── scripts/ # Development support scripts
├── tests/ # Test cases for the application
├── third_party/ # Third-party libraries
├── .gitignore # Git ignore file
├── go.mod # Go dependencies management
├── go.sum # Contains checksums of dependencies
├── LICENSE # Project license
└── README.md # Project description
This is the result of my project structure on Visual Studio Code
If you found this article useful and interesting, please share it with your friends and family. I hope you found it helpful. Thanks for reading 🙏
Let’s get connected! You can find me on:
- Medium: https://quanghieudev.medium.com/
- Dev: https://dev.to/hieunguyendev
- Linkedin: https://www.linkedin.com/in/hiếu-nguyễn-1a38132bb/
- Buy Me a Coffee: https://buymeacoffee.com/quanghieudev