Skip to content

Commit b2be356

Browse files
committed
docs: update LICENSE year and modify README for Twitter Clone API details
1 parent b55d66b commit b2be356

File tree

2 files changed

+242
-96
lines changed

2 files changed

+242
-96
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 M Naufal Badruttamam
3+
Copyright (c) 2025 Lab RPL ITS
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 241 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
1-
# Golang Gin Gorm Starter
2-
You can join in the development (Open Source). **Let's Go!!!**
1+
# Twitter Clone API 🐦
2+
3+
A modern Twitter clone API built with Go, Gin, and GORM following Clean Architecture principles. This project provides a complete backend solution for a Twitter-like social media platform with user authentication, posts, likes, and real-time logging.
34

45
## Introduction 👋
5-
> Clean Architecture is an approach to organizing code in an application that focuses on separating responsibilities and dependencies between components. In the context of Golang, Clean Architecture refers to the application of Clean Architecture principles in developing applications using the Go programming language.
66

7+
This project implements Clean Architecture principles in Go, providing a well-structured, maintainable, and scalable API for a Twitter clone application. The architecture separates concerns into distinct layers (controllers, services, repositories, entities) making the codebase easy to understand, test, and extend.
8+
9+
### Key Features ✨
10+
11+
- **User Management**: Registration, login, profile management
12+
- **Post System**: Create, read, update, delete posts
13+
- **Like System**: Like and unlike posts
14+
- **JWT Authentication**: Secure user authentication
15+
- **Real-time Logging**: Built-in logging system with web interface
16+
- **Clean Architecture**: Well-structured codebase following best practices
17+
- **Docker Support**: Easy deployment with Docker and Docker Compose
18+
- **Database Migrations**: Automated database schema management
19+
- **Testing**: Comprehensive test coverage
20+
21+
## API Endpoints 📋
722

