# aboelresh/riwaq architecture

> Architecture diagram of the GitHub repository aboelresh/riwaq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aboelresh/riwaq
- Repository: https://github.com/aboelresh/riwaq

## Overview

Riwaq is a multi-tenant adaptive-learning REST API. Its main workflow authenticates a learner, resolves the learner’s organization, serves tenant-scoped learning content, and records progress or assessment outcomes. The graph preserves the README’s major capabilities—learning, collaboration, AI, organizations and entitlements, notifications, search, and queued email—alongside the documented request pipeline. Several subsystem paths are directory-level because their individual implementations were not sampled; relationships shown from the README reflect its documented architecture, not inspection of unsampled code.

Main entry points: [`app/Http/Controllers/Api`](https://github.com/aboelresh/riwaq/tree/master/app/Http/Controllers/Api) (API controllers), [`app/Http/Middleware`](https://github.com/aboelresh/riwaq/tree/master/app/Http/Middleware) (Request middleware), [`app/Jobs/SendTeamInviteEmailJob.php`](https://github.com/aboelresh/riwaq/blob/master/app/Jobs/SendTeamInviteEmailJob.php) (Queued email jobs), [`routes/api.php`](https://github.com/aboelresh/riwaq/blob/master/routes/api.php) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["API access"]
  node_api["API routes<br/>[api.php]"]
  node_middleware["Request middleware"]
  node_auth["JWT authentication"]
  node_controllers["API controllers"]
  node_validation["Input validation"]
end

subgraph group_learning["Learning experience"]
  node_content["Tracks courses topics<br/>[Track.php]"]
  node_quizzes["Quiz engine<br/>[QuizService.php]"]
  node_assessment["Assessment"]
  node_progress["Learning progress"]
  node_recommendation["Level analysis"]
  node_video["Video progress<br/>[VideoService.php]"]
end

subgraph group_collaboration["Team collaboration"]
  node_teams["Team collaboration<br/>[TeamController.php]"]
  node_chat["Team chat<br/>[ChatController.php]"]
end

subgraph group_tenant["Tenant and SaaS"]
  node_organization["Organization management"]
  node_entitlements["Plan entitlements"]
  node_tenantcontext["Tenant context<br/>[TenantContext.php]"]
  node_tenantmodels["Tenant-scoped models"]
end

subgraph group_services["Platform services"]
  node_database[("Relational database")]
  node_ai["AI chat"]
  node_notifications["In-app notifications"]
  node_emailjobs["Queued email jobs"]
  node_search["Search"]
end

node_learner(("Learner or admin"))
node_ai_provider{{"AI providers"}}
node_mail{{"Email delivery"}}
node_cachequeue[("Redis cache and queue")]

node_learner -->|"sends request"| node_api
node_api -->|"routes through"| node_middleware
node_middleware -->|"dispatches"| node_controllers
node_middleware -->|"resolves tenant"| node_tenantcontext
node_controllers -->|"validates input"| node_validation
node_controllers -->|"serves learning content"| node_content
node_controllers -->|"handles quiz activity"| node_quizzes
node_controllers -->|"handles assessment"| node_assessment
node_controllers -->|"records progress"| node_progress
node_controllers -.->|"provides analysis"| node_recommendation
node_controllers -->|"tracks viewing"| node_video
node_controllers -->|"handles collaboration"| node_teams
node_controllers -->|"handles team chat"| node_chat
node_controllers -->|"manages organizations"| node_organization
node_controllers -->|"checks plan limits"| node_entitlements
node_controllers -->|"handles AI chat"| node_ai
node_ai -.->|"uses providers"| node_ai_provider
node_controllers -->|"sends notifications"| node_notifications
node_controllers -->|"dispatches email"| node_emailjobs
node_emailjobs -->|"delivers email"| node_mail
node_controllers -->|"serves search"| node_search
node_tenantcontext -->|"scopes queries"| node_tenantmodels
node_content -->|"reads and writes"| node_database
node_quizzes -->|"reads and writes"| node_database
node_assessment -->|"reads and writes"| node_database
node_progress -->|"reads and writes"| node_database
node_teams -->|"reads and writes"| node_database
node_organization -->|"reads and writes"| node_database
node_emailjobs -->|"uses queue"| node_cachequeue

click node_api "https://github.com/aboelresh/riwaq/blob/master/routes/api.php"
click node_middleware "https://github.com/aboelresh/riwaq/tree/master/app/Http/Middleware"
click node_auth "https://github.com/aboelresh/riwaq/tree/master/app/Http/Controllers/Api/Auth"
click node_controllers "https://github.com/aboelresh/riwaq/tree/master/app/Http/Controllers/Api"
click node_validation "https://github.com/aboelresh/riwaq/tree/master/app/Http/Requests"
click node_content "https://github.com/aboelresh/riwaq/blob/master/app/Models/Track.php"
click node_quizzes "https://github.com/aboelresh/riwaq/blob/master/app/Services/QuizService.php"
click node_assessment "https://github.com/aboelresh/riwaq/blob/master/app/Services/AssessmentService.php"
click node_progress "https://github.com/aboelresh/riwaq/blob/master/app/Services/ProgressService.php"
click node_recommendation "https://github.com/aboelresh/riwaq/blob/master/app/Services/LevelAnalysisService.php"
click node_video "https://github.com/aboelresh/riwaq/blob/master/app/Services/VideoService.php"
click node_teams "https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/TeamController.php"
click node_chat "https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/ChatController.php"
click node_organization "https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/Organization/OrganizationController.php"
click node_entitlements "https://github.com/aboelresh/riwaq/blob/master/app/SaaS/EntitlementService.php"
click node_tenantcontext "https://github.com/aboelresh/riwaq/blob/master/app/SaaS/TenantContext.php"
click node_tenantmodels "https://github.com/aboelresh/riwaq/blob/master/app/SaaS/BelongsToTenant.php"
click node_ai "https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/AiChatController.php"
click node_notifications "https://github.com/aboelresh/riwaq/blob/master/app/Services/NotificationService.php"
click node_emailjobs "https://github.com/aboelresh/riwaq/blob/master/app/Jobs/SendTeamInviteEmailJob.php"
click node_search "https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/SearchController.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_middleware,node_auth,node_controllers,node_validation toneBlue
class node_content,node_quizzes,node_assessment,node_progress,node_recommendation,node_video,node_cachequeue toneAmber
class node_teams,node_chat toneMint
class node_organization,node_entitlements,node_tenantcontext,node_tenantmodels toneRose
class node_database,node_ai,node_notifications,node_emailjobs,node_search,node_learner,node_ai_provider,node_mail toneIndigo
```

## Components

### API access

- [API routes](https://github.com/aboelresh/riwaq/blob/master/routes/api.php): `routes/api.php`
- [Request middleware](https://github.com/aboelresh/riwaq/tree/master/app/Http/Middleware): `app/Http/Middleware`
- [JWT authentication](https://github.com/aboelresh/riwaq/tree/master/app/Http/Controllers/Api/Auth): `app/Http/Controllers/Api/Auth`
- [API controllers](https://github.com/aboelresh/riwaq/tree/master/app/Http/Controllers/Api): `app/Http/Controllers/Api`
- [Input validation](https://github.com/aboelresh/riwaq/tree/master/app/Http/Requests): `app/Http/Requests`

### Learning experience

- [Tracks courses topics](https://github.com/aboelresh/riwaq/blob/master/app/Models/Track.php): `app/Models/Track.php`
- [Quiz engine](https://github.com/aboelresh/riwaq/blob/master/app/Services/QuizService.php): `app/Services/QuizService.php`
- [Assessment](https://github.com/aboelresh/riwaq/blob/master/app/Services/AssessmentService.php): `app/Services/AssessmentService.php`
- [Learning progress](https://github.com/aboelresh/riwaq/blob/master/app/Services/ProgressService.php): `app/Services/ProgressService.php`
- [Level analysis](https://github.com/aboelresh/riwaq/blob/master/app/Services/LevelAnalysisService.php): `app/Services/LevelAnalysisService.php`
- [Video progress](https://github.com/aboelresh/riwaq/blob/master/app/Services/VideoService.php): `app/Services/VideoService.php`

### Team collaboration

- [Team collaboration](https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/TeamController.php): `app/Http/Controllers/Api/TeamController.php`
- [Team chat](https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/ChatController.php): `app/Http/Controllers/Api/ChatController.php`

### Tenant and SaaS

- [Organization management](https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/Organization/OrganizationController.php): `app/Http/Controllers/Api/Organization/OrganizationController.php`
- [Plan entitlements](https://github.com/aboelresh/riwaq/blob/master/app/SaaS/EntitlementService.php): `app/SaaS/EntitlementService.php`
- [Tenant context](https://github.com/aboelresh/riwaq/blob/master/app/SaaS/TenantContext.php): `app/SaaS/TenantContext.php`
- [Tenant-scoped models](https://github.com/aboelresh/riwaq/blob/master/app/SaaS/BelongsToTenant.php): `app/SaaS/BelongsToTenant.php`

### Platform services

- **Relational database**
- [AI chat](https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/AiChatController.php): `app/Http/Controllers/Api/AiChatController.php`
- [In-app notifications](https://github.com/aboelresh/riwaq/blob/master/app/Services/NotificationService.php): `app/Services/NotificationService.php`
- [Queued email jobs](https://github.com/aboelresh/riwaq/blob/master/app/Jobs/SendTeamInviteEmailJob.php): `app/Jobs/SendTeamInviteEmailJob.php`
- [Search](https://github.com/aboelresh/riwaq/blob/master/app/Http/Controllers/Api/SearchController.php): `app/Http/Controllers/Api/SearchController.php`

### Other components

- **Learner or admin**
- **AI providers**
- **Email delivery**
- **Redis cache and queue**

## Connections

- Learner or admin → API routes: sends request (evidence: `README.md`)
- API routes → Request middleware: routes through (evidence: `README.md`)
- Request middleware → API controllers: dispatches (evidence: `README.md`)
- Request middleware → Tenant context: resolves tenant (evidence: `README.md`)
- API controllers → Input validation: validates input (evidence: `README.md`)
- API controllers → Tracks courses topics: serves learning content (evidence: `README.md`)
- API controllers → Quiz engine: handles quiz activity (evidence: `README.md`)
- API controllers → Assessment: handles assessment (evidence: `README.md`)
- API controllers → Learning progress: records progress (evidence: `README.md`)
- API controllers → Level analysis: provides analysis
- API controllers → Video progress: tracks viewing (evidence: `README.md`)
- API controllers → Team collaboration: handles collaboration (evidence: `README.md`)
- API controllers → Team chat: handles team chat (evidence: `README.md`)
- API controllers → Organization management: manages organizations (evidence: `README.md`)
- API controllers → Plan entitlements: checks plan limits (evidence: `README.md`)
- API controllers → AI chat: handles AI chat (evidence: `README.md`)
- AI chat → AI providers: uses providers
- API controllers → In-app notifications: sends notifications (evidence: `README.md`)
- API controllers → Queued email jobs: dispatches email (evidence: `app/Http/Controllers/Api/TeamController.php`)
- Queued email jobs → Email delivery: delivers email (evidence: `README.md`)
- API controllers → Search: serves search (evidence: `README.md`)
- Tenant context → Tenant-scoped models: scopes queries (evidence: `README.md`)
- Tracks courses topics → Relational database: reads and writes (evidence: `README.md`)
- Quiz engine → Relational database: reads and writes (evidence: `README.md`)
- Assessment → Relational database: reads and writes (evidence: `README.md`)
- Learning progress → Relational database: reads and writes (evidence: `README.md`)
- Team collaboration → Relational database: reads and writes (evidence: `app/Http/Controllers/Api/TeamController.php`)
- Organization management → Relational database: reads and writes (evidence: `app/Http/Controllers/Api/Organization/OrganizationController.php`)
- Queued email jobs → Redis cache and queue: uses queue (evidence: `README.md`)
