This project simulates a banking system to demonstrate various Go programming concepts and design patterns without implementing actual REST calls or database communication.
The banking system simulation includes the following features:
- Customer management
- Account management (checking, savings, business)
- Transaction processing (deposits, withdrawals, transfers)
- External system integration via adapters
- Notification system with adapter pattern implementation
- Generic repository pattern using Go generics
-
Structs and Interfaces
- Modeling domain entities with structs (Customer, Account, Transaction)
- Interface-based design for loose coupling
- Interface implementations for different behaviors
-
Pointers and References
- Pointer receivers for methods that modify state
- Passing pointers to repositories to ensure proper data manipulation
-
Package Organization
- Modular code organization with domain-specific packages
- Clean separation of concerns across packages
-
Generics
- Generic repository implementation for type-safe data access
- Type constraints with interfaces
-
Design Patterns
- Adapter Pattern: For external system communication and notifications
- Repository Pattern: For data access abstraction
- Dependency Injection: For service composition
bankingsystem/
├── main.go # Application entry point
└── pkg/ # Package directory
├── models/ # Domain models
│ ├── account.go # Account entity
│ ├── customer.go # Customer entity
│ └── transaction.go # Transaction entity
├── services/ # Business logic
│ ├── banking_service.go # Core banking functionality
│ └── interfaces.go # Service interfaces
├── adapters/ # External system adapters
│ ├── external_systems.go # External system integration
│ ├── generic_repository.go # Generic repository implementation
│ └── memory_repository.go # In-memory data storage
└── utils/ # Utility functions
└── id_generator.go # UUID generation
To run the banking system simulation:
go run main.goThis will execute the simulation which demonstrates:
- Creating customers and accounts
- Performing banking operations (deposits, withdrawals, transfers)
- Using the adapter pattern to switch between notification methods
- Demonstrating external system integration
- Using the generic repository pattern
The adapter pattern is implemented in two ways:
NotificationAdapter: Allows the system to switch between email and SMS notifications while providing a unified interfaceReportingAdapter: Allows the system to interact with external reporting systems
The project implements both specific and generic repositories:
- Type-specific repositories:
InMemoryCustomerRepository,InMemoryAccountRepository, etc. - Generic repository:
GenericRepository[T Entity]which works with any type that implements theEntityinterface
Services are composed by injecting their dependencies, making them testable and modular.