|
Some checks failed
Build and Deploy Frontend Learner / Build Frontend Learner Docker Image (push) Failing after 9s
Build and Deploy Frontend Learner / Deploy Frontend Learner to Server (push) Has been skipped
Build and Deploy Frontend Management / Build Frontend Management Docker Image (push) Failing after 9s
Build and Deploy Backend / Build Backend Docker Image (push) Failing after 9s
Build and Deploy Frontend Management / Deploy Frontend Management to Server (push) Has been skipped
Build and Deploy Backend / Deploy Backend to Server (push) Has been skipped
|
||
|---|---|---|
| .. | ||
| .agent | ||
| .agents/skills/nodejs-backend-patterns | ||
| .claude/skills | ||
| .codex/skills | ||
| .cursor/skills | ||
| .gemini/skills | ||
| .windsurf | ||
| assets | ||
| prisma | ||
| scripts | ||
| src | ||
| tests/k6 | ||
| .env.example | ||
| .gitignore | ||
| .npmrc | ||
| agent_skills_backend.md | ||
| compose.yaml | ||
| Dockerfile | ||
| nodemon.json | ||
| package-lock.json | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
| tsoa.json | ||
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
- Create a new controller in
src/controllers/ - Add TSOA decorators (
@Route,@Get,@Post, etc.) - Run
npm run tsoa:gento generate routes - Implement business logic in
src/services/ - 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