| 8 | ) |
| 9 | |
| 10 | func main() { |
| 11 | serviceName := flag.String("name", "", "Name of the service (e.g., user, payment)") |
| 12 | flag.Parse() |
| 13 | |
| 14 | if *serviceName == "" { |
| 15 | fmt.Println("Please provide a service name using -name flag") |
| 16 | os.Exit(1) |
| 17 | } |
| 18 | |
| 19 | // Create service directory structure |
| 20 | basePath := filepath.Join("services", *serviceName+"-service") |
| 21 | dirs := []string{ |
| 22 | "cmd", |
| 23 | "internal/domain", |
| 24 | "internal/service", |
| 25 | "internal/infrastructure/events", |
| 26 | "internal/infrastructure/grpc", |
| 27 | "internal/infrastructure/repository", |
| 28 | "pkg/types", |
| 29 | } |
| 30 | |
| 31 | for _, dir := range dirs { |
| 32 | fullPath := filepath.Join(basePath, dir) |
| 33 | if err := os.MkdirAll(fullPath, 0755); err != nil { |
| 34 | fmt.Printf("Error creating directory %s: %v\n", dir, err) |
| 35 | os.Exit(1) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Create an empty README.md |
| 40 | readmePath := filepath.Join(basePath, "README.md") |
| 41 | readmeContent := fmt.Sprintf(`# %s service |
| 42 | |
| 43 | This service handles all %s-related operations in the system. |
| 44 | |
| 45 | ## Architecture |
| 46 | |
| 47 | The service follows Clean Architecture principles with the following structure: |
| 48 | |
| 49 | ` + "```" + ` |
| 50 | services/%s-service/ |
| 51 | ├── cmd/ # Application entry points |
| 52 | │ └── main.go # Main application setup |
| 53 | ├── internal/ # Private application code |
| 54 | │ ├── domain/ # Business domain models and interfaces |
| 55 | │ ├── service/ # Business logic implementation |
| 56 | │ │ └── service.go # Service implementations |
| 57 | │ └── infrastructure/ # External dependencies implementations (abstractions) |
| 58 | │ ├── events/ # Event handling (RabbitMQ) |
| 59 | │ ├── grpc/ # gRPC server handlers |
| 60 | │ └── repository/ # Data persistence |
| 61 | ├── pkg/ # Public packages |
| 62 | │ └── types/ # Shared types and models |
| 63 | └── README.md # This file |
| 64 | ` + "```" + ` |
| 65 | |
| 66 | ### Layer Responsibilities |
| 67 | |