elearning/Backend
2026-01-26 17:23:26 +07:00
..
.agent add skill to project 2026-01-23 10:53:48 +07:00
.agents/skills/nodejs-backend-patterns add skill to project 2026-01-23 10:53:48 +07:00
.claude/skills add skill to project 2026-01-23 10:53:48 +07:00
.codex/skills add skill to project 2026-01-23 10:53:48 +07:00
.cursor/skills add skill to project 2026-01-23 10:53:48 +07:00
.gemini/skills add skill to project 2026-01-23 10:53:48 +07:00
.windsurf/skills add skill to project 2026-01-23 10:53:48 +07:00
prisma feat: Implement instructor-specific course management and refactor course creation into dedicated modules. 2026-01-16 11:12:12 +07:00
scripts update api chapterlesson 2026-01-22 15:56:56 +07:00
src feat: Implement granular API for video upload/update and attachment management with dedicated types and endpoints. 2026-01-26 17:23:26 +07:00
.env.example remove redis 2026-01-12 03:36:54 +00:00
.gitignore migration to typescript 2026-01-09 06:28:15 +00:00
.npmrc auth api 2026-01-13 06:49:37 +00:00
agent_skills_backend.md remove redis 2026-01-12 03:36:54 +00:00
compose.yaml remove redis 2026-01-12 03:36:54 +00:00
nodemon.json api login 2026-01-09 10:14:20 +00:00
package-lock.json Add:api-login 2026-01-14 15:15:31 +07:00
package.json update api chapterlesson 2026-01-22 15:56:56 +07:00
pnpm-lock.yaml auth api 2026-01-13 06:49:37 +00:00
README.md remove redis 2026-01-12 03:36:54 +00:00
tsconfig.json auth api 2026-01-13 06:49:37 +00:00
tsoa.json update api chapterlesson 2026-01-22 15:56:56 +07:00

E-Learning Platform Backend

Backend API for E-Learning Platform built with TypeScript, Express, TSOA, and Prisma.

🚀 Features

  • TypeScript - Type-safe development
  • TSOA - Automatic OpenAPI/Swagger documentation
  • Prisma - Type-safe database ORM
  • JWT Authentication - Secure user authentication
  • Role-based Authorization - Admin, Instructor, Student roles
  • Multi-language Support - Thai and English
  • File Upload - Video and attachment support with MinIO/S3
  • Rate Limiting - API protection
  • Comprehensive Error Handling - Structured error responses

📋 Prerequisites

  • Node.js >= 18
  • Docker & Docker Compose
  • PostgreSQL (via Docker)
  • MinIO (via Docker)

🛠️ Setup

1. Install Dependencies

npm install

2. Environment Configuration

cp .env.example .env
# Edit .env with your configuration

3. Start Docker Services

docker compose up -d

4. Database Setup

# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate dev

# Seed database
npx prisma db seed

5. Generate TSOA Routes & Swagger

npm run tsoa:gen

6. Start Development Server

npm run dev

The server will start at http://localhost:4000

📚 API Documentation

Swagger documentation is available at: http://localhost:4000/api-docs

🏗️ Project Structure

Backend/
├── prisma/
│   ├── migrations/      # Database migrations
│   ├── schema.prisma    # Database schema
│   └── seed.js         # Database seeder
├── src/
│   ├── config/         # Configuration files
│   │   ├── index.ts    # Main config
│   │   ├── logger.ts   # Winston logger
│   │   └── database.ts # Prisma client
│   ├── controllers/    # TSOA controllers
│   │   └── HealthController.ts
│   ├── middleware/     # Express middleware
│   │   ├── authentication.ts
│   │   └── errorHandler.ts
│   ├── services/       # Business logic
│   ├── types/          # TypeScript types
│   │   └── index.ts
│   ├── utils/          # Utility functions
│   ├── validators/     # Input validation
│   ├── app.ts         # Express app setup
│   └── server.ts      # Server entry point
├── public/            # Generated Swagger docs
├── .env.example       # Environment template
├── tsconfig.json      # TypeScript config
├── tsoa.json         # TSOA config
├── nodemon.json      # Nodemon config
└── package.json

🔧 Available Scripts

npm run dev              # Start dev server with hot reload
npm run build            # Build TypeScript + generate TSOA routes
npm start                # Start production server
npm run tsoa:gen         # Generate TSOA routes & Swagger
npm test                 # Run tests
npm run lint            # Run ESLint
npm run format          # Format code with Prettier

🗄️ Database Commands

npx prisma studio       # Open Prisma Studio (GUI)
npx prisma migrate dev  # Create and apply migration
npx prisma db seed      # Seed database
npx prisma generate     # Generate Prisma client

🐳 Docker Commands

docker compose up -d    # Start all services
docker compose down     # Stop all services
docker compose logs -f  # View logs
docker compose ps       # List running services

🔐 Default Credentials

After seeding, you can login with:

  • Admin: admin / admin123
  • Instructor: instructor / instructor123
  • Student: student / student123

📝 Development Workflow

  1. Create a new controller in src/controllers/
  2. Add TSOA decorators (@Route, @Get, @Post, etc.)
  3. Run npm run tsoa:gen to generate routes
  4. Implement business logic in src/services/
  5. Test your endpoints

🧪 Testing

npm test                # Run all tests
npm run test:watch      # Run tests in watch mode
npm run test:coverage   # Generate coverage report

🚀 Deployment

See Deployment Workflow for production deployment instructions.

📖 Documentation

🔍 Troubleshooting

Port already in use

lsof -i :4000
kill -9 <PID>

Database connection error

docker compose logs postgres
npx prisma db pull

Prisma client error

npx prisma generate

📄 License

ISC

👥 Team

E-Learning Development Team