A feature-rich REST API prototype designed for managing an online learning platform, built with Go, using Gin as the web framework and Sqlite3 for database interactions. This API allows course management, user management, enrollment handling, and more.
It Follows Clean Architecture
For more details, visit the Clean Architecture in Golang.
- Perform CRUD operations for courses.
- Store details such as:
- Course title
- Description
- Price
- Instructor name
- Category (e.g., programming, design, business).
- Register and manage users (students and instructors).
- Support roles such as
studentorinstructor. - Include additional user attributes like bio (optional for instructors).
- Enroll users in courses.
- Retrieve:
- Courses a user is enrolled in.
- Students enrolled in a specific course.
- Associate multiple lessons with courses.
- Track user progress at the lesson level.
- Add and retrieve course reviews.
- Include ratings (1-5 stars) and comments.
course-management/
βββ entities/ # Core business entities
β βββ course.go
βββ usecases/ # Business logic (use cases)
β βββ course_usecase.go
βββ interfaces/ # Controllers (HTTP handlers)
β βββ course_handler.go
βββ infrastructure/ # External systems (DB and routing)
β βββ database/
β β βββ course_repository.go
β βββ router.go
βββ config/ # Configuration files (DB setup)
β βββ database.go
βββ main.go # Application entry point
Hereβs a polished version of your README file, designed to be more professional and structured for clarity:
| Method | Endpoint | Description |
|---|---|---|
| POST | /course |
Add a new course. |
| GET | /courses |
Retrieve all courses. |
| GET | /course/{id} |
Retrieve details of a course. |
| PUT | /course |
Update course details. |
| DELETE | /course/{id} |
Delete a course. |
| Method | Endpoint | Description |
|---|---|---|
| POST | /user |
Register a new user. |
| GET | /users |
List all users. |
| GET | /user/{id} |
Retrieve details of a user. |
| PUT | /user |
Update user details. |
| DELETE | /user/{id} |
Delete a user. |
| Method | Endpoint | Description |
|---|---|---|
| POST | /enroll |
Enroll a user in a course. |
| GET | /enrolls |
Retrieve all enrollments. |
| GET | /enroll/:id |
Retrieve enrollment by ID. |
| GET | /enrolls/user/{id} |
Get all enrollments for a user. |
| PUT | /enroll |
Update enrollment details. |
| DELETE | /enroll/:id |
Delete an enrollment. |
| Method | Endpoint | Description |
|---|---|---|
| POST | /lesson |
Add a new lesson to a course. |
| GET | /lessons/course/{id} |
Get all lessons for a course. |
| GET | /lesson/{id} |
Retrieve details of a lesson. |
| PUT | /lesson |
Update lesson details. |
| DELETE | /lesson/{id} |
Delete a lesson. |
| Method | Endpoint | Description |
|---|---|---|
| POST | /progress |
Add progress for a lesson. |
| PUT | /progress |
Update progress details. |
| GET | /progress/{enrollmentID}/{lessonID} |
Get progress for a specific lesson. |
| Method | Endpoint | Description |
|---|---|---|
| POST | /review |
Add a review to a course. |
| GET | /reviews/course/{id} |
Retrieve reviews for a course. |
| DELETE | /review/{id} |
Delete a review. |
package entities
//this is entites or models or domain
type User struct {
ID uint `json:"id" gorm:"primary_key"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Password string `json:"password"` // hashed password
Role string `json:"role"` // student or instructor
Bio string `json:"bio"` // instructor bio optional
}
type Course struct {
ID uint `json:"id" gorm:"primary_key"`
Title string `json:"title"`
Description string `json:"description"`
Duration string `json:"duration"`
Price float64 `json:"price"`
Instructor string `json:"instructor"`
Category string `json:"category"` // programming, design, business, etc
}
//enrollment is the join table between users and courses
type Enrollment struct {
ID uint `json:"id" gorm:"primary_key"`
UserID uint `json:"user_id"`
CourseID uint `json:"course_id"`
Completed bool `json:"completed"`
}
//courses may have multiple lessons
type Lesson struct {
ID uint `json:"id" gorm:"primary_key"`
CourseID uint `json:"course_id"`
Title string `json:"title"`
Content string `json:"content"`
VideoURL string `json:"video_url"`
Order uint `json:"order"`
}
//progress is the join table between enrollments and lessons
type Progress struct {
ID uint `json:"id" gorm:"primaryKey"`
EnrollmentID uint `json:"enrollment_id"`
LessonID uint `json:"lesson_id"`
Completed bool `json:"completed"`
}
//reviews are associated with courses
type Review struct {
ID uint `json:"id" gorm:"primaryKey"`
CourseID uint `json:"course_id"`
UserID uint `json:"user_id"`
Rating int `json:"rating"` // e.g., 1-5 stars
Comment string `json:"comment"`
}
Hereβs the revised project setup with the correct module path:
Create a directory for your project and initialize the Go module:
mkdir mini_rest_api_clean_architecture
cd mini_rest_api_clean_architecture
go mod init github.com/username/mini_rest_api_clean_architectureInstall the required libraries:
# Web framework
go get -u github.com/gin-gonic/gin
# SQLite3 driver
go get github.com/mattn/go-sqlite3
- Ensure the database file is properly initialized.
- Start your Go server:
go run main.go
- Access the API endpoints using tools like Postman or Curl. The base URL is
http://localhost:8080.

