How f1amy/laravel-realworld-example-app works
Project Type and Purpose
• This is a “backend‐only” RESTful API server built on the Laravel framework.
• It implements the RealWorld API spec: CRUD on articles, comments, profiles, tags, user auth via JWT, pagination, etc.
• It’s meant to run in Docker/Sail, exposing /api endpoints to any frontend.
File Structure
• Top-level code sits in app/ (Auth, Http, Jwt, Models, Policies, Console, Exceptions, Contracts, Providers).
• Routing lives in routes/api.php, routes/web.php.
• HTTP layer: public/index.php → controllers → requests/validators → resources/transformers → Eloquent models → database.
• Config in config/ (db, cache, jwt, etc).
• Docker integration via docker-compose.yml and Laravel Sail scripts.
• Tests under tests/ (Feature & Unit).
README Insights
• Confirms RESTful nature, JWT auth in app/Jwt, PostgreSQL backend via Sail.
• Mentions OpenAPI (Swagger) endpoint under /api/documentation.
a. Main Components
• External Client(s): Browser or mobile UI calling the API
• HTTP Server / Docker Proxy: Nginx (or Sail defaults) forwarding to PHP‐FPM
• Laravel Application (PHP-FPM container) subdivided into layers:
– Middleware (auth, cors, throttling)
– Controllers & Form Requests (validation)
– Resources (transformers)
– Services / JwtGuard / Custom JWT library
– Eloquent Models & Policies (domain logic)
• Database (PostgreSQL container)
• (Optional) Cache / Queue / Broadcast services (Redis, Horizon)
• Swagger UI (static view served from storage/api-docs)
• CI/CD pipelines (GitHub Actions for tests, static analysis)
b. Relationships & Interactions
1. Client → HTTP Server (80/443) → Laravel public/index.php.
2. Kernel dispatches through HTTP Middleware chain.
3. Route resolves to Controller method (e.g., ArticleController@index).
4. Controller uses FormRequest to validate, then calls Eloquent Model &/or JwtGuard.
5. Models read/write to PostgreSQL.
6. Responses are transformed via API Resources and returned as JSON.
7. CI/CD workflows monitor GitHub repo → trigger tests, coverage, static analysis.
c. Architectural Patterns & Principles
• MVC + layered architecture
• Dependency inversion via Contracts (interfaces in app/Contracts)
• Single Responsibility: FormRequest, Resources, Controllers, Models, Policies
• JWT‐based stateless authentication (custom implementation in app/Jwt)
• Configuration over hard-coding (config/*.php)
• Dockerized deployments (infrastructure as code)
d. Key Technologies & Frameworks
• PHP 8.x, Laravel 10.x
• Eloquent ORM
• Custom JWT library (builder, parser, validator)
• PostgreSQL (via Sail)
• GitHub Actions for CI
• PHPUnit & Laravel’s test suite
• Swagger/OpenAPI