Skip to content

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.

Notifications You must be signed in to change notification settings

Naheed-Rayhan/GraphQL_elearning_platform_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL API with Clean Architecture

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.

clear architecture

Key Features

1. Course Management

  • Perform CRUD operations for courses.
  • Store details such as:
    • Course title
    • Description
    • Price
    • Instructor name
    • Category (e.g., programming, design, business).

2. User Management

  • Register and manage users (students and instructors).
  • Support roles such as student or instructor.
  • Include additional user attributes like bio (optional for instructors).

3. Enrollment Management

  • Enroll users in courses.
  • Retrieve:
    • Courses a user is enrolled in.
    • Students enrolled in a specific course.

4. Lessons and Progress Tracking

  • Associate multiple lessons with courses.
  • Track user progress at the lesson level.

5. Course Reviews

  • Add and retrieve course reviews.
  • Include ratings (1-5 stars) and comments.

File structure

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:


API Endpoints

Here are some GraphQL queries and mutations for testing the schema provided:


Mutations

1. Create a new user

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
  }
}

2. Create a new course

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
  }
}

3. Add a new enrollment

mutation AddEnrollment {
  addEnrollment(
    user_id: 1
    course_id: 1
    completed: false
  ) {
    id
    user_id
    course_id
  }
}

4. Add a new lesson

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
  }
}

5. Add progress for a lesson

mutation AddProgress {
  addProgress(
    enrollment_id: 1
    lesson_id: 1
    completed: true
  ) {
    id
    completed
  }
}

6. Add a review for a course

mutation AddReview {
  addReview(
    course_id: 1
    user_id: 1
    rating: 5
    comment: "Excellent course!"
  ) {
    id
    rating
    comment
  }
}

Queries

1. Fetch a single user by ID

query GetUser {
  user(id: 1) {
    id
    first_name
    last_name
    email
    role
    bio
  }
}

2. Fetch all users

query GetUsers {
  users {
    id
    first_name
    last_name
    email
    role
    bio
  }
}

3. Fetch a single course by ID

query GetCourse {
  course(id: 1) {
    id
    title
    description
    duration
    price
    instructor
    category
  }
}

4. Fetch all courses

query GetCourses {
  courses {
    id
    title
    description
    duration
    price
    instructor
    category
  }
}

5. Fetch enrollments by user ID

query GetEnrollmentsByUserID {
  enrollmentsByUserID(user_id: 1) {
    id
    course_id
    completed
  }
}

6. Fetch lessons by course ID

query GetLessonsByCourseID {
  lessonsbyCourseID(course_id: 1) {
    id
    title
    content
    video_url
    order
  }
}

7. Fetch progress by enrollment and lesson IDs

query GetProgressByEnrollmentAndLesson {
  progressbyEnrollmentAndLesson(enrollment_id: 1, lesson_id: 1) {
    id
    completed
  }
}

8. Fetch reviews by course ID

query GetReviewsByCourseID {
  reviewsByCourseID(course_id: 1) {
    id
    user_id
    rating
    comment
  }
}

How to Test

  1. Use a GraphQL client such as Postman or GraphiQL.
  2. Replace the variable values in the queries/mutations as per your setup.
  3. Verify the responses align with the expected schema and functionality.

Let me know if you need anything else! 🚀

Data Models

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"`
}

Project Setup

1. Initialize the Project

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_api

2. Install Dependencies

Install 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

3. Run the Application

  1. Ensure the database file is properly initialized.
  2. Start your Go server:
    go run main.go
  3. Access the API endpoints using tools like Postman or Curl. The base URL is http://localhost:8080.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages