Skip to content

Backend Documentation

Welcome to the CPR Backend documentation. This guide covers the Laravel 12 REST API that powers the Clinical Patient Records system.

Quick Start

bash
# Clone and install
git clone <repo-url>
cd cpr-backend
composer install

# Environment setup
cp .env.example .env
php artisan key:generate

# Database
php artisan migrate
php artisan db:seed

# Run development servers (Laravel + Queue + Logs + Vite)
composer dev

The API will be available at http://localhost:8000/api/v1.

Using Docker (Laravel Sail)

bash
./vendor/bin/sail up -d
./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan db:seed

Services: Laravel (port 80), MySQL 8.4 (port 3306), Redis 7 (port 6379), Mailhog (port 8025).

Project Structure

cpr-backend/
├── app/
│   ├── Actions/              # Single-responsibility command classes
│   ├── Contracts/            # Repository interfaces
│   ├── Dtos/                 # Data Transfer Objects
│   ├── Enums/                # PHP enums (status types, etc.)
│   ├── Exceptions/           # Custom exceptions
│   ├── Helpers/              # Utility functions (CodeGenerator)
│   ├── Http/
│   │   ├── Controllers/Api/V1/  # API v1 controllers
│   │   ├── Middleware/          # Auth, branch context, etc.
│   │   ├── Requests/            # Form request validation
│   │   └── Resources/           # API response transformers
│   ├── Models/               # Eloquent models (63 models)
│   ├── Pipelines/            # Processing chains (patient, auth)
│   ├── Providers/            # Service & repository bindings
│   ├── Repositories/         # Data access layer (46 repos)
│   ├── Services/             # Business logic (41 services)
│   └── Traits/               # Reusable traits
├── config/                   # Laravel configuration
├── database/
│   ├── factories/            # Model factories (56)
│   ├── migrations/           # Schema migrations (114)
│   └── seeders/              # Data seeders (38)
├── routes/
│   ├── api.php               # Main API routes
│   └── api/v1/               # Versioned route files (43 files)
├── tests/
│   ├── Feature/              # Integration tests (170+)
│   ├── Traits/               # Test helpers
│   └── Pest.php              # Pest configuration
├── compose.yaml              # Docker Compose
├── phpunit.xml               # Test configuration
└── composer.json             # Dependencies & scripts

Available Commands

CommandDescription
composer devStart all dev servers (Laravel, Queue, Logs, Vite)
composer testRun tests in parallel (10 processes)
composer stanRun PHPStan static analysis
composer pintRun Laravel Pint code formatter
composer setupFull setup (install, migrate, build)

Documentation Sections

Architecture & Standards

Guidelines

API

Database

Security

Testing

Performance

Tooling

Workflow

CPR - Clinical Patient Records