Skip to content

yanun0323/clean_architecture

Repository files navigation

Go Clean Architecture TodoApp

English 繁體中文 简体中文 日本語 한국어

This is a Todo application implemented in Go language following the Clean Architecture principles.

Project Structure

The project follows Clean Architecture principles, decoupling business logic from external dependencies to improve code testability and maintainability.

.
├── cmd                 # Application entry points
│   ├── gen             # Data model generation tools
│   └── server          # Main application server
├── config              # Configuration files and related functionality
├── database            # Database migrations and table definitions
│   └── migration       # Database migration scripts
├── internal            # Internal code
│   ├── adaptor         # Interface definitions between layers
│   ├── delivery        # External input layer (REST API)
│   ├── entity          # Domain entities
│   ├── repository      # Data persistence layer
│   └── usecase         # Business logic layer
├── infrastructure      # Infrastructure code
└── pkg                 # Shared utilities and functions

Technology Stack

  • Go 1.24
  • Uber FX (Dependency Injection Framework)
  • GORM (ORM Framework)
  • SQLite (Database)
  • Goose (Database Migration Tool)

Design Patterns

This project uses Clean Architecture design pattern, dividing the application into the following layers:

  1. Entity Layer: Contains business entities and business rules
  2. UseCase Layer: Contains application-specific business rules
  3. Repository Layer: Responsible for data persistence
  4. Delivery Layer: Handles external requests and responses

Features

  • Create todos
  • List todos (filterable by completion status)
  • Update todos
  • Delete todos
  • Pagination functionality

Quick Start

Prerequisites

  • Go 1.24 or higher
  • Goose (for database migrations)

Installation

  1. Clone the project:
git clone [YOUR_PROJECT_URL]
cd clean_architecture
  1. Install dependencies:
go mod download

Running

  1. Run database migrations and start the application:
make run
  1. Generate data model code (if needed):
make gen

Database Management

  • Run database migrations:
make migrate.up
  • Rollback database migrations:
make migrate.down

API Endpoints

Method Path Description
POST /todos Create a todo
GET /todos Get list of todos
PUT /todos/{id} Update a todo
DELETE /todos/{id} Delete a todo

Development Guide

Directory Structure Description

  • cmd: Contains main program entry points
  • config: Application configuration settings
  • database: Database-related files
  • internal: Internal application code, not accessible externally
    • adaptor: Interface definition layer, defines interaction interfaces between layers
    • delivery: Handles HTTP requests and responses
    • entity: Business entity definitions
    • repository: Data access layer
    • usecase: Business logic layer
  • pkg: Function libraries that can be referenced by external projects

Adding New Features

To add new features, it is recommended to follow this order:

  1. Define entities in internal/entity
  2. Define interfaces in internal/adaptor
  3. Implement data access layer in internal/repository
  4. Implement business logic in internal/usecase
  5. Implement API endpoints in internal/delivery

Testing

Testing framework not yet implemented.

Contribution Guidelines

Pull requests and issue discussions for problems or feature suggestions are welcome.

License

Please specify your license terms.

About

A Todo application implemented in Go language following the Clean Architecture principles.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published