Knowlytics MVP is a minimal implementation of an Education Technology (EdTech) platform designed to demonstrate core functionality for online learning. Users can register as either students or instructors, log in, and browse courses. Students can purchase existing courses using Stripe, while instructors cannot create courses at this time. Invoices are generated using PDFKit after each successful purchase, providing a seamless experience for tracking transactions.
This MVP focuses on essential features to validate the concept, with plans for future enhancements like email notifications, file uploads, and additional analytics.
- Features
- Technologies Used
- Database Schema (ERD)
- Project Structure
- Prerequisites
- Installation
- Usage
- Sequelize CLI Commands
- Contributing
- License
- Contact
- Key Updates
-
User Authentication:
- Secure registration and login system using session management (
express-session) and password hashing withbcrypt. - Role-based access for Students and Instructors.
- Token-based integration with Stripe using
jsonwebtokenfor customer management.
- Secure registration and login system using session management (
-
Role-Based Access:
- Student: Browse courses, purchase courses via Stripe, and view purchased courses.
- Instructor: Currently, instructors cannot create or manage courses (feature planned for future updates).
-
Course Management:
- Browse courses and view course details.
- Purchase courses using Stripe (for Students).
-
Payment Integration:
- Integrated with Stripe (
stripe) for secure online payments. - Supports payment processing for course purchases.
- Integrated with Stripe (
-
Invoice Generation:
- Generates PDF invoices using PDFKit (
pdfkit) after successful purchases. - Invoices are stored locally for record-keeping.
- Generates PDF invoices using PDFKit (
- Express.js: Web framework for Node.js to handle routing and server logic.
- Sequelize: ORM for PostgreSQL to manage database models, migrations, and seeders.
- PostgreSQL: Database for storing user, course, and purchase data.
- bcrypt: For secure password hashing.
- express-session: For session management.
- jsonwebtoken (JWT): For token-based authentication with Stripe.
- pdfkit: For generating PDF invoices after purchases.
- stripe: For payment processing and customer management.
- dotenv: For managing environment variables (e.g., Stripe credentials).
- HTML/EJS: Templating engine for rendering dynamic views.
- Tailwind CSS: Utility-first CSS framework for responsive and modern styling.
- JavaScript: For both backend (Node.js) and frontend logic.
The project uses the following tables with their relationships:
- Users: Stores user data (
id,username,email,password,rolewhereroleis eitherstudentorinstructor). - Courses: Stores course data (
id,name,description,price,userId). - UserCourses: Junction table for Many-to-Many relationship between
Users(Students) andCourses(purchases), withstripePaymentIdto track payments. - Categories: Stores category data (
id,name). - CourseCategories: Junction table for Many-to-Many relationship between
CoursesandCategories. - Lessons: Stores lesson data (
id,title,content,courseId). - UserProfiles: Stores user profile data (
id,fullName,phone,userId).
- One-to-Many:
Users→Courses(viauserIdinCourseswhereuserIdlinks to an Instructor). - Many-to-Many:
Users↔Courses(viaUserCoursesfor student purchases). - Many-to-Many:
Courses↔Categories(viaCourseCategories). - One-to-Many:
Courses→Lessons(viacourseIdinLessons). - One-to-One:
Users→UserProfiles(viauserIdinUserProfiles).
Below is the ERD for the Knowlytics database:
Based on the latest project directory, here’s the updated structure:
knowlytics/
├── config/
│ └── config.json # Database configuration for Sequelize
├── controllers/
│ └── controller.js # All controller logic
├── data/
│ ├── categories.json # Seed data for Categories
│ ├── courseCategories.json # Seed data for CourseCategories
│ ├── courses.json # Seed data for Courses
│ ├── lesson.json # Seed data for Lessons
│ ├── userCourses.json # Seed data for UserCourses
│ ├── userProfiles.json # Seed data for UserProfiles
│ └── users.json # Seed data for Users
├── helpers/
├── migrations/ # Sequelize migrations
├── models/
│ ├── category.js # Category model
│ ├── course.js # Course model
│ ├── coursecategory.js # CourseCategory model
│ ├── index.js # Sequelize model index
│ ├── lesson.js # Lesson model
│ ├── user.js # User model
│ ├── usercourse.js # UserCourse model
│ └── userprofile.js # UserProfile model
├── node_modules/ # Node.js dependencies
├── public/
│ └── payment.js # Client-side payment logic
├── routes/
├── seeders/ # Sequelize seeders
├── sessions/ # Session storage
├── views/
│ ├── courseDetail.ejs # Course detail page
│ ├── editProfile.ejs # Edit profile page
│ ├── invoiceView.ejs # Invoice view page
│ ├── landing.ejs # Landing page
│ ├── login.ejs # Login page
│ ├── payment.ejs # Payment page
│ ├── register.ejs # Register page
│ └── env # Environment-specific views (if any)
├── .gitignore # Git ignore file
├── app.js # Main application file
├── knowlyticsdb.scheme.drawio.png # Database schema diagram
├── LICENSE # License file
├── package-lock.json # Dependency lock file
├── package.json # Project dependencies and scripts
└── README.md # Project documentation
Before setting up Knowlytics MVP, ensure you have the following installed:
- Node.js (v14 or higher): Download Node.js
- PostgreSQL (v12 or higher): Download PostgreSQL
- npm (v6 or higher): Included with Node.js installation
- Git: Download Git (for cloning the repository)
- Stripe Account: Register at Stripe to obtain your
STRIPE_SECRET_KEY.
Follow these steps to set up and run Knowlytics MVP on your local machine:
-
Clone the Repository:
git clone https://github.com/your-username/knowlytics.git cd knowlytics -
Install Dependencies:
npm install
This will install all required packages, including:
expresssequelizepg(PostgreSQL driver)express-sessionbcryptjsjsonwebtokenejspdfkitstripedotenv
-
Setup PostgreSQL Database:
- Create a PostgreSQL database named
Knowlytics_DB:psql -U postgres -c "CREATE DATABASE Knowlytics_DB;" - Update the
config/config.jsonfile with your database credentials:{ "development": { "username": "postgres", "password": "postgres", "database": "Knowlytics_DB", "host": "localhost", "dialect": "postgres", "idle": 500 }, "test": { "username": "postgres", "password": "postgres", "database": "Knowlytics_test", "host": "localhost", "dialect": "postgres", "idle": 500 }, "production": { "username": "postgres", "password": "postgres", "database": "knowlytics_prod", "host": "localhost", "dialect": "postgres", "idle": 500 } }
- Create a PostgreSQL database named
-
Setup Environment Variables:
- Create a
.envfile in the root directory and add your credentials:STRIPE_SECRET_KEY=your-stripe-secret-key
- Replace
your-stripe-secret-keywith your Stripe secret key (obtainable from the Stripe Dashboard). - Ensure
.envis added to.gitignore:node_modules/ .env invoices/ sessions/
- Create a
-
Setup Stripe:
- Register for a Stripe account at Stripe to get your
STRIPE_SECRET_KEY. Use test mode for development.
- Register for a Stripe account at Stripe to get your
-
Run Migrations:
npx sequelize-cli db:migrate
This will create the tables:
UsersCoursesCategoriesUserCoursesCourseCategoriesLessonsUserProfiles
-
Run Seeders:
npx sequelize-cli db:seed:all
This will populate the database with sample data for:
- Users (with roles:
student,instructor) - Courses
- Categories
- Lessons
- UserCourses
- CourseCategories
- UserProfiles
- Users (with roles:
-
(Optional) Setup Tailwind CSS Locally:
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init
Update
tailwind.config.js:module.exports = { content: ["./views/**/*.ejs"], theme: { extend: {} }, plugins: [], };
Create
public/css/input.css:@tailwind base; @tailwind components; @tailwind utilities;
Add script to
package.json:"scripts": { "build:css": "tailwindcss -i ./public/css/input.css -o ./public/css/output.css --watch" }
Run:
npm run build:css
-
Run the Application:
node app.js
The application will be running at
http://localhost:3000.
-
Register and Login:
- Visit
http://localhost:3000/registerto create an account (choose role:studentorinstructor). - Login at
http://localhost:3000/login.
- Visit
-
Browse and Purchase Courses:
- Go to
http://localhost:3000/coursesto browse available courses. - Click "View Details" to see course information.
- Students can purchase a course via Stripe by clicking "Daftar Sekarang" on the course detail page.
- After a successful purchase, an invoice will be generated and saved in the
invoices/folder.
- Go to
-
View Purchased Courses:
- Students can see their purchased courses at
http://localhost:3000/my-courses.
- Students can see their purchased courses at
The following Sequelize CLI commands were used to create models, migrations, and seeders:
# Initialize Sequelize
npx sequelize-cli init
# Create Models and Migrations
npx sequelize-cli model:generate --name User --attributes "username:string,email:string,password:string,role:string"
npx sequelize-cli model:generate --name Course --attributes "name:string,description:string,price:integer,userId:integer"
npx sequelize-cli model:generate --name Category --attributes "name:string"
npx sequelize-cli model:generate --name Lesson --attributes "title:string,content:string,courseId:integer"
npx sequelize-cli model:generate --name UserProfile --attributes "fullName:string,phone:string,userId:integer"
# Create Junction Tables
npx sequelize-cli migration:generate --name create-user-courses
npx sequelize-cli migration:generate --name create-course-category
# Add Foreign Key Constraints
npx sequelize-cli migration:generate --name add-fk-constraint-to-userCourses-userId
npx sequelize-cli migration:generate --name add-fk-constraint-to-userCourses-courseId
npx sequelize-cli migration:generate --name add-fk-constraint-to-courseCategories-courseId
npx sequelize-cli migration:generate --name add-fk-constraint-to-courseCategories-categoryId
npx sequelize-cli migration:generate --name add-fk-constraint-to-userProfiles-userId
npx sequelize-cli migration:generate --name add-fk-constraint-to-lessons-courseId
# Run Migrations
npx sequelize-cli db:migrate
# Run Seeders
npx sequelize-cli db:seed:allWe welcome contributions to improve Knowlytics MVP! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and commit (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Create a Pull Request.
This project is licensed under the MIT License.
For any inquiries, please contact:
- Fadhal (fadhal.kerja@gmail.com)
-
Database Schema (ERD):
- Added
Categories,CourseCategories,Lessons, andUserProfilestables based on the migration and seeder files. - Updated relationships to include the new tables, such as the Many-to-Many relationship between
CoursesandCategoriesviaCourseCategories, One-to-Many betweenCoursesandLessons, and One-to-One betweenUsersandUserProfiles.
- Added
-
Project Structure:
- Added
categories.json,lessons.json,courseCategories.json, anduserProfiles.jsonto thedata/folder to reflect the seeders. - Added corresponding model files (
category.js,lesson.js,userProfile.js,userCourse.js,courseCategory.js) to themodels/folder. - Updated the structure to reflect the latest directory, including the
public/folder withpayment.jsand thesessions/folder for session storage.
- Added
-
Sequelize CLI Commands:
- Updated to include commands for generating the
Category,Lesson, andUserProfilemodels, as well as theCourseCategoriesjunction table. - Added commands for creating foreign key constraints as seen in the migration files.
- Updated to include commands for generating the
-
Installation:
- Updated the migration and seeder steps to include the new tables (
Categories,CourseCategories,Lessons,UserProfiles). - Removed references to EasyInvoice and added
pdfkitto the list of dependencies.
- Updated the migration and seeder steps to include the new tables (
-
Invoice Generation:
- Switched from EasyInvoice to PDFKit (
pdfkit) for generating PDF invoices. This change simplifies the invoice generation process by removing the dependency on an external API and allows for more customizable PDF creation usingPDFDocumentfrompdfkit.
- Switched from EasyInvoice to PDFKit (
-
Responsive Design for Invoice View:
- Modified the
invoiceView.ejspage to improve responsiveness:- On larger screens (≥640px), the "Unduh Invoice" button is placed to the right of the "Lihat Invoice Pembayaran" title.
- On mobile screens (<640px), the "Unduh Invoice" button is placed below the paragraph "Ini adalah bukti pembayaranmu (ID: ...)" for better usability.
- Modified the
Features Section:
- Updated the "Role-Based Access" subsection to clarify that instructors cannot create or manage courses at this time.
- Removed the "Instructors can add courses through a simple interface" point from the "Course Management" subsection, as this functionality is not currently available.