You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
3
4
4
5
## 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.
6
6
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.
-`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)
9
31
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 📊
11
44
12
45
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.
13
46
14
47
### Accessing Logs
15
48
To view the logs:
16
49
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:
18
52
```bash
19
53
http://your-domain/logs
20
54
```
@@ -25,112 +59,224 @@ http://your-domain/logs
25
59
-**Expandable Entries**: Click on any log entry to view its full content
26
60
-**Modern UI**: Clean and responsive interface with glass-morphism design
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
95
137
```
96
138
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
+
```
101
146
102
-
#### Migrate Database
103
-
To migrate the database schema
147
+
### Development Commands
104
148
```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
106
153
```
107
-
This command will apply all pending migrations to your PostgreSQL database specified in`.env`
108
154
109
-
#### Seeder Database
110
-
To seed the database with initial data:
155
+
### Command Line Arguments
156
+
The application supports various command line arguments:
157
+
111
158
```bash
112
-
go run main.go --seed
159
+
go run main.go --migrate --seed --run --script:example_script
113
160
```
114
-
This command will populate the database with initial data using the seeders defined in your application.
115
161
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:
118
245
```bash
119
-
go run main.go --script:example_script
246
+
make test
120
247
```
121
-
Replace ``example_script`` with the actual script name in**script.go** at script folder
122
248
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
124
255
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 🤝
127
257
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:
130
259
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
132
265
266
+
### Issue Templates
133
267
The repository includes templates for issues and pull requests to standardize contributions and improve the quality of discussions and code reviews.
134
268
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.
0 commit comments