- Introduction
- System Architecture
- Technical Stack
- Database Design
- Core Components
- Security Implementation
- API Documentation
- Testing Strategy
- Deployment Guide
The Training Management System (TMS) is a comprehensive platform designed to manage and deliver training programs. It provides functionality for course management, user administration, skill tracking, and progress monitoring.
The system encompasses:
- User Management with role-based access
- Course Creation and Management
- Skill and Achievement Tracking
- Progress Monitoring
- Assessment Management
- Calendar and Schedule Management
The TMS is built using a microservices architecture with Django REST Framework backend and Next.js frontend. It implements advanced features like:
- JWT-based authentication
- Real-time progress tracking
- Advanced user activity monitoring
- Comprehensive skill management
- Achievement system
- File management
Frontend (Next.js) Backend (Django) Database
│ │ │
├── User Interface ├── API Layer ├── PostgreSQL
├── State Management ├── Business Logic ├── Migrations
└── API Integration └── Data Access └── Indexes
apps/
├── users/ # User Management Service
├── courses/ # Course Management Service
└── calendar_app/ # Calendar Management Service
graph TD
A[Frontend] -->|API Requests| B[API Gateway]
B --> C[User Service]
B --> D[Course Service]
B --> E[Calendar Service]
C -->|DB Operations| F[Database]
D -->|DB Operations| F
E -->|DB Operations| F
- Framework: Django 4.2.7
- API: Django REST Framework 3.14.0
- Database: PostgreSQL 14
- Authentication: JWT (djangorestframework-simplejwt)
# Backend Dependencies
django-cors-headers==4.3.0
django-filter==23.5
django-phonenumber-field==7.3.0
Pillow==10.1.0
django-simple-history==3.4.0
psycopg2-binary==2.9.9
django-environ==0.11.2
- Framework: Next.js 13+
- State Management: React Query
- UI Components: Tailwind CSS
- Authentication: JWT with HTTP-only cookies
erDiagram
User ||--o{ UserProfile : has
User ||--o{ UserActivity : tracks
UserProfile ||--o{ UserSkill : has
UserProfile ||--|| TrainingPreference : has
erDiagram
Course ||--o{ Module : contains
Module ||--o{ Lesson : contains
Course ||--o{ Enrollment : has
User ||--o{ Enrollment : participates
-- Core User Table
CREATE TABLE users_user (
id UUID PRIMARY KEY,
email VARCHAR(254) UNIQUE NOT NULL,
role VARCHAR(20) NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE,
last_active TIMESTAMP WITH TIME ZONE,
failed_login_attempts INTEGER DEFAULT 0
);
-- User Profile
CREATE TABLE users_userprofile (
id UUID PRIMARY KEY,
user_id UUID REFERENCES users_user(id),
phone_number VARCHAR(128),
department VARCHAR(100),
position VARCHAR(100),
bio TEXT,
avatar VARCHAR(100),
skills JSONB,
preferences JSONB
);
-- Skills and Achievements
CREATE TABLE users_skill (
id UUID PRIMARY KEY,
name VARCHAR(100) UNIQUE,
category VARCHAR(50),
level_criteria JSONB
);
-- Course Table
CREATE TABLE courses_course (
id UUID PRIMARY KEY,
title VARCHAR(200) NOT NULL,
code VARCHAR(20) UNIQUE,
category VARCHAR(20),
difficulty_level VARCHAR(20),
duration_weeks INTEGER,
created_by UUID REFERENCES users_user(id)
);
-- Module Table
CREATE TABLE courses_module (
id UUID PRIMARY KEY,
course_id UUID REFERENCES courses_course(id),
title VARCHAR(200),
order INTEGER,
duration_hours INTEGER,
UNIQUE(course_id, order)
);
erDiagram
User ||--o{ Course : creates
User ||--o{ Enrollment : has
Course ||--o{ Module : contains
Module ||--o{ Lesson : contains
User ||--o{ UserSkill : acquires
Course ||--o{ RequiredSkill : requires
- Role-based access control (RBAC)
- Profile management
- Skill tracking
- Achievement system
- Activity monitoring
apps/users/
├── models/
│ ├── user.py
│ ├── profile.py
│ └── activity.py
├── views/
│ ├── auth.py
│ ├── profile.py
│ └── admin.py
└── services/
├── skill_service.py
└── achievement_service.py
- Course creation and modification
- Module and lesson management
- Enrollment handling
- Progress tracking
- Assessment system
apps/courses/
├── models/
│ ├── course.py
│ ├── module.py
│ └── enrollment.py
├── views/
│ ├── course.py
│ ├── enrollment.py
│ └── assessment.py
└── services/
├── progress_service.py
└── certificate_service.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
}
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': True,
}
class IsAdminUser(permissions.BasePermission):
def has_permission(self, request, view):
return request.user and request.user.role == UserRole.ADMIN
class IsTrainerOrAdmin(permissions.BasePermission):
def has_permission(self, request, view):
return request.user and request.user.role in [
UserRole.TRAINER,
UserRole.ADMIN
]
POST /api/auth/token/
POST /api/auth/token/refresh/
POST /api/auth/register/
GET /api/users/me/
PUT /api/users/me/
GET /api/users/profile/
PATCH /api/users/profile/
GET /api/users/skills/
POST /api/users/skills/
GET /api/courses/
POST /api/courses/
GET /api/courses/{id}/
PUT /api/courses/{id}/
GET /api/courses/{id}/modules/
POST /api/courses/{id}/enroll/
-
Unit Tests
class UserModelTest(TestCase): def test_user_creation(self): user = User.objects.create_user( email='test@example.com', password='testpass123' ) self.assertTrue(user.check_password('testpass123'))
-
Integration Tests
class UserAPITest(APITestCase): def test_user_registration(self): response = self.client.post('/api/auth/register/', { 'email': 'test@example.com', 'password': 'testpass123' }) self.assertEqual(response.status_code, 201)
-
End-to-End Tests
class EnrollmentFlowTest(TestCase): def test_complete_enrollment_flow(self): # Setup self.create_course() self.create_user() # Test enrollment self.enroll_user() # Verify enrollment self.verify_enrollment_success()
coverage run manage.py test
coverage report
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Setup database
python manage.py migrate
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "config.wsgi:application"]
# docker-compose.yml
version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
depends_on:
- db
db:
image: postgres:14
environment:
POSTGRES_DB: tms_db