8-
![image](https://github.com/user-attachments/assets/0b011bcc-f9c6-466e-a9da-964cce47a8bc)
23+
### User Endpoints (`/api/user`)
24+
- `POST /register` - User registration
25+
- `POST /login` - User authentication
26+
- `POST /check-username` - Check username availability
27+
- `GET /me` - Get current user profile (authenticated)
28+
- `GET /:username` - Get user by username
29+
- `GET /:username/posts` - Get posts by user
30+
- `PATCH /update` - Update user profile (authenticated)
931

10-
## Logs Feature 📋
32+
### Post Endpoints (`/api/post`)
33+
- `POST /` - Create new post (authenticated)
34+
- `GET /:post_id` - Get post by ID
35+
- `DELETE /:post_id` - Delete post (authenticated)
36+
- `PUT /:post_id` - Update post (authenticated)
37+
- `GET /` - Get all posts
38+
39+
### Like Endpoints (`/api/likes`)
40+
- `PUT /:post_id` - Like a post (authenticated)
41+
- `DELETE /:post_id` - Unlike a post (authenticated)
42+
43+
## Logs Feature 📊
1144

1245
The application includes a built-in logging system that allows you to monitor and track system queries. You can access the logs through a modern, user-friendly interface.
1346

1447
### Accessing Logs
1548
To view the logs:
1649
1. Make sure the application is running
17-
2. Open your browser and navigate to:
50+
2. Set `IS_LOGGER=true` in your environment variables
51+
3. Open your browser and navigate to:
1852
```bash
1953
http://your-domain/logs
2054
```
@@ -25,112 +59,224 @@ http://your-domain/logs
2559
- **Expandable Entries**: Click on any log entry to view its full content
2660
- **Modern UI**: Clean and responsive interface with glass-morphism design
2761

28-
![Logs Interface](https://github.com/user-attachments/assets/adda0afb-a1e4-4e05-b44e-87225fe63309)
29-
30-
31-
## Prerequisite 🏆
32-
- Go Version `>= go 1.20`
33-
- PostgreSQL Version `>= version 15.0`
34-
35-
## How To Use
36-
1. Clone the repository
37-
```bash
38-
git clone https://github.com/Lab-RPL-ITS/twitter-clone-api.git
39-
```
40-
2. Navigate to the project directory:
41-
```bash
42-
cd twitter-clone-api
43-
```
44-
3. Copy the example environment file and configure it:
45-
```bash
46-
cp .env.example .env
47-
```
48-
There are 2 ways to do running
49-
### With Docker
50-
1. Build Docker
51-
```bash
52-
make up
53-
```
54-
2. Run Initial UUID V4 for Auto Generate UUID
55-
```bash
56-
make init-uuid
57-
```
58-
3. Run Migration and Seeder
59-
```bash
60-
make migrate-seed
61-
```
62-
63-
### Without Docker
64-
1. Configure `.env` with your PostgreSQL credentials:
65-
```bash
66-
DB_HOST=localhost
67-
DB_USER=postgres
68-
DB_PASS=
69-
DB_NAME=
70-
DB_PORT=5432
71-
```
72-
2. Open the terminal and follow these steps:
73-
- If you haven't downloaded PostgreSQL, download it first.
74-
- Run:
75-
```bash
76-
psql -U postgres
77-
```
78-
- Create the database according to what you put in `.env` => if using uuid-ossp or auto generate (check file **/entity/user.go**):
79-
```bash
80-
CREATE DATABASE your_database;
81-
\c your_database
82-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; // remove default:uuid_generate_v4() if you not use you can uncomment code in user_entity.go
83-
\q
84-
```
85-
3. Run the application:
86-
```bash
87-
go run main.go
88-
```
89-
90-
## Run Migrations, Seeder, and Script
91-
To run migrations, seed the database, and execute a script while keeping the application running, use the following command:
62+
## Prerequisites 🏆
63+
- Go Version `>= 1.23.0`
64+
- PostgreSQL Version `>= 15.0`
65+
- Docker and Docker Compose (for containerized setup)
66+
67+
## Quick Start 🚀
68+
69+
### Option 1: Using Docker (Recommended)
70+
71+
1. **Clone the repository**
72+
```bash
73+
git clone https://github.com/Lab-RPL-ITS/twitter-clone-api.git
74+
cd twitter-clone-api
75+
```
76+
77+
2. **Set up environment variables**
78+
```bash
79+
cp .env.example .env
80+
# Edit .env with your configuration
81+
```
82+
83+
3. **Start the application**
84+
```bash
85+
make up
86+
```
87+
88+
4. **Initialize database**
89+
```bash
90+
make init-uuid
91+
make migrate-seed
92+
```
93+
94+
5. **Access the API**
95+
- API: `http://localhost:8888`
96+
- Nginx: `http://localhost:81`
97+
- Logs: `http://localhost:8888/logs` (if IS_LOGGER=true)
9298

99+
### Option 2: Local Development
100+
101+
1. **Clone and navigate**
102+
```bash
103+
git clone https://github.com/Lab-RPL-ITS/twitter-clone-api.git
104+
cd twitter-clone-api
105+
```
106+
107+
2. **Set up environment variables**
108+
```bash
109+
cp .env.example .env
110+
# Configure your PostgreSQL credentials in .env
111+
```
112+
113+
3. **Set up PostgreSQL**
114+
```bash
115+
# Create database and enable UUID extension
116+
psql -U postgres
117+
CREATE DATABASE your_database;
118+
\c your_database
119+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
120+
\q
121+
```
122+
123+
4. **Install dependencies and run**
124+
```bash
125+
go mod tidy
126+
go run main.go
127+
```
128+
129+
## Available Commands 🛠️
130+
131+
### Docker Commands
93132
```bash
94-
go run main.go --migrate --seed --run --script:example_script
133+
make up # Start all services
134+
make down # Stop all services
135+
make logs # View logs
136+
make init-docker # Build and start services
95137
```
96138

97-
- ``--migrate`` will apply all pending migrations.
98-
- ``--seed`` will seed the database with initial data.
99-
- ``--script:example_script`` will run the specified script (replace ``example_script`` with your script name).
100-
- ``--run`` will ensure the application continues running after executing the commands above.
139+
### Database Commands
140+
```bash
141+
make migrate # Run database migrations
142+
make seed # Seed database with initial data
143+
make migrate-seed # Run both migrations and seeding
144+
make init-uuid # Initialize UUID extension
145+
```
101146

102-
#### Migrate Database
103-
To migrate the database schema
147+
### Development Commands
104148
```bash
105-
go run main.go --migrate
149+
make run # Run the application locally
150+
make build # Build the application
151+
make test # Run tests
152+
make dep # Install dependencies
106153
```
107-
This command will apply all pending migrations to your PostgreSQL database specified in `.env`
108154

109-
#### Seeder Database
110-
To seed the database with initial data:
155+
### Command Line Arguments
156+
The application supports various command line arguments:
157+
111158
```bash
112-
go run main.go --seed
159+
go run main.go --migrate --seed --run --script:example_script
113160
```
114-
This command will populate the database with initial data using the seeders defined in your application.
115161

116-
#### Script Run
117-
To run a specific script:
162+
- `--migrate` - Apply database migrations
163+
- `--seed` - Seed database with initial data
164+
- `--script:script_name` - Run a specific script
165+
- `--run` - Keep the application running after executing commands
166+
167+
## Project Structure 📁
168+
169+
```
170+
twitter-clone-api/
171+
├── config/ # Configuration files
172+
├── controller/ # HTTP controllers
173+
├── dto/ # Data Transfer Objects
174+
├── entity/ # Database entities/models
175+
├── helpers/ # Helper functions
176+
├── middleware/ # HTTP middleware
177+
├── migrations/ # Database migrations
178+
├── provider/ # Dependency injection
179+
├── repository/ # Data access layer
180+
├── routes/ # API route definitions
181+
├── script/ # Utility scripts
182+
├── service/ # Business logic layer
183+
├── tests/ # Test files
184+
├── utils/ # Utility functions
185+
├── docker/ # Docker configuration
186+
├── main.go # Application entry point
187+
├── go.mod # Go module file
188+
├── docker-compose.yml
189+
└── Makefile # Build and deployment commands
190+
```
191+
192+
## Environment Variables 🔧
193+
194+
Create a `.env` file with the following variables:
195+
196+
```env
197+
# Application
198+
APP_NAME=twitter-clone-api
199+
APP_ENV=development
200+
PORT=8888
201+
IS_LOGGER=true
202+
203+
# Database
204+
DB_HOST=localhost
205+
DB_USER=postgres
206+
DB_PASS=your_password
207+
DB_NAME=twitter_clone
208+
DB_PORT=5432
209+
210+
# JWT
211+
JWT_SECRET=your_jwt_secret_key
212+
213+
# Email (optional)
214+
SMTP_HOST=smtp.gmail.com
215+
SMTP_PORT=587
216+
SMTP_USER=your_email@gmail.com
217+
SMTP_PASS=your_email_password
218+
```
219+
220+
## API Documentation 📚
221+
222+
### Postman Collection
223+
You can explore the available endpoints and their usage in the [Postman Documentation](https://documenter.getpostman.com/view/28076994/2sB2cYbf38). This documentation provides a comprehensive overview of the API endpoints, including request and response examples.
224+
225+
### Authentication
226+
Most endpoints require JWT authentication. Include the JWT token in the Authorization header:
227+
```
228+
Authorization: Bearer <your_jwt_token>
229+
```
230+
231+
## Development 🔧
232+
233+
### Hot Reload
234+
For development with hot reload, the project includes Air configuration:
235+
```bash
236+
# Install Air
237+
go install github.com/cosmtrek/air@latest
238+
239+
# Run with hot reload
240+
air
241+
```
242+
243+
### Testing
244+
Run the test suite:
118245
```bash
119-
go run main.go --script:example_script
246+
make test
120247
```
121-
Replace ``example_script`` with the actual script name in **script.go** at script folder
122248

123-
If you need the application to continue running after performing migrations, seeding, or executing a script, always append the ``--run`` option.
249+
### Code Quality
250+
The project follows Go best practices and Clean Architecture principles:
251+
- Separation of concerns
252+
- Dependency injection
253+
- Interface-based design
254+
- Comprehensive error handling
124255

125-
## What did you get?
126-
By using this template, you get a ready-to-go architecture with pre-configured endpoints. The template provides a structured foundation for building your application using Golang with Clean Architecture principles.
256+
## Contributing 🤝
127257

128-
### Postman Documentation
129-
You can explore the available endpoints and their usage in the [Postman Documentation](https://documenter.getpostman.com/view/29665461/2s9YJaZQCG). This documentation provides a comprehensive overview of the API endpoints, including request and response examples, making it easier to understand how to interact with the API.
258+
We welcome contributions! Please see our contributing guidelines:
130259

131-
### Issue / Pull Request Template
260+
1. Fork the repository
261+
2. Create a feature branch
262+
3. Make your changes
263+
4. Add tests for new functionality
264+
5. Submit a pull request
132265

266+
### Issue Templates
133267
The repository includes templates for issues and pull requests to standardize contributions and improve the quality of discussions and code reviews.
134268

135-
- **Issue Template**: Helps in reporting bugs or suggesting features by providing a structured format to capture all necessary information.
136-
- **Pull Request Template**: Guides contributors to provide a clear description of changes, related issues, and testing steps, ensuring smooth and efficient code reviews.
269+
## License 📄
270+
271+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
272+
273+
## Support 💬
274+
275+
If you have any questions or need help, please:
276+
- Open an issue on GitHub
277+
- Check the existing issues for solutions
278+
- Review the API documentation
279+
280+
---
281+
282+
**Happy Coding! 🚀**

0 commit comments

Comments
 (0)