Artur-Poffo / Code-Spark-API

Entra21 course TCC, Back-End

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CodeSpark - Entra21 TCC 💻

CodeSpark API

Status: ⚠️ Under Development - MVP Completed ⚠️

AboutPotential Refactoring or UpdatesSeparation of Initial RequirementsAPI RoutesHow It WorksTech StackAuthor

About

CodeSpark API - The CodeSpark API adheres to industry best practices such as Domain-Driven Design (DDD) and clean architecture. It serves as the backbone for a course platform, featuring a file upload system integrated with Cloudflare R2 (powered by AWS S3) and a comprehensive class evaluation system.

This project serves as the TCC (Trabalho de Conclusão de Curso - Course Conclusion Work) for the Entra21 training program Vue.js course.


Potential Refactoring or Updates

The API's scope has expanded beyond our initial expectations, necessitating some features to be deferred even from the MVP. Nevertheless, we're committed to further development post-presentation.

  • Implement a method for the course repository.
  • Refactor dependencies in all unit tests.
  • Optimize the usage of Promise.all() and apply destructuring where applicable.
  • Review use cases and explore potential improvements.
  • Ensure consistent usage of new UniqueEntityId() for entity IDs and rectify any inconsistencies.
  • Evaluate the Enrollment entity for possible simplifications in managing modules and classes.
  • Replace all asynchronous forEach loops with Promise.all() combined with asynchronous map.
  • Update error handling in use cases.
  • Implement sorting in findMany methods of Prisma repositories.
  • Refactor database relation names.
  • Revise mark as complete functionality for classes and modules system.
  • Fix infinite calls to Prisma repositories in some mapper usage scenarios.
  • Introduce domain events for Prisma repositories.
  • Implement mappers for mapping domain entities to DTOs.
  • Implement pagination.
  • Implement End-to-End (E2E) tests.
  • Refactor error handling in controllers.
  • Refactor the event handler class instance.

Separation of Initial Requirements

Functional Requirements

  • User must be able to register in the system as either "Student" or "Instructor."

  • User must be able to authenticate after registration.

  • Return information about a user.

  • Instructors must be able to register courses on the platform.

  • Instructors can register modules for a course.

  • Instructors can add classes to modules.

  • Should be able to register tags.

  • Responsible instructors can add "tags" to their courses to inform students about technologies present in the course.

  • Instructors can create classes and upload videos to them.

  • Instructors can upload a certificate template for students upon course completion.

  • Return information of an instructor with their courses.

  • Return information about a course.

  • Return information about a course with its modules.

  • Classes and modules must have a field informing their position, e.g., this class is number one, so this is the first class of the course.

  • Students can "enroll" to participate in a course.

  • Return information about a course with its students.

  • Students can mark classes as completed.

  • Mark modules as completed after the student views all its classes.

  • After completing all modules of a course, that course for a student should be marked as completed.

  • Return information about a student with the courses they are enrolled in.

  • After completing a course, the student can issue a certificate.

  • It should be possible to filter courses by name or "tags."

  • Students can evaluate a particular class they are taking with a rating from 1 to 5 to later have an average rating for the course.

  • Get course evaluations average.

  • An instructor should be able to retrieve traffic data for one of their courses.

  • CRUDs for all main entities: course, module, class, user, etc.

  • Return information about a course with student progress in your modules and classes.

  • Video streaming to watch the classes.

Business Rules

  • User should not be able to register with the same email.
  • User should not be able to register with the same CPF.
  • Only students can enroll for a course.
  • Only students can rate classes.
  • Only instructors can register a course.
  • A specific instructor cannot register a course with the same name.
  • A student should only be able to rate a class once.
  • Should not be able to register a course with the same name in the same instructor account.
  • Should not be able to register a module to a course with the same name twice.
  • Should not be able to add a class to a module with the same name twice.
  • Should not be able to register a module to a specific course with the same name twice.
  • A student can only issue one certificate per course.
  • A student can only enroll for a particular course once.
  • There should not be repeated tags in a course.

Non-Functional Requirements

  • File upload/storage on Cloudflare R2.
  • User's password must be encrypted.
  • Application data must be persisted in a PostgreSQL database with Docker.
  • User must be identified by JWT.
  • JWT must use the RS256 algorithm.

API Routes

The following documentation provides an initial overview of API routes. Further refinement will be undertaken post-presentation.

Users

  • GET /users/:userId - Get user details
  • POST /users - Register user
  • PUT /users/:userId - Update user
  • DELETE /users/:userId - Delete user

Sessions

  • POST /sessions - User authentication

Students

  • GET /courses/:courseId/students - Get students enrolled in a course
  • GET /students/:studentId/enrollments - Get student courses with instructor and evaluations

