feat: Initial commit for Saqel Platform architecture, backend, Docker, and documentation
This commit is contained in:
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Concept;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Concept>
|
||||
*/
|
||||
class ConceptFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'subject_id' => SubjectFactory::new(),
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Course;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Course>
|
||||
*/
|
||||
class CourseFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'subject_id' => SubjectFactory::new(),
|
||||
'grade' => 12,
|
||||
'track' => 'scientific',
|
||||
'title' => fake()->sentence(3),
|
||||
'description' => fake()->paragraph(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Lesson;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Lesson>
|
||||
*/
|
||||
class LessonFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'course_id' => CourseFactory::new(),
|
||||
'title' => fake()->sentence(4),
|
||||
'order_index' => fake()->numberBetween(1, 100),
|
||||
'video_id' => 'vid_'.fake()->unique()->uuid(),
|
||||
'duration_seconds' => fake()->numberBetween(300, 3600),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Question;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Question>
|
||||
*/
|
||||
class QuestionFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'quiz_id' => QuizFactory::new(),
|
||||
'concept_id' => ConceptFactory::new(),
|
||||
'body' => fake()->sentence().'؟',
|
||||
'explanation' => fake()->paragraph(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Quiz;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Quiz>
|
||||
*/
|
||||
class QuizFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'lesson_id' => LessonFactory::new(),
|
||||
'title' => fake()->sentence(2),
|
||||
'trigger_seconds' => fake()->numberBetween(60, 600),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Subject;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Subject>
|
||||
*/
|
||||
class SubjectFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
$name = fake()->unique()->randomElement(['mathematics', 'physics', 'chemistry', 'biology', 'arabic']);
|
||||
|
||||
return [
|
||||
'name' => ucfirst($name),
|
||||
'slug' => $name,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
'role' => 'student',
|
||||
'api_token' => Str::random(60),
|
||||
'grade' => 12,
|
||||
'track' => 'scientific',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function guardian(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => 'guardian',
|
||||
'grade' => null,
|
||||
'track' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedSmallInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->string('connection');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
|
||||
$table->index(['connection', 'queue', 'failed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('role', 20)->default('student')->index();
|
||||
$table->string('api_token', 80)->unique()->nullable();
|
||||
$table->unsignedTinyInteger('grade')->nullable();
|
||||
$table->string('track', 20)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['role', 'api_token', 'grade', 'track']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('subjects', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('courses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('subject_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedTinyInteger('grade');
|
||||
$table->string('track', 20);
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('lessons', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('course_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->unsignedInteger('order_index')->default(0);
|
||||
$table->string('video_id')->nullable();
|
||||
$table->unsignedInteger('duration_seconds')->default(0);
|
||||
$table->text('transcript')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('concepts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('subject_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->foreignId('remedial_lesson_id')->nullable()->constrained('lessons')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['subject_id', 'name']);
|
||||
});
|
||||
|
||||
Schema::create('lesson_concept', function (Blueprint $table) {
|
||||
$table->foreignId('lesson_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('concept_id')->constrained()->cascadeOnDelete();
|
||||
$table->primary(['lesson_id', 'concept_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lesson_concept');
|
||||
Schema::dropIfExists('concepts');
|
||||
Schema::dropIfExists('lessons');
|
||||
Schema::dropIfExists('courses');
|
||||
Schema::dropIfExists('subjects');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('quizzes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('lesson_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('title')->nullable();
|
||||
$table->unsignedInteger('trigger_seconds')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('questions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('quiz_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('concept_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->text('body');
|
||||
$table->text('explanation')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('question_options', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('question_id')->constrained()->cascadeOnDelete();
|
||||
$table->text('body');
|
||||
$table->boolean('is_correct')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('question_options');
|
||||
Schema::dropIfExists('questions');
|
||||
Schema::dropIfExists('quizzes');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('lesson_progress', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('lesson_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedInteger('last_position_seconds')->default(0);
|
||||
$table->unsignedTinyInteger('watched_percentage')->default(0);
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'lesson_id']);
|
||||
});
|
||||
|
||||
Schema::create('quiz_attempts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('quiz_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedTinyInteger('score');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('answers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('quiz_attempt_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('question_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('selected_option_id')->nullable()->constrained('question_options')->nullOnDelete();
|
||||
$table->boolean('is_correct');
|
||||
$table->unsignedInteger('time_spent_seconds')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('concept_mastery', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('concept_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedInteger('correct_count')->default(0);
|
||||
$table->unsignedInteger('wrong_count')->default(0);
|
||||
$table->decimal('mastery_score', 5, 2)->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'concept_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('concept_mastery');
|
||||
Schema::dropIfExists('answers');
|
||||
Schema::dropIfExists('quiz_attempts');
|
||||
Schema::dropIfExists('lesson_progress');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('guardian_student', function (Blueprint $table) {
|
||||
$table->foreignId('guardian_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->foreignId('student_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->primary(['guardian_id', 'student_id']);
|
||||
});
|
||||
|
||||
Schema::create('ai_reports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('type', 40)->index();
|
||||
$table->json('payload');
|
||||
$table->text('summary')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ai_reports');
|
||||
Schema::dropIfExists('guardian_student');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user