-
Notifications
You must be signed in to change notification settings - Fork 0
Yet Another App structure
Welcome to the Template Project! This project provides a robust foundation for building scalable and maintainable Go applications. It includes a module generator, Gossiper, to help you structure your code efficiently.
Below, you'll find detailed instructions on the project structure, setup, and extensibility.
The project is organized as follows:
app/
├── cmd/
│ └── server/
│ └── main.go
├── internal/
│ ├── core/
│ │ ├── cfg/ # Configuration handling
│ │ ├── utils/ # Core utilities
│ └── pkg/
│ ├── mymodule/
│ │ ├── ctrl/ # Controllers for the module
│ │ └── mymodule.ctrl.go
│ │ ├── svc/ # Services for the module
│ │ └── mymodule.svc.go
│ │ └── mymodule_module.go
│ └── router.go # Application routing
│── go.mod # Go module definition
└── Makefile # Development commands
-
cmd/
Contains entry points for the application. For example,main.goinitializes and starts the server. -
internal/
Houses the core utilities, configuration handling, and modular packages:-
core/: Includes configuration (cfg/) and utility functions (utils/). -
pkg/: Contains feature-specific modules, each with:-
ctrl/: Controllers for handling HTTP requests. -
svc/: Services for business logic. -
mymodule_module.go: Module initialization logic.
-
-
router.go: Defines application-wide routing.
-
-
go.mod
The Go module file, which manages dependencies. -
Makefile
A collection of commands to simplify development tasks, such as building, testing, and running the application.
- Modular Design: Encourages separation of concerns and scalability.
-
Ease of Development: Includes a
Makefileand Gossiper for streamlined workflows.
This project is designed with Clean Architecture and Domain-Driven Design (DDD) principles in mind. These approaches ensure that your application is flexible, maintainable, and scalable. Here's how:
- Separation of Concerns: Each layer of the application has a specific responsibility, ensuring that business logic, infrastructure, and user interfaces are decoupled.
- Independence: The core business logic is independent of frameworks, databases, or external systems, making it easier to test and adapt to changes.
- Flexibility Between Layers: You can freely define interactions between layers using interfaces, allowing you to swap implementations (e.g., changing a database or HTTP framework) without affecting the core logic.
- Focus on the Domain: The application is built around the business domain, with clear boundaries and responsibilities for each module.
- Entities and Value Objects: Use entities to represent core business objects and value objects for immutable data.
- Aggregates and Repositories: Group related entities into aggregates and use repositories to manage their persistence.
- Application Services: Encapsulate business use cases in services, ensuring that the domain logic remains clean and reusable.
- Design Patterns: You can implement patterns like Dependency Injection, Factory, or Strategy to enhance flexibility and maintainability.
- Interfaces: Define interfaces for services, repositories, or external dependencies to decouple implementations and enable easier testing.
This architecture gives you the freedom to:
- Add or modify layers as needed.
- Use different design patterns to solve specific problems.
- Replace or extend implementations without breaking the application.
-
Clone the Repository
git clone <repository-url> cd <repository-name>
-
Install Dependencies
go mod tidy
-
Run the Application
make run
-
Generate a New Module
Use Gossiper to create a new feature module:-
Install Gossiper globally:
go install github.com/pieceowater-dev/lotof.lib.gossiper/v2/cmd/gossiper@latest
-
Generate a module:
gossiper gen -m <module-name>
-
Alternatively, for local testing without installation:
go run cmd/gossiper/main.go gen -m <module-name>
For more details, visit the Gossiper repository.
-
To add a new feature:
-
Use Gossiper to create a new module under
internal/pkg/:gossiper gen -m <module-name>
-
Define controllers (
ctrl/) and services (svc/) for the module. -
Register the module in
router.go.
This template is designed to help you kickstart your Go projects with a clean and maintainable structure. Happy coding!