Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,22 @@ The DIP promotes high-level modules (e.g., use cases) to depend on abstractions

## πŸ—οΈ How To Run

setup environment and running on local
Start MySQL Container
```bash
make run # Start the database, run migrations, and start the application locally
make setup # Start MySQL database in Docker container
```

Run Database Migrations
```bash
make migrate-up # Apply database migrations
```

Run Application Locally
```bash
make run # Setup environment, run migrations, and start the application
```



## ✨ References

Expand Down
20 changes: 8 additions & 12 deletions config/config-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ App:
Name: "golang-clean-architecture"
Version: "v0.0.1"
Scheme: "http"
Host: "localhost:3002"
Host: "localhost:9090"
Environment: local #local,development,staging,production

Server:
Expand All @@ -11,21 +11,17 @@ Server:
TimeZone: "Asia/Jakarta"


Database:
Host: 127.0.0.1
Port: 3306
Name: users
User: root
Password: pwd
Database:
Host: "127.0.0.1"
Port: "3307"
DBName: "golang_clean_architecture"
UserName: "root"
Password: "pwd"
Debug: true

Authentication:
Key: DoWithLogic!@#

Observability:
Enable: false
Mode: "otlp/http"

Redis:
Addr: "localhost:6379"
Password: ""
DB: 0
13 changes: 7 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
AppConfig struct {
Name string
Version string
Schema string
Scheme string
Host string
Environment string
}
Expand All @@ -38,11 +38,12 @@ type (

// DatabaseConfig holds the configuration for the database connection.
DatabaseConfig struct {
Host string
Port int
Name string
User string
Password string
Host string // The host address of the database.
Port string // The port number of the database.
DBName string // The name of the database.
UserName string // The username for connecting to the database.
Password string // The password for connecting to the database.
Debug bool // The Debug for debugging when query executed.
}

RedisConfig struct {
Expand Down
20 changes: 8 additions & 12 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ App:
Name: "golang-clean-architecture"
Version: "v0.0.1"
Scheme: "http"
Host: "localhost:3002"
Host: "localhost:9090"
Environment: local #local,development,staging,production

Server:
Port: "9090"
Debug: true
TimeZone: "Asia/Jakarta"

Database:
Host: 127.0.0.1
Port: 3306
Name: users
User: root
Password: pwd
Database:
Host: "127.0.0.1"
Port: "3307"
DBName: "golang_clean_architecture"
UserName: "root"
Password: "pwd"
Debug: true

Authentication:
Key: DoWithLogic!@#

Observability:
Enable: false
Mode: "otlp/http"

Redis:
Addr: "localhost:6379"
Password: ""
DB: 0
29 changes: 18 additions & 11 deletions database/mysql/migration/20230924142159_add_user_table.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` text NOT NULL,
`fullname` varchar(255) NOT NULL,
`phone_number` varchar(15) NOT NULL,
`user_type` varchar(50) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`created_at` timestamp NOT NULL,
`updated_at` timestamp DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`contact_type` ENUM('EMAIL', 'PHONE') NOT NULL,
`contact_value` VARCHAR(320) NOT NULL,
`birth_date` DATE NULL,
`language` ENUM('EN', 'ID') NOT NULL DEFAULT 'ID',
`password` VARCHAR(255) NOT NULL,
`status` ENUM('PENDING', 'ACTIVE', 'REJECT', 'CLOSED') NOT NULL DEFAULT 'PENDING',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` TIMESTAMP NULL DEFAULT NULL,

PRIMARY KEY (`id`),
UNIQUE KEY `idx_contact` (`contact_type`, `contact_value`),
INDEX `idx_status` (`status`),
INDEX `idx_created_at` (`created_at`),
INDEX `idx_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- +goose StatementEnd

Expand Down
35 changes: 0 additions & 35 deletions docker-compose.yml

This file was deleted.

13 changes: 13 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Golang Clean Architecture

This is an example of implementation of Clean Architecture with S.O.L.I.D Principles in Go (Golang) projects.

Rule of Clean Architecture by Uncle Bob

- Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
- Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
- Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
- Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.
- Independent of any external agency. In fact your business rules simply don’t know anything at all about the outside world.

More at https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
Loading