- Overview
- Features
- Architecture
- Technologies Used
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Endpoints
- Contributing
- License
Welcome to the Go Clean Architecture API! This project serves as a foundational template for building scalable and maintainable Go applications. It leverages Clean Architecture principles combined with SOLID design principles to ensure a robust and flexible codebase.
- Clean Architecture & SOLID Principles: Ensures separation of concerns, making the codebase easy to maintain and extend.
- User CRUD Operations: Create, Read, Update, and Delete functionalities for user management.
- JWT Authentication: Secure authentication mechanism using JSON Web Tokens.
- Middleware: Handles authentication and other cross-cutting concerns seamlessly.
- Dockerized Setup: Easily containerize the application with Docker and orchestrate services using Docker Compose.
- Persistent Storage: Utilizes Docker volumes for database persistence.
The project is structured following Clean Architecture, which divides the application into distinct layers:
- Domain Layer: Contains business logic and entities.
- Use Case Layer: Implements application-specific business rules.
- Interface Layer: Handles interactions with external systems (e.g., databases, APIs).
- Frameworks & Drivers Layer: Includes frameworks, tools, and external interfaces like the HTTP server.
This separation ensures that each layer is independent and can be modified without affecting others, promoting scalability and testability.
- Go - Programming language
- JWT - JSON Web Tokens for authentication
- Docker - Containerization
- Docker Compose - Orchestrating multi-container Docker applications
- PostgreSQL - Relational database
Before you begin, ensure you have the following installed on your machine:
-
Clone the Repository:
git clone [email protected]:Casagrande-Lucas/golang-clean-architecture.git cd golang-clean-architecture
-
Install Dependencies
go mod download
- Copy the Example Environment File
cp .env.example .env
- Update the .env file and docker-compose.yml
Open the .env file in your preferred text editor and update the variables as needed.
There are two pre-installed databases, one being MySQL and the other Postgres. In the .env file we have two variable blocks for both databases, postgres by default is commented out, if you want to change it, just comment out the mysql variables and uncomment the postgres ones.
In the docker-compose.yml file we have the two databases again with separate volumes, and once again you will find the postgres information commented out, to change the database, just continue commenting one and uncommenting the other and changing the dependency (depends_on:) from "app" to the desired database.
-
Build and Start Services
docker-compose up -d --build
-
Accessing the API
Once the services are up and running, the API will be accessible at http://localhost:8080
-
Stopping the Services
docker-compose down