This repository contains a Laravel 12 based backend for managing branches, departments, folders, document types and secure Cloudinary backed uploads with token-based authentication powered by Laravel Sanctum + HTTP-only refresh tokens.
- API versioning (
/api/v1/...) enforced through a custom middleware. - Role based access control (SUPER_ADMIN, BRANCH_ADMIN, DEPARTMENT_ADMIN, DOCUMENT_CONTROLLER, USER).
- Branch, department, shelf, folder, document type, permission, role and document upload endpoints.
- Cloudinary signature generation + webhook to finalize uploads.
- Refresh token store with secure HTTP-only cookies.
- Caching for frequently accessed document types.
- Comprehensive database seeding for demo data (branches, departments, folders, documents, permissions, roles, users).
- Feature + unit tests (Auth, Branch, Document upload, Refresh token service).
- Postman collection for quick endpoint exploration (
docs/postman/document-management.postman_collection.json).
- PHP 8.3+
- Composer 2.6+
- MongoDB (default) - MongoDB server must be running
composer install
cp .env.example .env # configure MongoDB connection in .env
php artisan key:generateThe .env file should include MongoDB connection settings and other required keys:
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=event_booking
DB_USERNAME=
DB_PASSWORD=
DB_AUTHENTICATION_DATABASE=admin
API_VERSION=v1
SANCTUM_ACCESS_TOKEN_TTL=60
REFRESH_TOKEN_TTL_DAYS=30
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
CLOUDINARY_UPLOAD_PRESET=Populate the MongoDB connection details and Cloudinary credentials to enable functionality.
php artisan migrate --seedSeeding creates:
- 2 SUPER_ADMINs (
[email protected],[email protected], passwordPassword@123) - 3 branch admins, 10 department admins, 10 standard users
- 3 branches, 6 departments, 12 shelves, 36 folders
- 4 document types and 20 sample documents
php artisan serveAll endpoints are available under http://localhost:8000/api/v1.
php artisan testImport docs/postman/document-management.postman_collection.json. It contains examples for:
- Auth (register/login/refresh/logout/forgot/reset)
- Branch + Department CRUD
- Shelf/Folder/Document Type endpoints
- Document upload + webhook
- Permission, Role, and User Role assignment
app/Http/Controllers/Api # REST controllers
app/Http/Requests # DTO-style request validation
app/Http/Middleware # API version + role guards
app/Services # Cloudinary + refresh token services
app/Traits # Common query scopes
database/migrations # Schema for branches, departments, documents, etc.
database/seeders # Demo data
tests/Feature & tests/Unit # Automated coverage
- All responses share a consistent
{ status, message, data }schema viaBaseApiController. - Routes live in
routes/api.php, grouped by version, and protected withauth:sanctum+rolemiddleware. - Sanctum token TTL is controlled by
SANCTUM_ACCESS_TOKEN_TTLand refresh cookies byREFRESH_TOKEN_TTL_DAYS.
MIT © 2025
Prince