Instructors

  • GET /courses/:courseId/instructors - Get course instructor details
  • GET /instructors/:instructorId/courses - Get instructor courses with instructor and evaluations

Courses

  • GET /courses/:courseId - Get course details
  • GET /courses/:courseId/stats - Get course statistics, like duration and number of classes
  • GET /courses/:courseId/metrics - Get course metrics for a dashboard
  • GET /courses - Get recent courses with instructor and evaluation average
  • GET /courses/filter/name?q="" - Filter courses by name
  • GET /courses/filter/tags?q="" - Filter courses by tags
  • POST /courses - Register course
  • PUT /courses/:courseId - Update course details
  • DELETE /courses/:courseId - Delete course

Certificate

  • POST /courses/:courseId/certificates - Add certificate to course
  • DELETE /courses/:courseId/certificates - Remove certificate from course

StudentCertificate

  • POST /enrollments/:enrollmentId/certificates/issue - Issue student certificate

Modules

  • GET /courses/:courseId/modules - Get course modules
  • POST /modules - Register module
  • GET /modules/:moduleId/classes - Get classes from a module
  • PUT /modules/:moduleId - Update module details
  • DELETE /modules/:moduleId - Delete module

Classes

  • GET /courses/:courseId/classes - Get course classes
  • POST /modules/:moduleId/classes/video/:videoId - Register class
  • PUT /classes/:classId - Update class details
  • DELETE /classes/:classId - Delete class

Tags

  • GET /tags - Get recent tags
  • POST /tags - Register tag

CourseTags

  • GET /courses/:courseId/tags - Get course tags
  • POST /courses/:courseId/tags/:tagId - Attach tag to course
  • POST /courses/:courseId/tags/:tagId - Remove tag from course

Evaluations

  • GET /courses/:courseId/evaluations/average - Get course evaluation average
  • POST /evaluations - Register evaluation
  • PUT /evaluations/:evaluationId - Update evaluation

Enrollments

  • POST /courses/:courseId/enroll - Enroll in a course
  • POST /enrollments/:enrollmentId/modules/:moduleId/complete - Mark module as completed
  • POST /enrollments/:enrollmentId/classes/:classId/complete - Mark class as completed
  • POST /enrollments/:enrollmentId/complete - Mark enrollment as completed
  • GET /enrollments/:enrollmentId/progress - Get student enrollment progress
  • GET /courses/:courseId/students/:studentId/enrollments - Get enrollment of a student on a course
  • GET /enrollments/:enrollmentId/classes/completed - Fetch enrollment completed classes
  • GET /enrollments/:enrollmentId/modules/completed - Fetch enrollment completed modules
  • DELETE /enrollments/:enrollmentId - Cancel enrollment

File

  • POST /files - Upload file (image or video), multipart/form-data

Video

  • GET /videos/:fileKey - Get video details by fileKey

Image

  • GET /images/:fileKey - Get image details by fileKey

How It Works

Pre-requisites

Before you begin, ensure you have the following tools installed on your machine: Git, Node.js, Yarn, an editor like VSCode, and a REST client such as Insomnia.

Additionally, Docker is required to run the PostgreSQL database using Docker Compose.

Before running the project, make sure to configure the environment variables as indicated in the .env.example file.

Running the App

# Clone this repository
$ git clone https://github.com/Artur-Poffo/Code-Spark-API.git

# Navigate to the project directory in your terminal
$ cd Code-Spark-API

# Install dependencies
$ yarn

# Initialize the database
$ yarn docker:init
# This script should create and start a Docker container with the PostgreSQL database

# To stop Docker, run:
$ yarn docker:stop
# Or press Ctrl+C

# To start the container again, run:
$ yarn docker:start

# Generate RSA keys for JWT authentication, as instructed in the .env.example file

# Run the application in development mode
$ yarn start:dev

# The server will start at port 3333. You can now test it using Insomnia or any other REST client: http://localhost:3333

Run tests

# Run unit tests
$ yarn test:unit

# Run unit tests in watch mode
$ yarn test:unit:watch

# Run test coverage
$ yarn test:cov

Tech Stack

The following tools were used in the construction of the project:

  • Node.js
  • TypeScript
  • tsx
  • tsup
  • Fastify
  • @Fastify/jwt
  • @Fastify/cookie
  • bcrypt
  • zod
  • prisma
  • vitest
  • @aws-sdk/client-s3
  • Docker

See the file package.json


Author

  • Artur Poffo - Developer

Linkedin Badge Gmail Badge


About

Entra21 course TCC, Back-End


Languages

Language:TypeScript 100.0%