How nisrinelr/task_rbac works
Project Type and Purpose
• This is a Laravel-based RESTful API (“Task App RBAC API”) that provides user registration/login, role-based access control (RBAC) for admins and users, and CRUD operations on tasks. It leverages Laravel Sanctum for token-based authentication and L5-Swagger for interactive API documentation.
File Structure Analysis
• Top-level directories:
• app/ (MVC: Controllers, Models, Middleware, Console, Exceptions, Providers)
• config/ (configuration for auth, database, cache, swagger, etc.)
• database/ (migrations, seeders, factories)
• public/ (web entry point index.php, assets)
• resources/ (static assets, blade views – minimal since API only)
• routes/ (api.php, web.php, etc.)
• tests/ (Feature and Unit tests)
• MVC pattern with clear separation of concerns.
• Sanctum and Middleware for authentication and RBAC (RoleMiddleware).
• Swagger docs in storage/api-docs.
Key Components
a. External Clients
• API consumers (web clients, Postman, frontend JS apps)
• Swagger UI (interactive API docs)
b. API Gateway / Web Server
• Nginx/Apache (or PHP built-in server via php artisan serve)
• Entry point: public/index.php → bootstrap/app.php
c. Laravel HTTP Kernel & Middleware
• Global middleware (e.g., TrimStrings, TrustProxies)
• Route middleware (Authenticate, VerifyCsrfToken, RoleMiddleware)
d. Routing Layer
• routes/api.php defines endpoints (/api/register, /api/login, /api/tasks, etc.)
e. Controllers
• AuthController (register, login, me)
• TasksController (CRUD operations with RBAC checks)
f. Services / Business Logic
• Eloquent Models (User, Task)
• Policies or Middleware enforcing roles
g. Persistence
• Database (SQLite/MySQL) with tables: users, tasks, personal_access_tokens, etc.
• Migrations & Seeders provision schema and initial data
h. Authentication & Token Management
• Laravel Sanctum issues and validates tokens
i. API Documentation
• L5-Swagger reads annotations and serves Swagger UI at /api/documentation
Interactions and Data Flow
1. Client → Web Server: HTTP(S) request
2. Web Server → public/index.php → Laravel Kernel
3. Kernel → Global & Route Middleware (Auth, Role checks)
4. Middleware → Routing resolves Controller
5. Controller → Model (via Eloquent) → Database
6. Database → Eloquent → Controller → JSON response
7. Client receives response or Swagger UI displays docs
Architectural Patterns & Principles
• MVC (Model-View-Controller) – though “View” is minimal for an API
• Layered Architecture: Presentation (HTTP/API) → Application (Controllers/Middleware) → Domain (Models/Policies) → Infrastructure (DB)
• RBAC via middleware for separation of security concerns
• Configuration-as-code (config/ directory)