How liorocks/pingcrm-react works
Project Type and Purpose
• This is a full-stack demo CRM application (“Ping CRM React”) showcasing how Laravel (PHP) and React integrate via Inertia.js.
• The Laravel backend exposes controllers, models and routes (MVC), while the React front-end renders pages and components. Inertia.js glues them together, providing SPA behavior without a separate API.
File Structure Analysis
• Top-level folders:
• app/ (Laravel MVC code: Controllers, Middleware, Models, Requests, Resources)
• resources/js/ (React components, layouts, pages, utilities, TypeScript types)
• database/ (migrations, factories, seeders)
• config/ (Laravel config)
• public/ (entry point index.php, compiled assets, robots.txt)
• routes/ (web.php, console.php)
• tests/ (PHPUnit feature tests)
• root config files (composer.json, package.json, vite.config.js, tailwind.config.js, .env.example)
• Build scripts / dev tooling: Vite (vite.config.js), Tailwind CSS, NPM scripts, Composer, Makefile, Procfile (for Heroku).
Key README Insights
• Purpose: illustrate Inertia.js bridging Laravel and React.
• Tech stack: Laravel, Inertia.js, React, Vite, Tailwind.
• Database: SQLite by default (can be swapped), seeded with users, organizations, contacts.
a. Main Components
• Browser / Client: React SPA entry (public/index.php loads Laravel, serves initial HTML, then React hydration via Inertia).
• Inertia.js Middleware: intercepts requests, serializes props, returns Inertia responses (JSON + page component name).
• HTTP Layer & Routing: routes/web.php defines endpoints; HTTP Kernel loads middleware (TrustProxies, HandleInertiaRequests, Sanctum for auth).
• Controllers (app/Http/Controllers): handle requests (Auth\LoginController, ContactsController, UsersController, etc.), invoke Request validation, interact with Models, return Inertia::render or Resource JSON.
• Models & ORM: Eloquent models (User, Organization, Contact, Account) handle database interactions.
• Database: SQLite/MySQL/Postgres; schema managed via migrations; seeded data via seeders and factories.
• Asset Pipeline: Vite compiles resources/js and resources/css into public/build; served by Laravel’s mix middleware.
• External Services: Mail (config/mail.php), optional file storage (public uploads), third-party APIs (config/services.php).
• Testing: PHPUnit tests exercising feature flows via HTTP requests.
b. Relationships & Data Flow
1. User interacts with React UI (components/pages under resources/js/Pages).
2. Inertia intercepts link/navigation/forms → axios/fetch calls to Laravel endpoints.
3. Laravel routing → middleware → controller.
4. Controller validates Request → uses Eloquent Model → reads/writes DB.
5. Controller returns an Inertia response: page component + props (data) → sent as JSON.
6. Inertia on the client side updates the React component tree with new props.
7. Assets (JS/CSS) served from public/build; environment variables loaded from .env.
8. Tests simulate HTTP requests at the routing layer, assert JSON or HTTP response.
c. Architectural Patterns & Principles
• MVC on the backend (Controllers, Models, Views abstracted as Inertia pages)
• Component-based UI on the frontend (React + TSX)
• Single-page application via Inertia.js (no separate REST API)
• RESTful resource controllers (~ContactsController, UsersController, OrganizationsController)
• Layered architecture: Presentation (React/Inertia), Application (Laravel controllers/services), Data (Eloquent/DB).
• Use of middleware pipeline for cross-cutting concerns (auth, CSRF, proxies).
d. Key Technologies
• Backend: Laravel, PHP 7+, Composer packages, Sanctum for SPA auth.
• Frontend: React, TypeScript, Inertia.js, Vite, Tailwind CSS, Axios.
• Database: SQLite/MySQL/Postgres, Eloquent ORM, migrations & seeders.
• Testing: PHPUnit, Laravel’s testing helpers.