Skip to content

Yet Another App structure

pieceowater edited this page Mar 28, 2025 · 3 revisions

Template Project Overview

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.


Project Structure

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

Directory Breakdown

  • cmd/
    Contains entry points for the application. For example, main.go initializes 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.


Key Features

  • Modular Design: Encourages separation of concerns and scalability.
  • Ease of Development: Includes a Makefile and Gossiper for streamlined workflows.

Clean Architecture and Domain-Driven Design (DDD)

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:

Clean Architecture Principles

  • 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.

Domain-Driven Design (DDD)

  • 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 and Interfaces

  • 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.

Do What You Want Between Layers

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.

Getting Started

  1. Clone the Repository

    git clone <repository-url>
    cd <repository-name>
  2. Install Dependencies

    go mod tidy
  3. Run the Application

    make run
  4. 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.


Extending the Project

To add a new feature:

  1. Use Gossiper to create a new module under internal/pkg/:

    gossiper gen -m <module-name>
  2. Define controllers (ctrl/) and services (svc/) for the module.

  3. 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!

Clone this wiki locally