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.
-
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.
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
-
Domain-Centric Design:
- Encapsulate business logic within the
domainlayer. - Use
portsandadaptersfor clean dependency inversion.
- Encapsulate business logic within the
-
OpenAPI 3.0 Documentation-First:
- Define APIs in the
apidirectory usingapi.yml. - Generate server stubs and client code using tools like
oapi-codegen.
- Define APIs in the
-
Extensibility and Modularity:
- Decouple domain logic from infrastructure to facilitate changes.
- Go 1.23+ (consider upgrading to 1.23)
- Tools for OpenAPI code generation (e.g.,
oapi-codegen)
-
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
-
OpenAPI Specification:
- Define API contracts in
api/api.yml.
- Define API contracts in
-
Code Generation:
- Use
oapi-codegento generate server interfaces, request/response types, and handlers.
- Use
-
DDD Principles:
- Domain entities are located in
internal/domain. - Communication between layers happens through
portsand their implementations inadapters.
- Domain entities are located in
-
Implementation:
- Develop application logic in the
applayer, leveraging domain logic and adapters.
- Develop application logic in the
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.
This project is licensed under the MIT License.