Go-Driven Domain Design (DDD) Project
This project showcases the implementation of Domain-Driven Design (DDD) principles using Go, focusing on both tactical and strategic elements. The development process is OpenAPI 3.0 documentation-first, ensuring that the API is well-defined and consistent before implementation.
Table of Contents
- Project Goals
- Directory Structure
- Features
- Installation
- How It Works
- Contributing
- License
Project Goals
-
Apply DDD Tactical and Strategic Design:
- Develop self-managing entities, aggregates, and domain services.
- Establish bounded contexts and strategic communication patterns.
-
Documentation-First Approach:
- Use OpenAPI 3.0 specifications to design and document APIs before implementation.
- Automate code generation and testing based on the OpenAPI specification.
-
Flexible and Maintainable Architecture:
- Focus on separation of concerns for scalability and clarity.
Directory Structure
The project follows a modular structure for clarity and maintainability:
.
├── api # OpenAPI 3.0 specifications and generated code
├── internal
│ ├── domain # Core domain logic (entities, value objects, aggregates)
│ ├── ports # Interfaces for external systems (e.g., repository, services)
│ ├── adapters # Implementation of ports (e.g., database, API clients)
│ └── app # Application services (use cases and workflows)
└── pkg # Shared utilities, helpers, or common libraries
Features
Installation
Prerequisites
- Go 1.23+ (consider upgrading to 1.23)
- Tools for OpenAPI code generation (e.g.,
oapi-codegen
)
Steps
-
Clone the repository:
git clone <repository_url>
cd <repository_name>
-
Install dependencies:
go mod tidy
-
Generate code from OpenAPI specs:
oapi-codegen -generate types -o internal/app/api_types.gen.go api/api.yml
oapi-codegen -generate chi-server -o internal/app/api_server.gen.go api/api.yml
-
Run the application:
go run main.go
How It Works
-
OpenAPI Specification:
- Define API contracts in
api/api.yml
.
-
Code Generation:
- Use
oapi-codegen
to generate server interfaces, request/response types, and handlers.
-
DDD Principles:
- Domain entities are located in
internal/domain
.
- Communication between layers happens through
ports
and their implementations in adapters
.
-
Implementation:
- Develop application logic in the
app
layer, leveraging domain logic and adapters.
Contributing
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a feature branch:
git checkout -b feature/<feature_name>
- Commit your changes:
git commit -m "Add <feature_name>"
- Push to your branch:
git push origin feature/<feature_name>
- Open a pull request.
License
This project is licensed under the MIT License.