How neetunabbu/laravel-api-auth works
Project Type and Purpose
• This is a backend‐only RESTful API built with Laravel 10, focused on user authentication (registration, login, profile, logout).
• It uses token-based authentication via Laravel Sanctum, enforces rate limiting, and has been tested with Postman.
File Structure Analysis
• Top-level:
• app/ (MVC code: Controllers, Middleware, Models, Console commands, Exception handling)
• bootstrap/, config/, database/ (migrations, seeders), public/ (entry point), resources/ (static assets and views), routes/, storage/, tests/.
• Key directories:
• app/Http/Controllers/API – AuthController
• app/Http/Middleware – auth, rate limiting, CSRF, etc.
• app/Models – User model
• routes/api.php – defines /api/register, /api/login, /api/profile, /api/logout
• Config files for Sanctum, caching, database, queue, etc.
README Insights
• Core functionality: secure user registration/login/logout and protected profile route.
• Technology stack: Laravel 10, Sanctum, PHP, Eloquent ORM, MySQL (or configured DB), Postman.
a. Main Components
• Client (Postman or any front-end)
• HTTP Server (Nginx/Apache)
• Laravel Application
• Route Layer (routes/api.php)
• Middleware Layer (Sanctum authentication, rate limiter, CSRF, CORS)
• Controller Layer (AuthController)
• Service/Domain Layer (User registration, token issuance)
• Eloquent ORM (app/Models/User.php)
• Database (MySQL/PostgreSQL)
• Cache/Rate Limiter (Redis or filesystem)
• External Services (optional mail server, logging)
b. Relationships and Interactions
1. Client → HTTP Server: sends HTTP request with JSON payload or Bearer token
2. HTTP Server → public/index.php: entry point triggers Laravel bootstrap
3. Laravel → Route matching (routes/api.php) → Middleware pipeline
4. Middleware (Authenticate, Sanctum guard, RateLimiter) → Controller
5. Controller invokes Eloquent models/services → Database for reads/writes
6. Controller returns JSON response → middleware for response formatting → HTTP Server → Client
7. On login/register: Sanctum issues token and stores in personal_access_tokens table
c. Architectural Patterns
• MVC: controllers handle HTTP, models represent data, views unused (API only)
• Middleware pipeline for cross-cutting concerns (auth, rate limiting)
• Service providers for bootstrapping (Sanctum, events, routes)
• Token-based stateless authentication
d. Key Technologies and Libraries
• PHP 8+, Laravel 10 framework
• Laravel Sanctum (app/Providers/Sanctum, config/sanctum.php)
• Eloquent ORM (database interactions)
• MySQL/PostgreSQL (config/database.php)
• Cache backend (config/cache.php)
• Rate limiter (config/limiting.php or default settings)
• Composer (dependency management)