This repository contains a GraphQL API built using the graphql-go library and adheres to the principles of Clean Architecture. The backend is powered by SQLite3, ensuring lightweight and efficient data storage. 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
├── schema/ # Schema and resolver for GraphQL
│ └── schema.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:
Here are some GraphQL queries and mutations for testing the schema provided:
mutation CreateUser {
createUser(
first_name: "John"
last_name: "Doe"
email: "john.doe@example.com"
password: "securepassword"
role: "student"
bio: "Learning GraphQL!"
) {
id
first_name
last_name
email
}
}mutation CreateCourse {
createCourse(
title: "GraphQL 101"
description: "Learn the basics of GraphQL."
duration: "4 weeks"
price: 199.99
instructor: "Jane Smith"
category: "Programming"
) {
id
title
}
}mutation AddEnrollment {
addEnrollment(
user_id: 1
course_id: 1
completed: false
) {
id
user_id
course_id
}
}mutation AddLesson {
addLesson(
course_id: 1
title: "Introduction to GraphQL"
content: "Learn what GraphQL is and how it works."
video_url: "http://example.com/video.mp4"
order: 1
) {
id
title
course_id
}
}mutation AddProgress {
addProgress(
enrollment_id: 1
lesson_id: 1
completed: true
) {
id
completed
}
}mutation AddReview {
addReview(
course_id: 1
user_id: 1
rating: 5
comment: "Excellent course!"
) {
id
rating
comment
}
}query GetUser {
user(id: 1) {
id
first_name
last_name
email
role
bio
}
}query GetUsers {
users {
id
first_name
last_name
email
role
bio
}
}query GetCourse {
course(id: 1) {
id
title
description
duration
price
instructor
category
}
}query GetCourses {
courses {
id
title
description
duration
price
instructor
category
}
}query GetEnrollmentsByUserID {
enrollmentsByUserID(user_id: 1) {
id
course_id
completed
}
}query GetLessonsByCourseID {
lessonsbyCourseID(course_id: 1) {
id
title
content
video_url
order
}
}query GetProgressByEnrollmentAndLesson {
progressbyEnrollmentAndLesson(enrollment_id: 1, lesson_id: 1) {
id
completed
}
}query GetReviewsByCourseID {
reviewsByCourseID(course_id: 1) {
id
user_id
rating
comment
}
}- Use a GraphQL client such as Postman or GraphiQL.
- Replace the variable values in the queries/mutations as per your setup.
- Verify the responses align with the expected schema and functionality.
Let me know if you need anything else! 🚀
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"`
}
Create a directory for your project and initialize the Go module:
mkdir GraphQL_elearning_platform_api
cd GraphQL_elearning_platform_api
go mod init github.com/username/GraphQL_elearning_platform_apiInstall the required libraries:
# Web framework
go get -u github.com/gin-gonic/gin
# SQLite3 driver
go get github.com/mattn/go-sqlite3
# GraphQl Code based schema
go get github.com/graphql-go/graphql
- 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.

