REST API untuk manajemen catatan keuangan menggunakan Go, Echo Framework, dan Clean Architecture.
- Go 1.21+
- Echo v4 - Web framework
- GORM v2 - ORM
- MySQL - Database
- JWT - Authentication
- Viper - Configuration management
- Bcrypt - Password hashing
Project ini menggunakan Clean Architecture pattern yang memisahkan concerns ke dalam beberapa layer:
┌─────────────────────────────────────────────────────────────┐
│ Frameworks & Drivers │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Echo Web │ │ MySQL │ │ External Services │ │
│ │ Framework │ │ Database │ │ (JWT, Bcrypt, etc) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ Interface Adapters │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ HTTP │ │ Repository │ │ Middleware │ │
│ │ Handlers │ │ Implements │ │ (JWT, CORS, etc) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ Use Cases │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Auth │ │ User │ │ Business Logic │ │
│ │ Use Cases │ │ Use Cases │ │ & Validation │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────────┐
│ Entities │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ User │ │ Repository │ │ Domain Rules & │ │
│ │ Entity │ │ Interfaces │ │ Business Objects │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Location:
internal/domain/ - Purpose: Core business logic dan rules
- Contains:
entities/- Domain models (User)repositories/- Repository interfaces
- Dependencies: Tidak bergantung pada layer lain
- Location:
internal/usecases/ - Purpose: Application business rules dan orchestration
- Contains:
auth_usecase.go- Authentication logicuser_usecase.go- User management logiccategory_usecase.go- Category management logictransaction_usecase.go- Transaction management logic
- Dependencies: Hanya bergantung pada Entities
- Location:
internal/interfaces/daninternal/infrastructure/ - Purpose: Adapter untuk external interfaces
- Contains:
interfaces/http/handlers/- HTTP request handlersinterfaces/dto/- Data Transfer Objectsinfrastructure/repositories/- Repository implementationsinfrastructure/database/- Database connections
- Dependencies: Bergantung pada Use Cases dan Entities
- Location:
cmd/,pkg/,config/ - Purpose: External tools, frameworks, dan drivers
- Contains:
cmd/server/- Application entry pointpkg/- Shared utilities (JWT, Hash, Response, Validator)config/- Configuration management
- Dependencies: Bergantung pada semua layer
- Inner layers tidak boleh tahu tentang outer layers
- Outer layers bergantung pada inner layers
- Dependencies selalu mengarah ke dalam (inward)
├── cmd/server/ # 🔴 Application entry point
├── config/ # 🔴 Configuration files
├── database/ # 🔴 Database migrations
├── internal/
│ ├── domain/ # 🔵 Business entities and interfaces
│ │ ├── entities/ # Domain models (User, Category, Transaction)
│ │ └── repositories/ # Repository interfaces
│ ├── infrastructure/ # 🟡 External concerns implementation
│ │ ├── database/ # Database connections
│ │ └── repositories/ # Repository implementations
│ ├── interfaces/ # 🟡 HTTP handlers, DTOs
│ │ ├── dto/ # Data Transfer Objects
│ │ └── http/ # HTTP layer (handlers, middleware, routes)
│ └── usecases/ # 🟢 Business logic
└── pkg/ # 🔴 Shared utilities
├── hash/ # Password hashing
├── jwt/ # JWT token management
├── response/ # HTTP response utilities
└── validator/ # Request validation
✅ Testability - Easy to unit test business logic
✅ Maintainability - Clear separation of concerns
✅ Flexibility - Easy to change frameworks or databases
✅ Independence - Business logic independent of external tools
✅ Scalability - Easy to add new features
git clone <repository-url>
cd go-financial-recordsmake deps# Create MySQL database
mysql -u root -p
CREATE DATABASE financial_records;
# Run migration
make migrate-up# Setup development environment
make dev-setup
# Edit config.yaml with your database credentialsmake runServer akan berjalan di http://localhost:8080
http://localhost:8080/api/v1
Lihat dokumentasi lengkap API di: API Documentation
make help # Show all available commands
make run # Run the application
make build # Build the application
make test # Run tests
make fmt # Format code
make lint # Lint code
make clean # Clean build artifactsmake testmake buildThis project is licensed under the MIT License.