|
| 1 | +# Rockae Backend Database Schema |
| 2 | + |
| 3 | +## Overview |
| 4 | +The backend database is a fully functionaly postgre sql |
| 5 | + |
| 6 | +## Database Schema |
| 7 | + |
| 8 | +### User Table |
| 9 | +| Column Name | Data Type | Constraints | |
| 10 | +|-------------|-----------|-------------| |
| 11 | +| `id` | Integer | Primary Key, Auto-increment | |
| 12 | +| `user_id` | CharField | Unique, Format: ADM<pk> or USR<pk> | |
| 13 | +| `username` | varchar(255) | Unique, NOT NULL | |
| 14 | +| `email` | varchar | Unique, NOT NULL | |
| 15 | +| `password` | varchar | NOT NULL | |
| 16 | +| `is_verified` | boolean | default: false | |
| 17 | +| `is_active` | boolean | default: true | |
| 18 | +| `date_joined` | datetime | auto-generated | |
| 19 | + |
| 20 | +### UserProfile Table |
| 21 | +| Column Name | Data Type | Constraints | |
| 22 | +|-------------|-----------|-------------| |
| 23 | +| `id` | Integer | PRIMARY KEY, AUTO_INCREMENT | |
| 24 | +| `user` | ForeignKey | REFERENCES User (user_id), UNIQUE | |
| 25 | +| `firstname` | varchar | | |
| 26 | +| `lastname` | varchar | | |
| 27 | +| `phone_number` | varchar | nullable | |
| 28 | +| `photo` | file | nullable | |
| 29 | + |
| 30 | +### Quiz Table |
| 31 | +| Column Name | Data Type | Constraints | |
| 32 | +|-------------|-----------|-------------| |
| 33 | +| `id` | int | PRIMARY KEY | |
| 34 | +| `quiz_title` | varchar | NOT NULL | |
| 35 | +| `description` | text | nullable | |
| 36 | +| `user` | int | FOREIGN KEY REFERENCES User (user_id) | |
| 37 | +| `create_date` | datetime | auto-generated | |
| 38 | +| `number_of_questions` | int | default: 10 | |
| 39 | +| `difficulty_level` | varchar | Choices: Easy, Medium, Hard | |
| 40 | +| `category` | varchar | NOT NULL | |
| 41 | +| `is_public` | boolean | default: false | |
| 42 | +| `is_timed` | boolean | default: false | |
| 43 | +| `time_limit` | float | nullable | |
| 44 | +| `auth_required` | boolean | default: false | |
| 45 | +| `has_flash_card` | boolean | default: false | |
| 46 | + |
| 47 | +### Question Table |
| 48 | +| Column Name | Data Type | Constraints | |
| 49 | +|-------------|-----------|-------------| |
| 50 | +| `id` | int | PRIMARY KEY | |
| 51 | +| `quiz_id` | int | ForeignKey to Quiz | |
| 52 | +| `text` | text | NOT NULL | |
| 53 | + |
| 54 | +### AnswerOption Table |
| 55 | +| Column Name | Data Type | Constraints | |
| 56 | +|-------------|-----------|-------------| |
| 57 | +| `id` | int | PRIMARY KEY | |
| 58 | +| `question_id` | int | ForeignKey to Question | |
| 59 | +| `label` | varchar(1) | NOT NULL (A, B, C, D, etc.) | |
| 60 | +| `text` | text | NOT NULL | |
| 61 | +| `is_correct` | boolean | NOT NULL | |
| 62 | + |
| 63 | +### Flashcard Table |
| 64 | +| Column Name | Data Type | Constraints | |
| 65 | +|-------------|-----------|-------------| |
| 66 | +| `id` | int | PRIMARY KEY | |
| 67 | +| `title` | varchar | NOT NULL | |
| 68 | +| `description` | text | nullable | |
| 69 | +| `user_id` | int | ForeignKey to User | |
| 70 | +| `quiz_id` | int | One-to-one relationship with Quiz, nullable | |
| 71 | + |
| 72 | +### FlashcardItem Table |
| 73 | +| Column Name | Data Type | Constraints | |
| 74 | +|-------------|-----------|-------------| |
| 75 | +| `id` | int | PRIMARY KEY | |
| 76 | +| `flashcard_id` | int | ForeignKey to Flashcard | |
| 77 | +| `question` | text | NOT NULL | |
| 78 | +| `answer` | text | NOT NULL | |
| 79 | + |
| 80 | +### SubscriptionPlan Table |
| 81 | +| Column Name | Data Type | Constraints | |
| 82 | +|-------------|-----------|-------------| |
| 83 | +| `id` | int | PRIMARY KEY | |
| 84 | +| `name` | varchar | UNIQUE, NOT NULL | |
| 85 | +| `duration_days` | int | NOT NULL | |
| 86 | +| `price` | decimal | NOT NULL | |
| 87 | +| `is_active` | boolean | default: true | |
| 88 | + |
| 89 | +### UserSubscription Table |
| 90 | +| Column Name | Data Type | Constraints | |
| 91 | +|-------------|-----------|-------------| |
| 92 | +| `id` | int | PRIMARY KEY | |
| 93 | +| `user_id` | int | ForeignKey to User | |
| 94 | +| `plan_id` | int | ForeignKey to SubscriptionPlan | |
| 95 | +| `start_date` | datetime | auto-generated | |
| 96 | +| `end_date` | datetime | calculated from SubscriptionPlan | |
| 97 | + |
| 98 | +## API Endpoints |
| 99 | + |
| 100 | +(Endpoints listed as previously defined) |
| 101 | + |
| 102 | +## Technologies |
| 103 | +- **Django** |
| 104 | +- **Django REST Framework** |
| 105 | +- **JWT Authentication** |
| 106 | +- **Pandas (CSV/Excel processing)** |
| 107 | +- **DRF Spectacular (API documentation)** |
| 108 | +- **Generative AI (Gemini)** |
| 109 | +- **Decouple (Environment Variables Management)** |
| 110 | +- **Corsheaders (Cross-Origin Resource Sharing)** |
| 111 | + |
| 112 | +## Security Measures |
| 113 | +- **JWT Authentication** |
| 114 | +- **Custom Permission Classes** |
| 115 | +- **Data Validation & Sanitization** |
| 116 | +- **Error Handling & Standardized Responses** |
| 117 | +- **File Upload Security** |
| 118 | +- **FTP Secure Storage** |
| 119 | + |
| 120 | +## Deployment |
| 121 | +- Uses FTP storage for handling static and user-uploaded files |
| 122 | +- Environment configuration via `python-decouple` |
| 123 | +- Ready for deployment to platforms such as Railway, Heroku, or AWS |
| 124 | + |
| 125 | +## Documentation |
| 126 | +- Comprehensive API documentation via DRF Spectacular (Swagger/OpenAPI) |
| 127 | + |
| 128 | +## Configuration |
| 129 | +- Secure environment variables handling (`SECRET_KEY`, `DATABASE_URL`, SMTP settings, AI keys) |
| 130 | +- Database configured for optimized production performance (`dj_database_url`) |
| 131 | +- JWT authentication token lifetime configurable |
| 132 | + |
| 133 | +## Future Enhancements |
| 134 | +- Real-time analytics |
| 135 | +- Enhanced admin interface |
| 136 | +- User activity logs |
| 137 | +- Expanded subscription and payment options |
| 138 | + |
0 commit comments