Skip to content

Repository files navigation

Financial Records API

REST API untuk manajemen catatan keuangan menggunakan Go, Echo Framework, dan Clean Architecture.

Tech Stack

  • Go 1.21+
  • Echo v4 - Web framework
  • GORM v2 - ORM
  • MySQL - Database
  • JWT - Authentication
  • Viper - Configuration management
  • Bcrypt - Password hashing

Clean Architecture

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      │ │
│  └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

Layer Descriptions:

🔵 Entities (Domain Layer)

  • Location: internal/domain/
  • Purpose: Core business logic dan rules
  • Contains:
    • entities/ - Domain models (User)
    • repositories/ - Repository interfaces
  • Dependencies: Tidak bergantung pada layer lain

🟢 Use Cases (Application Layer)

  • Location: internal/usecases/
  • Purpose: Application business rules dan orchestration
  • Contains:
    • auth_usecase.go - Authentication logic
    • user_usecase.go - User management logic
    • category_usecase.go - Category management logic
    • transaction_usecase.go - Transaction management logic
  • Dependencies: Hanya bergantung pada Entities

🟡 Interface Adapters

  • Location: internal/interfaces/ dan internal/infrastructure/
  • Purpose: Adapter untuk external interfaces
  • Contains:
    • interfaces/http/handlers/ - HTTP request handlers
    • interfaces/dto/ - Data Transfer Objects
    • infrastructure/repositories/ - Repository implementations
    • infrastructure/database/ - Database connections
  • Dependencies: Bergantung pada Use Cases dan Entities

🔴 Frameworks & Drivers

  • Location: cmd/, pkg/, config/
  • Purpose: External tools, frameworks, dan drivers
  • Contains:
    • cmd/server/ - Application entry point
    • pkg/ - Shared utilities (JWT, Hash, Response, Validator)
    • config/ - Configuration management
  • Dependencies: Bergantung pada semua layer

Dependency Rule

  • Inner layers tidak boleh tahu tentang outer layers
  • Outer layers bergantung pada inner layers
  • Dependencies selalu mengarah ke dalam (inward)

Project Structure

├── 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

Benefits of Clean Architecture

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

Setup

1. Clone Repository

git clone <repository-url>
cd go-financial-records

2. Install Dependencies

make deps

3. Setup Database

# Create MySQL database
mysql -u root -p
CREATE DATABASE financial_records;

# Run migration
make migrate-up

4. Configuration

# Setup development environment
make dev-setup

# Edit config.yaml with your database credentials

5. Run Application

make run

Server akan berjalan di http://localhost:8080

API Documentation

Base URL

http://localhost:8080/api/v1

Lihat dokumentasi lengkap API di: API Documentation

Development

Available Commands

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 artifacts

Running Tests

make test

Build for Production

make build

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages