Release v0.2.0 #25
356 changed files with 24360 additions and 16944 deletions
|
|
@ -1,34 +0,0 @@
|
||||||
**/*.log
|
|
||||||
**/*.md
|
|
||||||
**/*.php~
|
|
||||||
**/*.dist.php
|
|
||||||
**/*.dist
|
|
||||||
**/*.cache
|
|
||||||
**/._*
|
|
||||||
**/.dockerignore
|
|
||||||
**/.DS_Store
|
|
||||||
**/.git/
|
|
||||||
**/.gitattributes
|
|
||||||
**/.gitignore
|
|
||||||
**/.gitmodules
|
|
||||||
**/compose.*.yaml
|
|
||||||
**/compose.*.yml
|
|
||||||
**/compose.yaml
|
|
||||||
**/compose.yml
|
|
||||||
**/docker-compose.*.yaml
|
|
||||||
**/docker-compose.*.yml
|
|
||||||
**/docker-compose.yaml
|
|
||||||
**/docker-compose.yml
|
|
||||||
**/Dockerfile
|
|
||||||
**/Thumbs.db
|
|
||||||
.github/
|
|
||||||
docs/
|
|
||||||
public/bundles/
|
|
||||||
tests/
|
|
||||||
var/
|
|
||||||
vendor/
|
|
||||||
.editorconfig
|
|
||||||
.env.*.local
|
|
||||||
.env.local
|
|
||||||
.env.local.php
|
|
||||||
.env.test
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
# editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
|
|
@ -10,8 +8,11 @@ indent_style = space
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[{compose.yaml,compose.*.yaml}]
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[docker-compose.yml]
|
||||||
|
indent_size = 4
|
||||||
|
|
|
||||||
41
.env
41
.env
|
|
@ -1,41 +0,0 @@
|
||||||
# In all environments, the following files are loaded if they exist,
|
|
||||||
# the latter taking precedence over the former:
|
|
||||||
#
|
|
||||||
# * .env contains default values for the environment variables needed by the app
|
|
||||||
# * .env.local uncommitted file with local overrides
|
|
||||||
# * .env.$APP_ENV committed environment-specific defaults
|
|
||||||
# * .env.$APP_ENV.local uncommitted environment-specific overrides
|
|
||||||
#
|
|
||||||
# Real environment variables win over .env files.
|
|
||||||
#
|
|
||||||
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
|
|
||||||
# https://symfony.com/doc/current/configuration/secrets.html
|
|
||||||
#
|
|
||||||
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
|
|
||||||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
|
||||||
|
|
||||||
###> symfony/framework-bundle ###
|
|
||||||
APP_ENV=dev
|
|
||||||
APP_SECRET=
|
|
||||||
APP_SHARE_DIR=var/share
|
|
||||||
###< symfony/framework-bundle ###
|
|
||||||
|
|
||||||
###> symfony/routing ###
|
|
||||||
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
|
|
||||||
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
|
|
||||||
DEFAULT_URI=http://localhost
|
|
||||||
###< symfony/routing ###
|
|
||||||
|
|
||||||
###> doctrine/doctrine-bundle ###
|
|
||||||
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
|
||||||
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
|
|
||||||
#
|
|
||||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db"
|
|
||||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
|
||||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
|
||||||
DATABASE_URL="postgresql://buckets:buckets@database:5432/buckets?serverVersion=16&charset=utf8"
|
|
||||||
###< doctrine/doctrine-bundle ###
|
|
||||||
|
|
||||||
###> nelmio/cors-bundle ###
|
|
||||||
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
|
||||||
###< nelmio/cors-bundle ###
|
|
||||||
4
.env.dev
4
.env.dev
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
###> symfony/framework-bundle ###
|
|
||||||
APP_SECRET=e40b1e033ac0fd255a7d69a334466243
|
|
||||||
###< symfony/framework-bundle ###
|
|
||||||
65
.env.example
Normal file
65
.env.example
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
APP_NAME=Laravel
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
APP_LOCALE=en
|
||||||
|
APP_FALLBACK_LOCALE=en
|
||||||
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
# APP_MAINTENANCE_STORE=database
|
||||||
|
|
||||||
|
# PHP_CLI_SERVER_WORKERS=4
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_STACK=single
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
|
DB_CONNECTION=sqlite
|
||||||
|
# DB_HOST=127.0.0.1
|
||||||
|
# DB_PORT=3306
|
||||||
|
# DB_DATABASE=laravel
|
||||||
|
# DB_USERNAME=root
|
||||||
|
# DB_PASSWORD=
|
||||||
|
|
||||||
|
SESSION_DRIVER=database
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
SESSION_ENCRYPT=false
|
||||||
|
SESSION_PATH=/
|
||||||
|
SESSION_DOMAIN=null
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=database
|
||||||
|
|
||||||
|
CACHE_STORE=database
|
||||||
|
# CACHE_PREFIX=
|
||||||
|
|
||||||
|
MEMCACHED_HOST=127.0.0.1
|
||||||
|
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_SCHEME=null
|
||||||
|
MAIL_HOST=127.0.0.1
|
||||||
|
MAIL_PORT=2525
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
# define your env variables for the test env here
|
|
||||||
KERNEL_CLASS='App\Kernel'
|
|
||||||
APP_SECRET='$ecretf0rt3st'
|
|
||||||
|
|
||||||
# Test database: real Postgres (same engine as prod). Doctrine's when@test config
|
|
||||||
# appends "_test" to the dbname, so this resolves to "buckets_test".
|
|
||||||
DATABASE_URL="postgresql://buckets:buckets@database:5432/buckets?serverVersion=16&charset=utf8"
|
|
||||||
25
.env.testing
Normal file
25
.env.testing
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
APP_NAME=Laravel
|
||||||
|
APP_ENV=testing
|
||||||
|
APP_KEY=base64:5VABFQKtzx6flRFn7rQUQYI/G8xLnkUSYPVaYz2s/4M=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=4
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_STACK=single
|
||||||
|
|
||||||
|
DB_CONNECTION=sqlite
|
||||||
|
DB_DATABASE=:memory:
|
||||||
|
|
||||||
|
SESSION_DRIVER=array
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=sync
|
||||||
|
|
||||||
|
CACHE_STORE=array
|
||||||
|
|
||||||
|
MAIL_MAILER=array
|
||||||
41
.forgejo/workflows/build.yml
Normal file
41
.forgejo/workflows/build.yml
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
name: Build and Push Docker Image
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags: ['v*']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://data.forgejo.org/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Forgejo Registry
|
||||||
|
uses: https://data.forgejo.org/docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: forge.lvl0.xyz
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Determine tags
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||||
|
TAG="${{ github.ref_name }}"
|
||||||
|
echo "tags=forge.lvl0.xyz/lvl0/buckets:${TAG},forge.lvl0.xyz/lvl0/buckets:latest" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "tags=forge.lvl0.xyz/lvl0/buckets:latest" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: https://data.forgejo.org/docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
113
.forgejo/workflows/ci.yml
Normal file
113
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['release/*']
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://data.forgejo.org/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
extensions: pdo_sqlite, mbstring, xml, dom
|
||||||
|
coverage: pcov
|
||||||
|
|
||||||
|
- name: Cache Composer dependencies
|
||||||
|
uses: https://data.forgejo.org/actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.composer/cache
|
||||||
|
key: composer-${{ hashFiles('composer.lock') }}
|
||||||
|
restore-keys: composer-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer install --no-interaction --prefer-dist
|
||||||
|
|
||||||
|
- name: Prepare environment
|
||||||
|
run: cp .env.testing .env
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: vendor/bin/pint --test
|
||||||
|
|
||||||
|
- name: Static analysis
|
||||||
|
run: vendor/bin/phpstan analyse --memory-limit=512M
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: php artisan test --coverage-clover coverage.xml --coverage-text
|
||||||
|
|
||||||
|
- name: Parse coverage
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
id: coverage
|
||||||
|
run: |
|
||||||
|
COVERAGE=$(php -r '
|
||||||
|
$xml = simplexml_load_file("coverage.xml");
|
||||||
|
if ($xml === false || !isset($xml->project->metrics)) {
|
||||||
|
echo "0";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$metrics = $xml->project->metrics;
|
||||||
|
$statements = (int) $metrics["statements"];
|
||||||
|
$covered = (int) $metrics["coveredstatements"];
|
||||||
|
echo $statements > 0 ? round(($covered / $statements) * 100, 2) : 0;
|
||||||
|
')
|
||||||
|
echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Comment coverage on PR
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
COVERAGE: ${{ steps.coverage.outputs.percentage }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
COMMIT_SHA: ${{ github.sha }}
|
||||||
|
run: |
|
||||||
|
API_URL="${SERVER_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments"
|
||||||
|
MARKER="<!-- buckets-ci-coverage-report -->"
|
||||||
|
|
||||||
|
BODY="${MARKER}
|
||||||
|
## Code Coverage Report
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
|--------|-------|
|
||||||
|
| **Line Coverage** | ${COVERAGE}% |
|
||||||
|
|
||||||
|
_Updated by CI — commit ${COMMIT_SHA}_"
|
||||||
|
|
||||||
|
# Find existing coverage comment
|
||||||
|
EXISTING=$(curl -sf -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
"${API_URL}?limit=50" | \
|
||||||
|
php -r '
|
||||||
|
$comments = json_decode(file_get_contents("php://stdin"), true);
|
||||||
|
if (!is_array($comments)) exit;
|
||||||
|
foreach ($comments as $c) {
|
||||||
|
if (str_contains($c["body"], "<!-- buckets-ci-coverage-report -->")) {
|
||||||
|
echo $c["id"];
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' || true)
|
||||||
|
|
||||||
|
if [ -n "$EXISTING" ]; then
|
||||||
|
# Update existing comment
|
||||||
|
curl -sf -X PATCH \
|
||||||
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \
|
||||||
|
"${SERVER_URL}/api/v1/repos/${REPO}/issues/comments/${EXISTING}" > /dev/null
|
||||||
|
else
|
||||||
|
# Create new comment
|
||||||
|
curl -sf -X POST \
|
||||||
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \
|
||||||
|
"${API_URL}" > /dev/null
|
||||||
|
fi
|
||||||
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
*.blade.php diff=html
|
||||||
|
*.css diff=css
|
||||||
|
*.html diff=html
|
||||||
|
*.md diff=markdown
|
||||||
|
*.php diff=php
|
||||||
|
|
||||||
|
CHANGELOG.md export-ignore
|
||||||
|
README.md export-ignore
|
||||||
|
.github/workflows/browser-tests.yml export-ignore
|
||||||
45
.github/workflows/lint.yml
vendored
Normal file
45
.github/workflows/lint.yml
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
name: linter
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
quality:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.4'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||||
|
npm install
|
||||||
|
|
||||||
|
- name: Run Pint
|
||||||
|
run: vendor/bin/pint
|
||||||
|
|
||||||
|
- name: Format Frontend
|
||||||
|
run: npm run format
|
||||||
|
|
||||||
|
- name: Lint Frontend
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
# - name: Commit Changes
|
||||||
|
# uses: stefanzweifel/git-auto-commit-action@v7
|
||||||
|
# with:
|
||||||
|
# commit_message: fix code style
|
||||||
|
# commit_options: '--no-verify'
|
||||||
50
.github/workflows/tests.yml
vendored
Normal file
50
.github/workflows/tests.yml
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
name: tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: 8.4
|
||||||
|
tools: composer:v2
|
||||||
|
coverage: xdebug
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install Node Dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
||||||
|
|
||||||
|
- name: Build Assets
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Copy Environment File
|
||||||
|
run: cp .env.example .env
|
||||||
|
|
||||||
|
- name: Generate Application Key
|
||||||
|
run: php artisan key:generate
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: ./vendor/bin/phpunit
|
||||||
57
.gitignore
vendored
57
.gitignore
vendored
|
|
@ -1,24 +1,33 @@
|
||||||
|
/.vite
|
||||||
###> symfony/framework-bundle ###
|
/.phpunit.cache
|
||||||
/.env.local
|
/bootstrap/ssr
|
||||||
/.env.local.php
|
/node_modules
|
||||||
/.env.*.local
|
/public/build
|
||||||
/config/secrets/prod/prod.decrypt.private.php
|
/public/hot
|
||||||
/public/bundles/
|
/public/storage
|
||||||
/var/
|
/public/vendor
|
||||||
/vendor/
|
/resources/js/actions
|
||||||
###< symfony/framework-bundle ###
|
/resources/js/routes
|
||||||
|
/resources/js/wayfinder
|
||||||
###> phpunit/phpunit ###
|
/storage/*.key
|
||||||
/phpunit.xml
|
/storage/pail
|
||||||
/.phpunit.cache/
|
/vendor
|
||||||
###< phpunit/phpunit ###
|
.env
|
||||||
|
.env.backup
|
||||||
###> phpstan/phpstan ###
|
.env.production
|
||||||
phpstan.neon
|
.phpactor.json
|
||||||
###< phpstan/phpstan ###
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
###> friendsofphp/php-cs-fixer ###
|
Homestead.yaml
|
||||||
/.php-cs-fixer.php
|
npm-debug.log
|
||||||
/.php-cs-fixer.cache
|
yarn-error.log
|
||||||
###< friendsofphp/php-cs-fixer ###
|
/package-lock.json
|
||||||
|
/auth.json
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.nova
|
||||||
|
/.vscode
|
||||||
|
/.zed
|
||||||
|
/coverage-report*
|
||||||
|
/coverage.xml
|
||||||
|
/.claude
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
$finder = (new PhpCsFixer\Finder())
|
|
||||||
->in(__DIR__)
|
|
||||||
->exclude('var')
|
|
||||||
// Auto-generated Symfony config files — not hand-written source, and the
|
|
||||||
// risky ruleset mangles prose like "@type" inside their doc comments.
|
|
||||||
->notPath('config/bundles.php')
|
|
||||||
->notPath('config/reference.php');
|
|
||||||
|
|
||||||
return (new PhpCsFixer\Config())
|
|
||||||
->setRiskyAllowed(true)
|
|
||||||
// PHP 8.4 may be newer than the fixer officially supports; allow it explicitly.
|
|
||||||
->setUnsupportedPhpVersionAllowed(true)
|
|
||||||
->setRules([
|
|
||||||
'@Symfony' => true,
|
|
||||||
'@Symfony:risky' => true,
|
|
||||||
])
|
|
||||||
->setFinder($finder)
|
|
||||||
->setCacheFile('var/.php-cs-fixer.cache');
|
|
||||||
2
.prettierignore
Normal file
2
.prettierignore
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
resources/js/components/ui/*
|
||||||
|
resources/views/mail/*
|
||||||
25
.prettierrc
Normal file
25
.prettierrc
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"singleAttributePerLine": false,
|
||||||
|
"htmlWhitespaceSensitivity": "css",
|
||||||
|
"printWidth": 80,
|
||||||
|
"plugins": [
|
||||||
|
"prettier-plugin-organize-imports",
|
||||||
|
"prettier-plugin-tailwindcss"
|
||||||
|
],
|
||||||
|
"tailwindFunctions": [
|
||||||
|
"clsx",
|
||||||
|
"cn"
|
||||||
|
],
|
||||||
|
"tailwindStylesheet": "resources/css/app.css",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "**/*.yml",
|
||||||
|
"options": {
|
||||||
|
"tabWidth": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
285
Dockerfile
285
Dockerfile
|
|
@ -1,179 +1,124 @@
|
||||||
#syntax=docker/dockerfile:1
|
# Production Dockerfile with FrankenPHP
|
||||||
|
FROM dunglas/frankenphp:latest-php8.3-alpine
|
||||||
|
|
||||||
# Versions
|
# Install system dependencies (except Node - Alpine's is too old for Vite 7)
|
||||||
FROM dunglas/frankenphp:1-php8.4 AS frankenphp_upstream
|
RUN apk add --no-cache \
|
||||||
|
git \
|
||||||
|
mysql-client \
|
||||||
|
curl
|
||||||
|
|
||||||
# The different stages of this Dockerfile are meant to be built into separate images
|
# Install Node.js 20.19.0+ (Vite 7 requires 20.19+)
|
||||||
# https://docs.docker.com/build/building/multi-stage/#stop-at-a-specific-build-stage
|
RUN curl -fsSL https://unofficial-builds.nodejs.org/download/release/v20.19.0/node-v20.19.0-linux-x64-musl.tar.xz | tar -xJ -C /usr/local --strip-components=1
|
||||||
# https://docs.docker.com/reference/compose-file/build/#target
|
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
# Base FrankenPHP image
|
RUN install-php-extensions \
|
||||||
FROM frankenphp_upstream AS frankenphp_base
|
pdo_mysql \
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# persistent deps
|
|
||||||
# hadolint ignore=DL3008
|
|
||||||
RUN <<-EOF
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
file \
|
|
||||||
git
|
|
||||||
install-php-extensions \
|
|
||||||
@composer \
|
|
||||||
apcu \
|
|
||||||
intl \
|
|
||||||
opcache \
|
opcache \
|
||||||
pdo_pgsql \
|
zip \
|
||||||
zip
|
gd \
|
||||||
rm -rf /var/lib/apt/lists/*
|
intl
|
||||||
EOF
|
|
||||||
|
|
||||||
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
# Install Composer
|
||||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
|
|
||||||
|
|
||||||
###> recipes ###
|
|
||||||
###< recipes ###
|
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/
|
|
||||||
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
|
||||||
COPY --link frankenphp/Caddyfile /etc/frankenphp/Caddyfile
|
|
||||||
|
|
||||||
ENTRYPOINT ["docker-entrypoint"]
|
|
||||||
|
|
||||||
HEALTHCHECK --start-period=60s CMD php -r 'exit(false === @file_get_contents("http://localhost:2019/metrics", context: stream_context_create(["http" => ["timeout" => 5]])) ? 1 : 0);'
|
|
||||||
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
|
|
||||||
|
|
||||||
# Dev FrankenPHP image
|
|
||||||
FROM frankenphp_base AS frankenphp_dev
|
|
||||||
|
|
||||||
ENV APP_ENV=dev
|
|
||||||
ENV XDEBUG_MODE=off
|
|
||||||
ENV FRANKENPHP_WORKER_CONFIG=watch
|
|
||||||
|
|
||||||
# dev dependencies
|
|
||||||
# hadolint ignore=DL3008
|
|
||||||
RUN <<-EOF
|
|
||||||
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
aggregate \
|
|
||||||
curl \
|
|
||||||
dnsmasq \
|
|
||||||
dnsutils \
|
|
||||||
iproute2 \
|
|
||||||
ipset \
|
|
||||||
iptables \
|
|
||||||
jq \
|
|
||||||
sudo
|
|
||||||
install-php-extensions xdebug
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
useradd -m -s /bin/bash nonroot
|
|
||||||
echo "nonroot ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nonroot
|
|
||||||
git config --system --add safe.directory /app
|
|
||||||
EOF
|
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
|
|
||||||
|
|
||||||
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ]
|
|
||||||
|
|
||||||
# Builder for the prod FrankenPHP image
|
|
||||||
FROM frankenphp_base AS frankenphp_prod_builder
|
|
||||||
|
|
||||||
ENV APP_ENV=prod
|
|
||||||
|
|
||||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
|
|
||||||
|
|
||||||
# prevent the reinstallation of vendors at every changes in the source code
|
|
||||||
COPY --link composer.* symfony.* ./
|
|
||||||
RUN composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress
|
|
||||||
|
|
||||||
# copy sources
|
|
||||||
COPY --link --exclude=frankenphp/ . ./
|
|
||||||
|
|
||||||
RUN <<-EOF
|
|
||||||
mkdir -p var/cache var/log var/share
|
|
||||||
composer dump-autoload --classmap-authoritative --no-dev
|
|
||||||
composer dump-env prod
|
|
||||||
composer run-script --no-dev post-install-cmd
|
|
||||||
if [ -f importmap.php ]; then
|
|
||||||
php bin/console asset-map:compile
|
|
||||||
fi
|
|
||||||
chmod +x bin/console
|
|
||||||
chmod -R g=u var
|
|
||||||
sync
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Collect shared libraries needed by FrankenPHP and PHP extensions
|
|
||||||
# hadolint ignore=DL3008,SC3054,DL4006
|
|
||||||
RUN <<-'EOF'
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --no-install-recommends libtree
|
|
||||||
mkdir -p /tmp/libs
|
|
||||||
BINARIES=(frankenphp php file)
|
|
||||||
for target in $(printf '%s\n' "${BINARIES[@]}" | xargs -I{} which {}) \
|
|
||||||
$(find "$(php -r 'echo ini_get("extension_dir");')" -maxdepth 2 -name "*.so"); do
|
|
||||||
libtree -pv "$target" 2>/dev/null | grep -oP '(?:── )\K/\S+(?= \[)' | while IFS= read -r lib; do
|
|
||||||
[ -f "$lib" ] && cp -n "$lib" /tmp/libs/
|
|
||||||
done
|
|
||||||
done
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Prod FrankenPHP image
|
|
||||||
FROM debian:13-slim AS frankenphp_prod
|
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
|
|
||||||
|
|
||||||
ENV APP_ENV=prod
|
|
||||||
ENV PHP_INI_SCAN_DIR=":/usr/local/etc/php/app.conf.d"
|
|
||||||
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/bin/php /usr/local/bin/php
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/bin/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions
|
|
||||||
COPY --from=frankenphp_prod_builder /tmp/libs /usr/lib
|
|
||||||
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/etc/php/php.ini /usr/local/etc/php/php.ini
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/local/etc/php/app.conf.d /usr/local/etc/php/app.conf.d
|
|
||||||
|
|
||||||
COPY --from=frankenphp_prod_builder /etc/frankenphp/Caddyfile /etc/frankenphp/Caddyfile
|
|
||||||
|
|
||||||
# CA certificates for TLS, file/libmagic for Symfony MIME type detection
|
|
||||||
COPY --from=frankenphp_prod_builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
COPY --from=frankenphp_prod_builder /etc/ssl/openssl.cnf /etc/ssl/openssl.cnf
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/bin/file /usr/bin/file
|
|
||||||
COPY --from=frankenphp_prod_builder /usr/lib/file/magic.mgc /usr/lib/file/magic.mgc
|
|
||||||
|
|
||||||
ENV OPENSSL_CONF=/etc/ssl/openssl.cnf XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data
|
|
||||||
|
|
||||||
RUN <<-EOF
|
|
||||||
mkdir -p /data/caddy /config/caddy
|
|
||||||
chown -R www-data:www-data /data /config
|
|
||||||
# Remove setuid/setgid bits
|
|
||||||
find / -perm /6000 -type f -exec chmod a-s {} + 2>/dev/null || true
|
|
||||||
EOF
|
|
||||||
|
|
||||||
COPY --link --exclude=var --from=frankenphp_prod_builder /app /app
|
|
||||||
# Group 0 + g=u for arbitrary-UID runtimes (e.g. OpenShift).
|
|
||||||
COPY --chown=www-data:0 --from=frankenphp_prod_builder /app/var /app/var
|
|
||||||
RUN chmod g=u /app/var
|
|
||||||
|
|
||||||
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
|
||||||
|
|
||||||
USER www-data
|
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENTRYPOINT ["docker-entrypoint"]
|
# Set fixed production environment variables
|
||||||
|
ENV APP_ENV=production \
|
||||||
|
APP_DEBUG=false \
|
||||||
|
DB_CONNECTION=mysql \
|
||||||
|
DB_HOST=db \
|
||||||
|
DB_PORT=3306 \
|
||||||
|
SESSION_DRIVER=database \
|
||||||
|
CACHE_DRIVER=file \
|
||||||
|
QUEUE_CONNECTION=database \
|
||||||
|
LOG_CHANNEL=stack \
|
||||||
|
LOG_LEVEL=error \
|
||||||
|
MAIL_MAILER=smtp \
|
||||||
|
MAIL_ENCRYPTION=tls
|
||||||
|
|
||||||
HEALTHCHECK --start-period=60s CMD php -r 'exit(false === @file_get_contents("http://localhost:2019/metrics", context: stream_context_create(["http" => ["timeout" => 5]])) ? 1 : 0);'
|
# Copy application code first
|
||||||
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
|
COPY . .
|
||||||
|
|
||||||
|
# Install PHP dependencies (production only)
|
||||||
|
RUN composer install --no-dev --no-interaction --optimize-autoloader
|
||||||
|
|
||||||
|
# Install ALL Node dependencies (including dev for building)
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Build frontend assets
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Remove node_modules after build to save space
|
||||||
|
RUN rm -rf node_modules
|
||||||
|
|
||||||
|
# Laravel optimizations
|
||||||
|
RUN php artisan config:cache \
|
||||||
|
&& php artisan route:cache \
|
||||||
|
&& composer dump-autoload --optimize
|
||||||
|
|
||||||
|
# Set permissions
|
||||||
|
RUN chown -R www-data:www-data /app/storage /app/bootstrap/cache
|
||||||
|
|
||||||
|
# Configure Caddy
|
||||||
|
RUN cat > /etc/caddy/Caddyfile <<EOF
|
||||||
|
{
|
||||||
|
frankenphp
|
||||||
|
order php_server before file_server
|
||||||
|
}
|
||||||
|
|
||||||
|
:8000 {
|
||||||
|
root * /app/public
|
||||||
|
|
||||||
|
php_server {
|
||||||
|
index index.php
|
||||||
|
}
|
||||||
|
|
||||||
|
encode gzip
|
||||||
|
|
||||||
|
file_server
|
||||||
|
|
||||||
|
header {
|
||||||
|
X-Frame-Options "SAMEORIGIN"
|
||||||
|
X-Content-Type-Options "nosniff"
|
||||||
|
X-XSS-Protection "1; mode=block"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
# Health check
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
|
CMD curl -f http://localhost:8000/up || exit 1
|
||||||
|
|
||||||
|
# Create startup script for production
|
||||||
|
RUN cat > /start-prod.sh <<'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Wait for database to be ready
|
||||||
|
echo "Waiting for database..."
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
if php artisan db:monitor --database=mysql 2>/dev/null | grep -q "OK"; then
|
||||||
|
echo "Database is ready!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "Waiting for database... ($i/30)"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
echo "Running migrations..."
|
||||||
|
php artisan migrate --force || echo "Migrations failed or already up-to-date"
|
||||||
|
|
||||||
|
# Start FrankenPHP
|
||||||
|
exec frankenphp run --config /etc/caddy/Caddyfile
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUN chmod +x /start-prod.sh
|
||||||
|
|
||||||
|
# Start with our script
|
||||||
|
CMD ["/start-prod.sh"]
|
||||||
|
|
|
||||||
117
Dockerfile.dev
Normal file
117
Dockerfile.dev
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
# Development Dockerfile with FrankenPHP
|
||||||
|
FROM dunglas/frankenphp:latest-php8.3-alpine
|
||||||
|
|
||||||
|
# Install system dependencies + development tools (except nodejs/npm)
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
git \
|
||||||
|
mysql-client \
|
||||||
|
vim \
|
||||||
|
bash \
|
||||||
|
nano \
|
||||||
|
curl
|
||||||
|
|
||||||
|
# Install Node.js 20.19.0+ from NodeSource (for compatibility with Vite 7)
|
||||||
|
RUN curl -fsSL https://unofficial-builds.nodejs.org/download/release/v20.19.0/node-v20.19.0-linux-x64-musl.tar.xz | tar -xJ -C /usr/local --strip-components=1
|
||||||
|
|
||||||
|
# Install PHP extensions including xdebug for development
|
||||||
|
RUN install-php-extensions \
|
||||||
|
pdo_mysql \
|
||||||
|
opcache \
|
||||||
|
zip \
|
||||||
|
gd \
|
||||||
|
intl \
|
||||||
|
xdebug
|
||||||
|
|
||||||
|
# Install Composer
|
||||||
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Configure PHP for development
|
||||||
|
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
||||||
|
|
||||||
|
# Configure Xdebug (disabled by default to reduce noise)
|
||||||
|
RUN echo "xdebug.mode=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||||
|
&& echo ";xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||||
|
&& echo ";xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
|
||||||
|
&& echo ";xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
||||||
|
|
||||||
|
# Configure Caddy for development (simpler, no worker mode)
|
||||||
|
RUN cat > /etc/caddy/Caddyfile <<EOF
|
||||||
|
{
|
||||||
|
frankenphp
|
||||||
|
order php_server before file_server
|
||||||
|
}
|
||||||
|
|
||||||
|
:8000 {
|
||||||
|
root * /app/public
|
||||||
|
|
||||||
|
php_server {
|
||||||
|
index index.php
|
||||||
|
}
|
||||||
|
|
||||||
|
encode gzip
|
||||||
|
|
||||||
|
file_server
|
||||||
|
|
||||||
|
# Less strict headers for development
|
||||||
|
header {
|
||||||
|
X-Frame-Options "SAMEORIGIN"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Install Node development dependencies globally
|
||||||
|
RUN npm install -g nodemon
|
||||||
|
|
||||||
|
# Create startup script for development (runs as host user)
|
||||||
|
RUN cat > /start.sh <<'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Fix DNS resolution by adding db host entry
|
||||||
|
# This is a workaround for podman-compose DNS issues
|
||||||
|
echo "10.89.1.2 db" >> /etc/hosts 2>/dev/null || true
|
||||||
|
|
||||||
|
# Create .env file if it doesn't exist
|
||||||
|
if [ ! -f ".env" ]; then
|
||||||
|
echo "Creating .env file from .env.example..."
|
||||||
|
cp .env.example .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Skip composer install - use mounted vendor directory
|
||||||
|
echo "Using mounted vendor directory, skipping composer install"
|
||||||
|
|
||||||
|
# Skip npm install - use mounted node_modules
|
||||||
|
echo "Using mounted node_modules directory, skipping npm install"
|
||||||
|
|
||||||
|
# Clear Laravel caches
|
||||||
|
php artisan config:clear || true
|
||||||
|
php artisan cache:clear || true
|
||||||
|
|
||||||
|
# Wait for database and run migrations
|
||||||
|
echo "Waiting for database..."
|
||||||
|
sleep 5
|
||||||
|
php artisan migrate --force || echo "Migration failed or not needed"
|
||||||
|
|
||||||
|
# Generate app key if not set
|
||||||
|
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:YOUR_KEY_HERE" ]; then
|
||||||
|
echo "Generating application key..."
|
||||||
|
php artisan key:generate
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start Vite dev server in background
|
||||||
|
npm run dev &
|
||||||
|
|
||||||
|
# Start FrankenPHP
|
||||||
|
exec frankenphp run --config /etc/caddy/Caddyfile
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUN chmod +x /start.sh
|
||||||
|
|
||||||
|
# Expose ports
|
||||||
|
EXPOSE 8000 5173
|
||||||
|
|
||||||
|
# Use the startup script
|
||||||
|
CMD ["/start.sh"]
|
||||||
661
LICENSE
Normal file
661
LICENSE
Normal file
|
|
@ -0,0 +1,661 @@
|
||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
202
README.md
Normal file
202
README.md
Normal file
|
|
@ -0,0 +1,202 @@
|
||||||
|
# Buckets Budget
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Buckets Budget is a modern web application for personal budget management using a bucket allocation system. Built with Laravel, Inertia.js, React, and TypeScript, it allows users to create different budget scenarios and allocate funds into various spending "buckets" - making budget planning intuitive and visual.
|
||||||
|
|
||||||
|
Key features:
|
||||||
|
- **Multiple Budget Scenarios**: Create and manage different budget projections (e.g., "2025 Budget", "Emergency Planning")
|
||||||
|
- **Bucket-based Allocation**: Organize spending into categorized buckets with allocated amounts
|
||||||
|
- **Modern Tech Stack**: Laravel backend with React/TypeScript frontend via Inertia.js
|
||||||
|
- **Containerized**: Ready for deployment with Docker/Podman
|
||||||
|
|
||||||
|
## Production Deployment
|
||||||
|
|
||||||
|
### Docker Compose Quick Start
|
||||||
|
|
||||||
|
1. **Create a `docker-compose.yml` file:**
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: codeberg.org/lvl0/buckets:latest
|
||||||
|
container_name: buckets_app
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
environment:
|
||||||
|
APP_NAME: "Buckets Budget"
|
||||||
|
APP_ENV: production
|
||||||
|
APP_DEBUG: false
|
||||||
|
APP_KEY: "${APP_KEY:-base64:generate_a_32_char_random_string_and_base64_encode_it}"
|
||||||
|
APP_URL: "${APP_URL:-http://localhost:8000}"
|
||||||
|
|
||||||
|
DB_CONNECTION: mysql
|
||||||
|
DB_HOST: db
|
||||||
|
DB_PORT: 3306
|
||||||
|
DB_DATABASE: buckets
|
||||||
|
DB_USERNAME: buckets
|
||||||
|
DB_PASSWORD: "${DB_PASSWORD:-change_me_in_production}"
|
||||||
|
|
||||||
|
SESSION_DRIVER: database
|
||||||
|
CACHE_DRIVER: file
|
||||||
|
QUEUE_CONNECTION: sync
|
||||||
|
volumes:
|
||||||
|
- app_storage:/app/storage
|
||||||
|
- app_cache:/app/bootstrap/cache
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
networks:
|
||||||
|
- buckets
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: mariadb:11
|
||||||
|
container_name: buckets_db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_DATABASE: buckets
|
||||||
|
MYSQL_USER: buckets
|
||||||
|
MYSQL_PASSWORD: "${DB_PASSWORD:-change_me_in_production}"
|
||||||
|
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD:-change_me_root}"
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- buckets
|
||||||
|
|
||||||
|
networks:
|
||||||
|
buckets:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
app_storage:
|
||||||
|
app_cache:
|
||||||
|
db_data:
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Generate an application key:**
|
||||||
|
```bash
|
||||||
|
# Using OpenSSL (Linux/Mac):
|
||||||
|
openssl rand -base64 32
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Create a `.env` file with your settings:**
|
||||||
|
```env
|
||||||
|
APP_KEY=base64:YOUR_GENERATED_KEY_HERE
|
||||||
|
APP_URL=https://yourdomain.com
|
||||||
|
DB_PASSWORD=your_secure_password
|
||||||
|
DB_ROOT_PASSWORD=your_secure_root_password
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Start the application:**
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
The container will automatically:
|
||||||
|
- Wait for the database to be ready
|
||||||
|
- Run database migrations
|
||||||
|
- Start serving the application
|
||||||
|
|
||||||
|
5. **Access your application:**
|
||||||
|
Open http://localhost:8000 (or your configured domain)
|
||||||
|
|
||||||
|
### Security Notes
|
||||||
|
|
||||||
|
- **Always change default passwords** in production
|
||||||
|
- Use HTTPS with a reverse proxy (nginx, Caddy, Traefik)
|
||||||
|
- Regularly backup your database volume
|
||||||
|
|
||||||
|
## Development Setup (NixOS + Podman)
|
||||||
|
|
||||||
|
> **⚠️ Warning**: This development setup is specifically configured for NixOS with rootless Podman. Users on other systems may need to adjust configurations, particularly around user namespace mappings and SELinux contexts.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- NixOS with Podman installed
|
||||||
|
- Nix development environment
|
||||||
|
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
1. **Clone and enter the development environment:**
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/yourusername/buckets-budget.git
|
||||||
|
cd buckets-budget
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Start development containers:**
|
||||||
|
When prompted, type `y` to start containers, or manually run:
|
||||||
|
```bash
|
||||||
|
dev-up
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Access the application:**
|
||||||
|
- Application: http://localhost:8100
|
||||||
|
- Vite Dev Server: http://localhost:5174
|
||||||
|
- MailHog: http://localhost:8026
|
||||||
|
- Database: localhost:3307
|
||||||
|
|
||||||
|
### Development Commands
|
||||||
|
|
||||||
|
The NixOS shell provides these helper commands:
|
||||||
|
|
||||||
|
- `dev-up` - Start development environment
|
||||||
|
- `dev-down` - Stop development environment
|
||||||
|
- `dev-rebuild` - Full rebuild (removes volumes, reinstalls dependencies)
|
||||||
|
- `dev-rebuild-quick` - Quick rebuild (preserves volumes)
|
||||||
|
- `dev-logs [service]` - Follow container logs
|
||||||
|
- `dev-shell` - Enter app container shell
|
||||||
|
- `dev-artisan [command]` - Run Artisan commands
|
||||||
|
|
||||||
|
### Troubleshooting
|
||||||
|
|
||||||
|
**Permission Issues:**
|
||||||
|
```bash
|
||||||
|
dev-fix-permissions
|
||||||
|
```
|
||||||
|
|
||||||
|
**Fresh Start:**
|
||||||
|
```bash
|
||||||
|
dev-rebuild # This will wipe everything and start fresh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Database Issues:**
|
||||||
|
```bash
|
||||||
|
dev-artisan migrate:fresh --seed
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other Development Environments
|
||||||
|
|
||||||
|
Currently, the development setup is optimized for NixOS with Podman. If you're using a different system (Ubuntu, macOS, etc.) and would like to contribute configuration files, please open an issue or PR. We're happy to add support for other development environments.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
We welcome contributions! Here's how to get started:
|
||||||
|
|
||||||
|
1. **Fork the repository** and create your feature branch (`git checkout -b feature/amazing-feature`)
|
||||||
|
2. **Make your changes** and commit them (`git commit -m 'Add amazing feature'`)
|
||||||
|
3. **Run tests** if applicable (`dev-artisan test`)
|
||||||
|
4. **Push to your branch** (`git push origin feature/amazing-feature`)
|
||||||
|
5. **Open a Pull Request** with a clear description of your changes
|
||||||
|
|
||||||
|
### Guidelines
|
||||||
|
|
||||||
|
- Follow the existing code style (Laravel conventions for PHP, React/TypeScript best practices)
|
||||||
|
- Update documentation if you're changing functionality
|
||||||
|
- Add tests for new features when possible
|
||||||
|
- Keep commits atomic and write clear commit messages
|
||||||
|
|
||||||
|
### Reporting Issues
|
||||||
|
|
||||||
|
- Use the issue tracker for bug reports and feature requests
|
||||||
|
- Include steps to reproduce for bug reports
|
||||||
|
- Check existing issues before creating a new one
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the [LICENSE](LICENSE) file for details.
|
||||||
|
|
||||||
|
**What this means:**
|
||||||
|
- ✅ You can use, modify, and distribute this software
|
||||||
|
- ✅ You can use it commercially
|
||||||
|
- ⚠️ Any modifications must be open sourced under AGPL-3.0
|
||||||
|
- ⚠️ If you run a modified version on a server, you must provide the source code to users
|
||||||
|
- ⚠️ This includes SaaS deployments - the "network use" clause applies
|
||||||
59
app/Actions/ApplyDistributionAction.php
Normal file
59
app/Actions/ApplyDistributionAction.php
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Services\Projection\PipelineAllocationService;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ApplyDistributionAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly PipelineAllocationService $pipelineAllocationService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply an income distribution to bucket balances.
|
||||||
|
*
|
||||||
|
* Re-runs the allocation algorithm server-side and updates each bucket's
|
||||||
|
* starting_amount by adding the allocated amount.
|
||||||
|
*
|
||||||
|
* @return array{allocations: Collection<int, array{bucket_id: string, bucket_name: string, bucket_type: string, allocated_amount: int}>, total_allocated: int, unallocated: int}
|
||||||
|
*/
|
||||||
|
public function execute(Scenario $scenario, int $amount): array
|
||||||
|
{
|
||||||
|
$draws = $this->pipelineAllocationService->allocateInflow($scenario, $amount);
|
||||||
|
|
||||||
|
/** @var array<int, Bucket> $bucketLookup */
|
||||||
|
$bucketLookup = $scenario->buckets->keyBy('id')->all();
|
||||||
|
|
||||||
|
DB::transaction(function () use ($draws, $bucketLookup) {
|
||||||
|
foreach ($draws as $draw) {
|
||||||
|
$bucket = $bucketLookup[$draw->bucket_id];
|
||||||
|
$bucket->increment('starting_amount', (int) $draw->amount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$allocations = $draws->map(function ($draw) use ($bucketLookup) {
|
||||||
|
$bucket = $bucketLookup[$draw->bucket_id];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'bucket_id' => $bucket->uuid,
|
||||||
|
'bucket_name' => $bucket->name,
|
||||||
|
'bucket_type' => $bucket->type->value,
|
||||||
|
'allocated_amount' => (int) $draw->amount,
|
||||||
|
];
|
||||||
|
})->values();
|
||||||
|
|
||||||
|
/** @var int $totalAllocated */
|
||||||
|
$totalAllocated = $draws->sum('amount');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'allocations' => $allocations,
|
||||||
|
'total_allocated' => $totalAllocated,
|
||||||
|
'unallocated' => $amount - $totalAllocated,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
170
app/Actions/CreateBucketAction.php
Normal file
170
app/Actions/CreateBucketAction.php
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Enums\BucketAllocationTypeEnum;
|
||||||
|
use App\Enums\BucketTypeEnum;
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class CreateBucketAction
|
||||||
|
{
|
||||||
|
public function execute(
|
||||||
|
Scenario $scenario,
|
||||||
|
string $name,
|
||||||
|
BucketAllocationTypeEnum $allocationType,
|
||||||
|
BucketTypeEnum $type = BucketTypeEnum::NEED,
|
||||||
|
?float $allocationValue = null,
|
||||||
|
?int $priority = null,
|
||||||
|
?float $bufferMultiplier = null,
|
||||||
|
): Bucket {
|
||||||
|
// Validate type + allocation type constraints
|
||||||
|
$this->validateTypeConstraints($type, $allocationType);
|
||||||
|
|
||||||
|
// Enforce one overflow bucket per scenario
|
||||||
|
if ($type === BucketTypeEnum::OVERFLOW && $scenario->buckets()->where('type', BucketTypeEnum::OVERFLOW->value)->exists()) {
|
||||||
|
throw new InvalidArgumentException('A scenario can only have one overflow bucket');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate allocation value based on type
|
||||||
|
$this->validateAllocationValue($allocationType, $allocationValue);
|
||||||
|
|
||||||
|
// Validate and normalize buffer multiplier
|
||||||
|
$bufferMultiplier = $bufferMultiplier ?? 0.0;
|
||||||
|
if ($bufferMultiplier < 0) {
|
||||||
|
throw new InvalidArgumentException('Buffer multiplier must be non-negative');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set allocation_value to null for unlimited buckets
|
||||||
|
if ($allocationType === BucketAllocationTypeEnum::UNLIMITED) {
|
||||||
|
$allocationValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buffer only applies to fixed_limit buckets
|
||||||
|
if ($allocationType !== BucketAllocationTypeEnum::FIXED_LIMIT) {
|
||||||
|
$bufferMultiplier = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($scenario, $name, $allocationType, $allocationValue, $priority, $type, $bufferMultiplier) {
|
||||||
|
// Determine priority (append to end if not specified)
|
||||||
|
if ($priority === null) {
|
||||||
|
$maxPriority = $scenario->buckets()->max('priority') ?? 0;
|
||||||
|
$priority = $maxPriority + 1;
|
||||||
|
} else {
|
||||||
|
// Validate priority is positive
|
||||||
|
if ($priority < 1) {
|
||||||
|
throw new InvalidArgumentException('Priority must be at least 1');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if priority already exists and shift others if needed
|
||||||
|
$existingBucket = $scenario->buckets()->where('priority', $priority)->first();
|
||||||
|
if ($existingBucket) {
|
||||||
|
// Shift priorities in reverse order to avoid unique constraint violations
|
||||||
|
// (SQLite checks constraints per-row during bulk updates)
|
||||||
|
$scenario->buckets()
|
||||||
|
->where('priority', '>=', $priority)
|
||||||
|
->orderByDesc('priority')
|
||||||
|
->each(function ($bucket) {
|
||||||
|
$bucket->increment('priority');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the bucket
|
||||||
|
return $scenario->buckets()->create([
|
||||||
|
'name' => $name,
|
||||||
|
'type' => $type,
|
||||||
|
'priority' => $priority,
|
||||||
|
'sort_order' => $priority, // Start with sort_order matching priority
|
||||||
|
'allocation_type' => $allocationType,
|
||||||
|
'allocation_value' => $allocationValue,
|
||||||
|
'buffer_multiplier' => $bufferMultiplier,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that bucket type and allocation type are compatible.
|
||||||
|
*/
|
||||||
|
private function validateTypeConstraints(BucketTypeEnum $type, BucketAllocationTypeEnum $allocationType): void
|
||||||
|
{
|
||||||
|
$allowedTypes = $type->getAllowedAllocationTypes();
|
||||||
|
if (! in_array($allocationType, $allowedTypes, true)) {
|
||||||
|
$allowed = implode(', ', array_map(fn ($t) => $t->value, $allowedTypes));
|
||||||
|
throw new InvalidArgumentException("Invalid allocation type for {$type->value} bucket. Allowed: {$allowed}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate allocation value based on allocation type.
|
||||||
|
*/
|
||||||
|
private function validateAllocationValue(BucketAllocationTypeEnum $allocationType, ?float $allocationValue): void
|
||||||
|
{
|
||||||
|
switch ($allocationType) {
|
||||||
|
case BucketAllocationTypeEnum::FIXED_LIMIT:
|
||||||
|
if ($allocationValue === null) {
|
||||||
|
throw new InvalidArgumentException('Fixed limit buckets require an allocation value');
|
||||||
|
}
|
||||||
|
if ($allocationValue < 0) {
|
||||||
|
throw new InvalidArgumentException('Fixed limit allocation value must be non-negative');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BucketAllocationTypeEnum::PERCENTAGE:
|
||||||
|
if ($allocationValue === null) {
|
||||||
|
throw new InvalidArgumentException('Percentage buckets require an allocation value');
|
||||||
|
}
|
||||||
|
if ($allocationValue < 1 || $allocationValue > 10000) {
|
||||||
|
throw new InvalidArgumentException('Percentage allocation value must be between 1 and 10000');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BucketAllocationTypeEnum::UNLIMITED:
|
||||||
|
// Unlimited buckets should not have an allocation value
|
||||||
|
// We'll set it to null in the main method regardless
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create default buckets for a scenario.
|
||||||
|
*/
|
||||||
|
public function createDefaultBuckets(Scenario $scenario): array
|
||||||
|
{
|
||||||
|
$buckets = [];
|
||||||
|
|
||||||
|
// Monthly Expenses - Need, fixed limit, priority 1
|
||||||
|
$buckets[] = $this->execute(
|
||||||
|
$scenario,
|
||||||
|
'Monthly Expenses',
|
||||||
|
BucketAllocationTypeEnum::FIXED_LIMIT,
|
||||||
|
BucketTypeEnum::NEED,
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
// Emergency Fund - Need, fixed limit, priority 2
|
||||||
|
$buckets[] = $this->execute(
|
||||||
|
$scenario,
|
||||||
|
'Emergency Fund',
|
||||||
|
BucketAllocationTypeEnum::FIXED_LIMIT,
|
||||||
|
BucketTypeEnum::NEED,
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
// Overflow - Overflow, unlimited, priority 3
|
||||||
|
$buckets[] = $this->execute(
|
||||||
|
$scenario,
|
||||||
|
'Overflow',
|
||||||
|
BucketAllocationTypeEnum::UNLIMITED,
|
||||||
|
BucketTypeEnum::OVERFLOW,
|
||||||
|
null,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
|
return $buckets;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Actions/CreateScenarioAction.php
Normal file
28
app/Actions/CreateScenarioAction.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
readonly class CreateScenarioAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private CreateBucketAction $createBucketAction
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function execute(array $data): Scenario
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($data) {
|
||||||
|
$scenario = Scenario::create($data);
|
||||||
|
$this->createDefaultBuckets($scenario);
|
||||||
|
|
||||||
|
return $scenario;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createDefaultBuckets(Scenario $scenario): void
|
||||||
|
{
|
||||||
|
$this->createBucketAction->createDefaultBuckets($scenario);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Actions/Fortify/CreateNewUser.php
Normal file
39
app/Actions/Fortify/CreateNewUser.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||||
|
|
||||||
|
class CreateNewUser implements CreatesNewUsers
|
||||||
|
{
|
||||||
|
use PasswordValidationRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate and create a newly registered user.
|
||||||
|
*
|
||||||
|
* @param array<string, string> $input
|
||||||
|
*/
|
||||||
|
public function create(array $input): User
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'email' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'email',
|
||||||
|
'max:255',
|
||||||
|
Rule::unique(User::class),
|
||||||
|
],
|
||||||
|
'password' => $this->passwordRules(),
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
return User::create([
|
||||||
|
'name' => $input['name'],
|
||||||
|
'email' => $input['email'],
|
||||||
|
'password' => $input['password'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Actions/Fortify/PasswordValidationRules.php
Normal file
18
app/Actions/Fortify/PasswordValidationRules.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
|
use Illuminate\Validation\Rules\Password;
|
||||||
|
|
||||||
|
trait PasswordValidationRules
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules used to validate passwords.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
protected function passwordRules(): array
|
||||||
|
{
|
||||||
|
return ['required', 'string', Password::default(), 'confirmed'];
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/Actions/Fortify/ResetUserPassword.php
Normal file
28
app/Actions/Fortify/ResetUserPassword.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Laravel\Fortify\Contracts\ResetsUserPasswords;
|
||||||
|
|
||||||
|
class ResetUserPassword implements ResetsUserPasswords
|
||||||
|
{
|
||||||
|
use PasswordValidationRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate and reset the user's forgotten password.
|
||||||
|
*
|
||||||
|
* @param array<string, string> $input
|
||||||
|
*/
|
||||||
|
public function reset(User $user, array $input): void
|
||||||
|
{
|
||||||
|
Validator::make($input, [
|
||||||
|
'password' => $this->passwordRules(),
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
$user->forceFill([
|
||||||
|
'password' => $input['password'],
|
||||||
|
])->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
app/Actions/UpdateScenarioAction.php
Normal file
15
app/Actions/UpdateScenarioAction.php
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Scenario;
|
||||||
|
|
||||||
|
readonly class UpdateScenarioAction
|
||||||
|
{
|
||||||
|
public function execute(Scenario $scenario, array $data): Scenario
|
||||||
|
{
|
||||||
|
$scenario->update($data);
|
||||||
|
|
||||||
|
return $scenario;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Enums/BucketAllocationTypeEnum.php
Normal file
33
app/Enums/BucketAllocationTypeEnum.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum BucketAllocationTypeEnum: string
|
||||||
|
{
|
||||||
|
case FIXED_LIMIT = 'fixed_limit';
|
||||||
|
case PERCENTAGE = 'percentage';
|
||||||
|
case UNLIMITED = 'unlimited';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::FIXED_LIMIT => 'Fixed Limit',
|
||||||
|
self::PERCENTAGE => 'Percentage',
|
||||||
|
self::UNLIMITED => 'Unlimited',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllocationValueRules(): array
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::FIXED_LIMIT => ['required', 'integer', 'min:0'],
|
||||||
|
self::PERCENTAGE => ['required', 'integer', 'min:1', 'max:10000'],
|
||||||
|
self::UNLIMITED => ['nullable'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Enums/BucketTypeEnum.php
Normal file
37
app/Enums/BucketTypeEnum.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum BucketTypeEnum: string
|
||||||
|
{
|
||||||
|
case NEED = 'need';
|
||||||
|
case WANT = 'want';
|
||||||
|
case OVERFLOW = 'overflow';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::NEED => 'Need',
|
||||||
|
self::WANT => 'Want',
|
||||||
|
self::OVERFLOW => 'Overflow',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get valid allocation types for this bucket type.
|
||||||
|
*
|
||||||
|
* @return BucketAllocationTypeEnum[]
|
||||||
|
*/
|
||||||
|
public function getAllowedAllocationTypes(): array
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::NEED, self::WANT => [BucketAllocationTypeEnum::FIXED_LIMIT, BucketAllocationTypeEnum::PERCENTAGE],
|
||||||
|
self::OVERFLOW => [BucketAllocationTypeEnum::UNLIMITED],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Enums/DistributionModeEnum.php
Normal file
30
app/Enums/DistributionModeEnum.php
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum DistributionModeEnum: string
|
||||||
|
{
|
||||||
|
case EVEN = 'even';
|
||||||
|
case PRIORITY = 'priority';
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::EVEN => 'Even Split',
|
||||||
|
self::PRIORITY => 'Priority Order',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::EVEN => 'Split evenly across buckets in each phase, respecting individual capacity',
|
||||||
|
self::PRIORITY => 'Fill highest-priority bucket first, then next',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
}
|
||||||
55
app/Enums/StreamFrequencyEnum.php
Normal file
55
app/Enums/StreamFrequencyEnum.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum StreamFrequencyEnum: string
|
||||||
|
{
|
||||||
|
case ONCE = 'once';
|
||||||
|
case DAILY = 'daily';
|
||||||
|
case WEEKLY = 'weekly';
|
||||||
|
case BIWEEKLY = 'biweekly';
|
||||||
|
case MONTHLY = 'monthly';
|
||||||
|
case QUARTERLY = 'quarterly';
|
||||||
|
case YEARLY = 'yearly';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::ONCE => 'One-time',
|
||||||
|
self::DAILY => 'Daily',
|
||||||
|
self::WEEKLY => 'Weekly',
|
||||||
|
self::BIWEEKLY => 'Bi-weekly',
|
||||||
|
self::MONTHLY => 'Monthly',
|
||||||
|
self::QUARTERLY => 'Quarterly',
|
||||||
|
self::YEARLY => 'Yearly',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function labels(): array
|
||||||
|
{
|
||||||
|
$labels = [];
|
||||||
|
foreach (self::cases() as $case) {
|
||||||
|
$labels[$case->value] = $case->label();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMonthlyEquivalentMultiplier(): float
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::DAILY => 30.44, // Average days per month
|
||||||
|
self::WEEKLY => 4.33, // Average weeks per month
|
||||||
|
self::BIWEEKLY => 2.17,
|
||||||
|
self::MONTHLY => 1.0,
|
||||||
|
self::QUARTERLY => 1.0 / 3.0,
|
||||||
|
self::YEARLY => 1.0 / 12.0,
|
||||||
|
self::ONCE => 0.0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Enums/StreamTypeEnum.php
Normal file
33
app/Enums/StreamTypeEnum.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum StreamTypeEnum: string
|
||||||
|
{
|
||||||
|
case INCOME = 'income';
|
||||||
|
case EXPENSE = 'expense';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::INCOME => 'Income',
|
||||||
|
self::EXPENSE => 'Expense',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function labels(): array
|
||||||
|
{
|
||||||
|
$labels = [];
|
||||||
|
|
||||||
|
foreach (self::cases() as $case) {
|
||||||
|
$labels[$case->value] = $case->label();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $labels;
|
||||||
|
}
|
||||||
|
}
|
||||||
295
app/Http/Controllers/BucketController.php
Normal file
295
app/Http/Controllers/BucketController.php
Normal file
|
|
@ -0,0 +1,295 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Actions\CreateBucketAction;
|
||||||
|
use App\Enums\BucketAllocationTypeEnum;
|
||||||
|
use App\Enums\BucketTypeEnum;
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class BucketController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$buckets = $scenario->buckets()
|
||||||
|
->orderedBySortOrder()
|
||||||
|
->get()
|
||||||
|
->map(fn ($bucket) => $this->formatBucketResponse($bucket));
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'buckets' => $buckets,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'type' => 'required|in:'.implode(',', BucketTypeEnum::values()),
|
||||||
|
'allocation_type' => 'required|in:'.implode(',', BucketAllocationTypeEnum::values()),
|
||||||
|
'allocation_value' => 'nullable|integer',
|
||||||
|
'buffer_multiplier' => 'sometimes|numeric|min:0',
|
||||||
|
'priority' => 'nullable|integer|min:1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$type = BucketTypeEnum::from($validated['type']);
|
||||||
|
$allocationType = BucketAllocationTypeEnum::from($validated['allocation_type']);
|
||||||
|
|
||||||
|
$constraintError = $this->validateBucketTypeConstraints($type, $allocationType, $scenario);
|
||||||
|
if ($constraintError) {
|
||||||
|
return $constraintError;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$createBucketAction = new CreateBucketAction;
|
||||||
|
$bucket = $createBucketAction->execute(
|
||||||
|
$scenario,
|
||||||
|
$validated['name'],
|
||||||
|
$allocationType,
|
||||||
|
$type,
|
||||||
|
$validated['allocation_value'] ?? null,
|
||||||
|
$validated['priority'] ?? null,
|
||||||
|
isset($validated['buffer_multiplier']) ? (float) $validated['buffer_multiplier'] : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'bucket' => $this->formatBucketResponse($bucket),
|
||||||
|
'message' => 'Bucket created successfully.',
|
||||||
|
], 201);
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'errors' => ['allocation_value' => [$e->getMessage()]],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, Bucket $bucket): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'name' => 'sometimes|required|string|max:255',
|
||||||
|
'type' => 'sometimes|required|in:'.implode(',', BucketTypeEnum::values()),
|
||||||
|
'allocation_type' => 'sometimes|required|in:'.implode(',', BucketAllocationTypeEnum::values()),
|
||||||
|
'allocation_value' => 'sometimes|nullable|integer',
|
||||||
|
'buffer_multiplier' => 'sometimes|numeric|min:0',
|
||||||
|
'starting_amount' => 'sometimes|integer|min:0',
|
||||||
|
'priority' => 'sometimes|nullable|integer|min:1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$type = isset($validated['type']) ? BucketTypeEnum::from($validated['type']) : $bucket->type;
|
||||||
|
$allocationType = isset($validated['allocation_type']) ? BucketAllocationTypeEnum::from($validated['allocation_type']) : $bucket->allocation_type;
|
||||||
|
|
||||||
|
// Prevent changing overflow bucket's type away from overflow
|
||||||
|
if (isset($validated['type']) && $bucket->type === BucketTypeEnum::OVERFLOW && $type !== BucketTypeEnum::OVERFLOW) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'errors' => ['type' => ['The overflow bucket\'s type cannot be changed.']],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run type/allocation constraint validation when relevant fields change
|
||||||
|
if (isset($validated['type']) || isset($validated['allocation_type'])) {
|
||||||
|
$constraintError = $this->validateBucketTypeConstraints($type, $allocationType, $bucket->scenario, $bucket);
|
||||||
|
if ($constraintError) {
|
||||||
|
return $constraintError;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set allocation_value to null for unlimited buckets
|
||||||
|
if ($allocationType === BucketAllocationTypeEnum::UNLIMITED) {
|
||||||
|
$validated['allocation_value'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buffer only applies to fixed_limit buckets — always reset on type change
|
||||||
|
if ($allocationType !== BucketAllocationTypeEnum::FIXED_LIMIT) {
|
||||||
|
$validated['buffer_multiplier'] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate allocation_value when it or allocation_type changes
|
||||||
|
if (array_key_exists('allocation_value', $validated) || isset($validated['allocation_type'])) {
|
||||||
|
$allocationValueRules = Bucket::allocationValueRules($allocationType);
|
||||||
|
$request->validate([
|
||||||
|
'allocation_value' => $allocationValueRules,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle priority change if needed
|
||||||
|
if (isset($validated['priority']) && $validated['priority'] !== $bucket->priority) {
|
||||||
|
$this->updateBucketPriority($bucket, $validated['priority']);
|
||||||
|
$validated['sort_order'] = $validated['priority'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$bucket->update($validated);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'bucket' => $this->formatBucketResponse($bucket),
|
||||||
|
'message' => 'Bucket updated successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified bucket.
|
||||||
|
*/
|
||||||
|
public function destroy(Bucket $bucket): JsonResponse
|
||||||
|
{
|
||||||
|
if ($bucket->type === BucketTypeEnum::OVERFLOW) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'The overflow bucket cannot be deleted.',
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scenarioId = $bucket->scenario_id;
|
||||||
|
$deletedPriority = $bucket->priority;
|
||||||
|
|
||||||
|
$bucket->delete();
|
||||||
|
|
||||||
|
// Shift remaining priorities down to fill the gap
|
||||||
|
$this->shiftPrioritiesDown($scenarioId, $deletedPriority);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Bucket deleted successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update bucket priorities (for drag-and-drop reordering).
|
||||||
|
*/
|
||||||
|
public function updatePriorities(Request $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'bucket_priorities' => 'required|array',
|
||||||
|
'bucket_priorities.*.id' => 'required|exists:buckets,uuid',
|
||||||
|
'bucket_priorities.*.priority' => 'required|integer|min:1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($validated['bucket_priorities'] as $bucketData) {
|
||||||
|
$bucket = Bucket::where('uuid', $bucketData['id'])->first();
|
||||||
|
if ($bucket && $bucket->scenario_id === $scenario->id) {
|
||||||
|
$bucket->update([
|
||||||
|
'priority' => $bucketData['priority'],
|
||||||
|
'sort_order' => $bucketData['priority'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Bucket priorities updated successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate bucket type constraints (type+allocation compatibility, one overflow per scenario).
|
||||||
|
*/
|
||||||
|
private function validateBucketTypeConstraints(
|
||||||
|
BucketTypeEnum $type,
|
||||||
|
BucketAllocationTypeEnum $allocationType,
|
||||||
|
Scenario $scenario,
|
||||||
|
?Bucket $excludeBucket = null
|
||||||
|
): ?JsonResponse {
|
||||||
|
$allowedTypes = $type->getAllowedAllocationTypes();
|
||||||
|
if (! in_array($allocationType, $allowedTypes, true)) {
|
||||||
|
$allowed = implode(', ', array_map(fn ($t) => $t->getLabel(), $allowedTypes));
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'errors' => ['allocation_type' => ["{$type->getLabel()} buckets only support: {$allowed}."]],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type === BucketTypeEnum::OVERFLOW) {
|
||||||
|
$query = $scenario->buckets()->where('type', BucketTypeEnum::OVERFLOW->value);
|
||||||
|
|
||||||
|
if ($excludeBucket) {
|
||||||
|
$query->where('id', '!=', $excludeBucket->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($query->exists()) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Validation failed.',
|
||||||
|
'errors' => ['type' => ['A scenario can only have one overflow bucket.']],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format bucket data for JSON response.
|
||||||
|
* All amounts in storage units (cents for currency, basis points for percentages).
|
||||||
|
* Frontend handles conversion to display units.
|
||||||
|
*/
|
||||||
|
private function formatBucketResponse(Bucket $bucket): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $bucket->uuid,
|
||||||
|
'name' => $bucket->name,
|
||||||
|
'type' => $bucket->type,
|
||||||
|
'type_label' => $bucket->type->getLabel(),
|
||||||
|
'priority' => $bucket->priority,
|
||||||
|
'sort_order' => $bucket->sort_order,
|
||||||
|
'allocation_type' => $bucket->allocation_type,
|
||||||
|
'allocation_value' => $bucket->allocation_value,
|
||||||
|
'allocation_type_label' => $bucket->getAllocationTypeLabel(),
|
||||||
|
'buffer_multiplier' => (float) $bucket->buffer_multiplier,
|
||||||
|
'effective_capacity' => $bucket->hasFiniteCapacity() ? $bucket->getEffectiveCapacity() : null,
|
||||||
|
'starting_amount' => $bucket->starting_amount,
|
||||||
|
'current_balance' => $bucket->getCurrentBalance(),
|
||||||
|
'has_available_space' => $bucket->hasAvailableSpace(),
|
||||||
|
'available_space' => $bucket->hasFiniteCapacity() ? $bucket->getAvailableSpace() : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift priorities down to fill gap after deletion.
|
||||||
|
*/
|
||||||
|
private function shiftPrioritiesDown(int $scenarioId, int $deletedPriority): void
|
||||||
|
{
|
||||||
|
Bucket::query()
|
||||||
|
->where('scenario_id', $scenarioId)
|
||||||
|
->where('priority', '>', $deletedPriority)
|
||||||
|
->decrement('priority');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a bucket's priority and adjust other buckets accordingly.
|
||||||
|
*/
|
||||||
|
private function updateBucketPriority(Bucket $bucket, int $newPriority): void
|
||||||
|
{
|
||||||
|
$oldPriority = $bucket->priority;
|
||||||
|
$scenario = $bucket->scenario;
|
||||||
|
|
||||||
|
if ($newPriority === $oldPriority) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use database transaction to handle constraint conflicts
|
||||||
|
DB::transaction(function () use ($bucket, $scenario, $oldPriority, $newPriority) {
|
||||||
|
// Temporarily set the moving bucket to a high priority to avoid conflicts
|
||||||
|
$tempPriority = $scenario->buckets()->max('priority') + 100;
|
||||||
|
$bucket->update(['priority' => $tempPriority]);
|
||||||
|
|
||||||
|
if ($newPriority < $oldPriority) {
|
||||||
|
// Moving up - shift others down
|
||||||
|
$scenario->buckets()
|
||||||
|
->where('id', '!=', $bucket->id)
|
||||||
|
->whereBetween('priority', [$newPriority, $oldPriority - 1])
|
||||||
|
->increment('priority');
|
||||||
|
} else {
|
||||||
|
// Moving down - shift others up
|
||||||
|
$scenario->buckets()
|
||||||
|
->where('id', '!=', $bucket->id)
|
||||||
|
->whereBetween('priority', [$oldPriority + 1, $newPriority])
|
||||||
|
->decrement('priority');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, set the bucket to its new priority
|
||||||
|
$bucket->update(['priority' => $newPriority]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
abstract class Controller
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
87
app/Http/Controllers/ProjectionController.php
Normal file
87
app/Http/Controllers/ProjectionController.php
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Actions\ApplyDistributionAction;
|
||||||
|
use App\Http\Requests\CalculateProjectionRequest;
|
||||||
|
use App\Http\Requests\PreviewAllocationRequest;
|
||||||
|
use App\Http\Resources\ProjectionResource;
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Services\Projection\PipelineAllocationService;
|
||||||
|
use App\Services\Projection\ProjectionGeneratorService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class ProjectionController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ProjectionGeneratorService $projectionGeneratorService,
|
||||||
|
private readonly PipelineAllocationService $pipelineAllocationService,
|
||||||
|
private readonly ApplyDistributionAction $applyDistributionAction,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function calculate(CalculateProjectionRequest $request, Scenario $scenario): ProjectionResource
|
||||||
|
{
|
||||||
|
$startDate = Carbon::parse($request->input('start_date'));
|
||||||
|
$endDate = Carbon::parse($request->input('end_date'));
|
||||||
|
|
||||||
|
$projections = $this->projectionGeneratorService->generateProjections(
|
||||||
|
$scenario,
|
||||||
|
$startDate,
|
||||||
|
$endDate
|
||||||
|
);
|
||||||
|
|
||||||
|
return new ProjectionResource($projections);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All amounts in cents. Frontend handles conversion to display units.
|
||||||
|
*/
|
||||||
|
public function preview(PreviewAllocationRequest $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$amountInCents = (int) $request->input('amount');
|
||||||
|
|
||||||
|
$draws = $this->pipelineAllocationService->allocateInflow($scenario, $amountInCents);
|
||||||
|
|
||||||
|
/** @var array<int, Bucket> $bucketLookup */
|
||||||
|
$bucketLookup = $scenario->buckets->keyBy('id')->all();
|
||||||
|
|
||||||
|
$allocations = $draws->map(function ($draw) use ($bucketLookup) {
|
||||||
|
$bucket = $bucketLookup[$draw->bucket_id];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'bucket_id' => $bucket->uuid,
|
||||||
|
'bucket_name' => $bucket->name,
|
||||||
|
'bucket_type' => $bucket->type->value,
|
||||||
|
'allocated_amount' => $draw->amount,
|
||||||
|
'remaining_capacity' => $bucket->hasFiniteCapacity()
|
||||||
|
? max(0, $bucket->getEffectiveCapacity() - $draw->amount)
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
})->values();
|
||||||
|
|
||||||
|
$totalAllocated = $draws->sum('amount');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'allocations' => $allocations,
|
||||||
|
'total_allocated' => $totalAllocated,
|
||||||
|
'unallocated' => $amountInCents - $totalAllocated,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply an income distribution to bucket balances.
|
||||||
|
*
|
||||||
|
* Re-runs the allocation server-side and updates starting_amount for each bucket.
|
||||||
|
* All amounts in cents.
|
||||||
|
*/
|
||||||
|
public function apply(PreviewAllocationRequest $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$amountInCents = (int) $request->input('amount');
|
||||||
|
|
||||||
|
$result = $this->applyDistributionAction->execute($scenario, $amountInCents);
|
||||||
|
|
||||||
|
return response()->json($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Controllers/ScenarioController.php
Normal file
38
app/Http/Controllers/ScenarioController.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Actions\UpdateScenarioAction;
|
||||||
|
use App\Http\Requests\UpdateScenarioRequest;
|
||||||
|
use App\Http\Resources\BucketResource;
|
||||||
|
use App\Http\Resources\ScenarioResource;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
|
||||||
|
class ScenarioController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly UpdateScenarioAction $updateScenarioAction,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function show(Scenario $scenario): Response
|
||||||
|
{
|
||||||
|
$scenario->load(['buckets' => function ($query) {
|
||||||
|
$query->orderedBySortOrder();
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return Inertia::render('Scenarios/Show', [
|
||||||
|
'scenario' => ScenarioResource::make($scenario)->resolve(),
|
||||||
|
'buckets' => BucketResource::collection($scenario->buckets),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateScenarioRequest $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$this->updateScenarioAction->execute($scenario, $request->validated());
|
||||||
|
|
||||||
|
return response()->json(['success' => true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Controllers/Settings/PasswordController.php
Normal file
38
app/Http/Controllers/Settings/PasswordController.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Settings;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rules\Password;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
|
||||||
|
class PasswordController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show the user's password settings page.
|
||||||
|
*/
|
||||||
|
public function edit(): Response
|
||||||
|
{
|
||||||
|
return Inertia::render('settings/password');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the user's password.
|
||||||
|
*/
|
||||||
|
public function update(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'current_password' => ['required', 'current_password'],
|
||||||
|
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$request->user()->update([
|
||||||
|
'password' => $validated['password'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Http/Controllers/Settings/ProfileController.php
Normal file
63
app/Http/Controllers/Settings/ProfileController.php
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Settings;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Settings\ProfileUpdateRequest;
|
||||||
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
|
||||||
|
class ProfileController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show the user's profile settings page.
|
||||||
|
*/
|
||||||
|
public function edit(Request $request): Response
|
||||||
|
{
|
||||||
|
return Inertia::render('settings/profile', [
|
||||||
|
'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
|
||||||
|
'status' => $request->session()->get('status'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the user's profile settings.
|
||||||
|
*/
|
||||||
|
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$request->user()->fill($request->validated());
|
||||||
|
|
||||||
|
if ($request->user()->isDirty('email')) {
|
||||||
|
$request->user()->email_verified_at = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request->user()->save();
|
||||||
|
|
||||||
|
return to_route('profile.edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the user's account.
|
||||||
|
*/
|
||||||
|
public function destroy(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'password' => ['required', 'current_password'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
Auth::logout();
|
||||||
|
|
||||||
|
$user->delete();
|
||||||
|
|
||||||
|
$request->session()->invalidate();
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Settings;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Settings\TwoFactorAuthenticationRequest;
|
||||||
|
use Illuminate\Routing\Controllers\HasMiddleware;
|
||||||
|
use Illuminate\Routing\Controllers\Middleware;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
use Laravel\Fortify\Features;
|
||||||
|
|
||||||
|
class TwoFactorAuthenticationController extends Controller implements HasMiddleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the middleware that should be assigned to the controller.
|
||||||
|
*/
|
||||||
|
public static function middleware(): array
|
||||||
|
{
|
||||||
|
return Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
|
||||||
|
? [new Middleware('password.confirm', only: ['show'])]
|
||||||
|
: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the user's two-factor authentication settings page.
|
||||||
|
*/
|
||||||
|
public function show(TwoFactorAuthenticationRequest $request): Response
|
||||||
|
{
|
||||||
|
$request->ensureStateIsValid();
|
||||||
|
|
||||||
|
return Inertia::render('settings/two-factor', [
|
||||||
|
'twoFactorEnabled' => $request->user()->hasEnabledTwoFactorAuthentication(),
|
||||||
|
'requiresConfirmation' => Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
app/Http/Controllers/StreamController.php
Normal file
69
app/Http/Controllers/StreamController.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\StoreStreamRequest;
|
||||||
|
use App\Http\Requests\UpdateStreamRequest;
|
||||||
|
use App\Http\Resources\StreamResource;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Models\Stream;
|
||||||
|
use App\Repositories\StreamRepository;
|
||||||
|
use App\Services\Streams\StatsService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class StreamController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly StreamRepository $streamRepository,
|
||||||
|
private readonly StatsService $statsService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function index(Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$streams = $this->streamRepository->getForScenario($scenario);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'streams' => StreamResource::collection($streams),
|
||||||
|
'stats' => $this->statsService->getSummaryStats($scenario),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreStreamRequest $request, Scenario $scenario): JsonResponse
|
||||||
|
{
|
||||||
|
$stream = $this->streamRepository->create($scenario, $request->validated());
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'stream' => new StreamResource($stream),
|
||||||
|
'message' => 'Stream created successfully.',
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateStreamRequest $request, Stream $stream): JsonResponse
|
||||||
|
{
|
||||||
|
$stream = $this->streamRepository->update($stream, $request->validated());
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'stream' => new StreamResource($stream),
|
||||||
|
'message' => 'Stream updated successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Stream $stream): JsonResponse
|
||||||
|
{
|
||||||
|
$this->streamRepository->delete($stream);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Stream deleted successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggle(Stream $stream): JsonResponse
|
||||||
|
{
|
||||||
|
$stream = $this->streamRepository->toggleActive($stream);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'stream' => new StreamResource($stream),
|
||||||
|
'message' => $stream->is_active ? 'Stream activated.' : 'Stream deactivated.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Http/Middleware/HandleAppearance.php
Normal file
23
app/Http/Middleware/HandleAppearance.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class HandleAppearance
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
View::share('appearance', $request->cookie('appearance') ?? 'system');
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Http/Middleware/HandleInertiaRequests.php
Normal file
54
app/Http/Middleware/HandleInertiaRequests.php
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Http\Resources\ScenarioResource;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Illuminate\Foundation\Inspiring;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Inertia\Middleware;
|
||||||
|
|
||||||
|
class HandleInertiaRequests extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The root template that's loaded on the first page visit.
|
||||||
|
*
|
||||||
|
* @see https://inertiajs.com/server-side-setup#root-template
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $rootView = 'app';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the current asset version.
|
||||||
|
*
|
||||||
|
* @see https://inertiajs.com/asset-versioning
|
||||||
|
*/
|
||||||
|
public function version(Request $request): ?string
|
||||||
|
{
|
||||||
|
return parent::version($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the props that are shared by default.
|
||||||
|
*
|
||||||
|
* @see https://inertiajs.com/shared-data
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function share(Request $request): array
|
||||||
|
{
|
||||||
|
[$message, $author] = str(Inspiring::quotes()->random())->explode('-');
|
||||||
|
|
||||||
|
return [
|
||||||
|
...parent::share($request),
|
||||||
|
'name' => config('app.name'),
|
||||||
|
'quote' => ['message' => trim($message), 'author' => trim($author)],
|
||||||
|
'auth' => [
|
||||||
|
'user' => $request->user(),
|
||||||
|
],
|
||||||
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||||
|
'scenario' => fn () => ($scenario = Scenario::first()) ? ScenarioResource::make($scenario)->resolve() : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Http/Requests/CalculateProjectionRequest.php
Normal file
29
app/Http/Requests/CalculateProjectionRequest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CalculateProjectionRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start_date' => ['required', 'date', 'before_or_equal:end_date'],
|
||||||
|
'end_date' => ['required', 'date', 'after_or_equal:start_date'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start_date.before_or_equal' => 'Start date must be before or equal to end date.',
|
||||||
|
'end_date.after_or_equal' => 'End date must be after or equal to start date.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
20
app/Http/Requests/PreviewAllocationRequest.php
Normal file
20
app/Http/Requests/PreviewAllocationRequest.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class PreviewAllocationRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'amount' => ['required', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Http/Requests/Settings/ProfileUpdateRequest.php
Normal file
32
app/Http/Requests/Settings/ProfileUpdateRequest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Settings;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class ProfileUpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
|
||||||
|
'email' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'lowercase',
|
||||||
|
'email',
|
||||||
|
'max:255',
|
||||||
|
Rule::unique(User::class)->ignore($this->user()->id),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Settings;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Laravel\Fortify\Features;
|
||||||
|
use Laravel\Fortify\InteractsWithTwoFactorState;
|
||||||
|
|
||||||
|
class TwoFactorAuthenticationRequest extends FormRequest
|
||||||
|
{
|
||||||
|
use InteractsWithTwoFactorState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return Features::enabled(Features::twoFactorAuthentication());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
107
app/Http/Requests/StoreStreamRequest.php
Normal file
107
app/Http/Requests/StoreStreamRequest.php
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Models\Stream;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class StoreStreamRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
// In production, check if user owns the scenario
|
||||||
|
// For now, allow all requests
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'type' => ['required', Rule::in([Stream::TYPE_INCOME, Stream::TYPE_EXPENSE])],
|
||||||
|
'amount' => ['required', 'numeric', 'min:0.01', 'max:999999999.99'],
|
||||||
|
'frequency' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([
|
||||||
|
Stream::FREQUENCY_ONCE,
|
||||||
|
Stream::FREQUENCY_WEEKLY,
|
||||||
|
Stream::FREQUENCY_BIWEEKLY,
|
||||||
|
Stream::FREQUENCY_MONTHLY,
|
||||||
|
Stream::FREQUENCY_QUARTERLY,
|
||||||
|
Stream::FREQUENCY_YEARLY,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
'start_date' => ['required', 'date', 'date_format:Y-m-d'],
|
||||||
|
'end_date' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_date'],
|
||||||
|
'bucket_id' => ['nullable', 'exists:buckets,uuid'],
|
||||||
|
'description' => ['nullable', 'string', 'max:1000'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type.in' => 'The type must be either income or expense.',
|
||||||
|
'frequency.in' => 'Invalid frequency selected.',
|
||||||
|
'amount.min' => 'The amount must be greater than zero.',
|
||||||
|
'amount.max' => 'The amount is too large.',
|
||||||
|
'end_date.after_or_equal' => 'The end date must be after or equal to the start date.',
|
||||||
|
'bucket_id.exists' => 'The selected bucket does not exist.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withValidator($validator): void
|
||||||
|
{
|
||||||
|
$validator->after(function ($validator) {
|
||||||
|
// Validate that the bucket belongs to the scenario
|
||||||
|
if ($this->bucket_id) {
|
||||||
|
/** @var Scenario $scenario */
|
||||||
|
$scenario = $this->route('scenario');
|
||||||
|
|
||||||
|
$bucketBelongsToScenario = $scenario->buckets()
|
||||||
|
->where('uuid', $this->bucket_id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (! $bucketBelongsToScenario) {
|
||||||
|
$validator->errors()->add('bucket_id', 'The selected bucket does not belong to this scenario.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For expense streams, bucket is required
|
||||||
|
if ($this->type === Stream::TYPE_EXPENSE && ! $this->bucket_id) {
|
||||||
|
$validator->errors()->add('bucket_id', 'A bucket must be selected for expense streams.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
// Ensure dates are in the correct format
|
||||||
|
if ($this->has('start_date') && ! empty($this->start_date)) {
|
||||||
|
$this->merge([
|
||||||
|
'start_date' => date('Y-m-d', strtotime($this->start_date)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->has('end_date') && ! empty($this->end_date)) {
|
||||||
|
$this->merge([
|
||||||
|
'end_date' => date('Y-m-d', strtotime($this->end_date)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert amount to float
|
||||||
|
if ($this->has('amount')) {
|
||||||
|
$this->merge([
|
||||||
|
'amount' => (float) $this->amount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Http/Requests/UpdateScenarioRequest.php
Normal file
50
app/Http/Requests/UpdateScenarioRequest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateScenarioRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['sometimes', 'string', 'max:255', 'min:1'],
|
||||||
|
'description' => ['sometimes', 'nullable', 'string', 'max:1000'],
|
||||||
|
'distribution_mode' => ['sometimes', 'string', Rule::in(DistributionModeEnum::values())],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name.min' => 'The scenario name must be at least 1 character.',
|
||||||
|
'name.max' => 'The scenario name cannot exceed 255 characters.',
|
||||||
|
'description.max' => 'The description cannot exceed 1000 characters.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
// Trim the name
|
||||||
|
if ($this->has('name')) {
|
||||||
|
$this->merge([
|
||||||
|
'name' => trim($this->name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim the description
|
||||||
|
if ($this->has('description')) {
|
||||||
|
$this->merge([
|
||||||
|
'description' => $this->description ? trim($this->description) : null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
110
app/Http/Requests/UpdateStreamRequest.php
Normal file
110
app/Http/Requests/UpdateStreamRequest.php
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Stream;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateStreamRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
// In production, check if user owns the stream/scenario
|
||||||
|
// For now, allow all requests
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'type' => ['required', Rule::in([Stream::TYPE_INCOME, Stream::TYPE_EXPENSE])],
|
||||||
|
'amount' => ['required', 'numeric', 'min:0.01', 'max:999999999.99'],
|
||||||
|
'frequency' => [
|
||||||
|
'required',
|
||||||
|
Rule::in([
|
||||||
|
Stream::FREQUENCY_ONCE,
|
||||||
|
Stream::FREQUENCY_WEEKLY,
|
||||||
|
Stream::FREQUENCY_BIWEEKLY,
|
||||||
|
Stream::FREQUENCY_MONTHLY,
|
||||||
|
Stream::FREQUENCY_QUARTERLY,
|
||||||
|
Stream::FREQUENCY_YEARLY,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
'start_date' => ['required', 'date', 'date_format:Y-m-d'],
|
||||||
|
'end_date' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_date'],
|
||||||
|
'bucket_id' => ['nullable', 'exists:buckets,uuid'],
|
||||||
|
'description' => ['nullable', 'string', 'max:1000'],
|
||||||
|
'is_active' => ['boolean'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type.in' => 'The type must be either income or expense.',
|
||||||
|
'frequency.in' => 'Invalid frequency selected.',
|
||||||
|
'amount.min' => 'The amount must be greater than zero.',
|
||||||
|
'amount.max' => 'The amount is too large.',
|
||||||
|
'end_date.after_or_equal' => 'The end date must be after or equal to the start date.',
|
||||||
|
'bucket_id.exists' => 'The selected bucket does not exist.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withValidator($validator): void
|
||||||
|
{
|
||||||
|
$validator->after(function ($validator) {
|
||||||
|
/** @var Stream $stream */
|
||||||
|
$stream = $this->route('stream');
|
||||||
|
|
||||||
|
// Validate that the bucket belongs to the stream's scenario
|
||||||
|
if ($this->bucket_id) {
|
||||||
|
$bucketBelongsToScenario = $stream->scenario->buckets()
|
||||||
|
->where('uuid', $this->bucket_id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (! $bucketBelongsToScenario) {
|
||||||
|
$validator->errors()->add('bucket_id', 'The selected bucket does not belong to this scenario.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For expense streams, bucket is required
|
||||||
|
if ($this->type === Stream::TYPE_EXPENSE && ! $this->bucket_id) {
|
||||||
|
$validator->errors()->add('bucket_id', 'A bucket must be selected for expense streams.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
// Ensure dates are in the correct format
|
||||||
|
if ($this->has('start_date') && ! empty($this->start_date)) {
|
||||||
|
$this->merge([
|
||||||
|
'start_date' => date('Y-m-d', strtotime($this->start_date)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->has('end_date') && ! empty($this->end_date)) {
|
||||||
|
$this->merge([
|
||||||
|
'end_date' => date('Y-m-d', strtotime($this->end_date)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert amount to float
|
||||||
|
if ($this->has('amount')) {
|
||||||
|
$this->merge([
|
||||||
|
'amount' => (float) $this->amount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default is_active to current value if not provided
|
||||||
|
if (! $this->has('is_active')) {
|
||||||
|
/** @var Stream $stream */
|
||||||
|
$stream = $this->route('stream');
|
||||||
|
$this->merge([
|
||||||
|
'is_active' => $stream->is_active,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Resources/BucketResource.php
Normal file
34
app/Http/Resources/BucketResource.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class BucketResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* All amounts in storage units (cents for currency, basis points for percentages).
|
||||||
|
* Frontend handles conversion to display units.
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'name' => $this->name,
|
||||||
|
'type' => $this->type,
|
||||||
|
'type_label' => $this->type->getLabel(),
|
||||||
|
'priority' => $this->priority,
|
||||||
|
'sort_order' => $this->sort_order,
|
||||||
|
'allocation_type' => $this->allocation_type,
|
||||||
|
'allocation_value' => $this->allocation_value,
|
||||||
|
'allocation_type_label' => $this->getAllocationTypeLabel(),
|
||||||
|
'buffer_multiplier' => (float) $this->buffer_multiplier,
|
||||||
|
'effective_capacity' => $this->hasFiniteCapacity() ? $this->getEffectiveCapacity() : null,
|
||||||
|
'starting_amount' => $this->starting_amount,
|
||||||
|
'current_balance' => $this->getCurrentBalance(),
|
||||||
|
'has_available_space' => $this->hasAvailableSpace(),
|
||||||
|
'available_space' => $this->hasFiniteCapacity() ? $this->getAvailableSpace() : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Http/Resources/DrawResource.php
Normal file
23
app/Http/Resources/DrawResource.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class DrawResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'bucket_id' => $this->bucket?->uuid,
|
||||||
|
'amount' => $this->amount_currency,
|
||||||
|
'formatted_amount' => $this->formatted_amount,
|
||||||
|
'date' => $this->date->format('Y-m-d'),
|
||||||
|
'description' => $this->description,
|
||||||
|
'is_projected' => $this->is_projected,
|
||||||
|
'priority_order' => $this->priority_order ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Resources/InflowResource.php
Normal file
22
app/Http/Resources/InflowResource.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class InflowResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'stream_id' => $this->stream?->uuid,
|
||||||
|
'amount' => $this->amount_currency,
|
||||||
|
'formatted_amount' => $this->formatted_amount,
|
||||||
|
'date' => $this->date->format('Y-m-d'),
|
||||||
|
'description' => $this->description,
|
||||||
|
'is_projected' => $this->is_projected,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Http/Resources/OutflowResource.php
Normal file
23
app/Http/Resources/OutflowResource.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class OutflowResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'stream_id' => $this->stream?->uuid,
|
||||||
|
'bucket_id' => $this->bucket?->uuid,
|
||||||
|
'amount' => $this->amount_currency,
|
||||||
|
'formatted_amount' => $this->formatted_amount,
|
||||||
|
'date' => $this->date->format('Y-m-d'),
|
||||||
|
'description' => $this->description,
|
||||||
|
'is_projected' => $this->is_projected,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Http/Resources/ProjectionResource.php
Normal file
24
app/Http/Resources/ProjectionResource.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ProjectionResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'inflows' => InflowResource::collection($this->resource['inflows']),
|
||||||
|
'outflows' => OutflowResource::collection($this->resource['outflows']),
|
||||||
|
'draws' => DrawResource::collection($this->resource['draws']),
|
||||||
|
'summary' => [
|
||||||
|
'total_inflow' => $this->resource['inflows']->sum('amount_currency'),
|
||||||
|
'total_outflow' => $this->resource['outflows']->sum('amount_currency'),
|
||||||
|
'total_allocated' => $this->resource['draws']->sum('amount_currency'),
|
||||||
|
'net_cashflow' => $this->resource['inflows']->sum('amount_currency') - $this->resource['outflows']->sum('amount_currency'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Resources/ScenarioResource.php
Normal file
22
app/Http/Resources/ScenarioResource.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ScenarioResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'name' => $this->name,
|
||||||
|
'description' => $this->description,
|
||||||
|
'distribution_mode' => $this->distribution_mode->value,
|
||||||
|
'distribution_mode_label' => $this->distribution_mode->getLabel(),
|
||||||
|
'created_at' => $this->created_at,
|
||||||
|
'updated_at' => $this->updated_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Http/Resources/StreamResource.php
Normal file
29
app/Http/Resources/StreamResource.php
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class StreamResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->uuid,
|
||||||
|
'name' => $this->name,
|
||||||
|
'type' => $this->type,
|
||||||
|
'type_label' => $this->getTypeLabel(),
|
||||||
|
'amount' => $this->amount,
|
||||||
|
'frequency' => $this->frequency,
|
||||||
|
'frequency_label' => $this->getFrequencyLabel(),
|
||||||
|
'start_date' => $this->start_date->format('Y-m-d'),
|
||||||
|
'end_date' => $this->end_date?->format('Y-m-d'),
|
||||||
|
'bucket_id' => $this->bucket?->uuid,
|
||||||
|
'bucket_name' => $this->bucket?->name,
|
||||||
|
'description' => $this->description,
|
||||||
|
'is_active' => $this->is_active,
|
||||||
|
'monthly_equivalent' => $this->getMonthlyEquivalent(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
167
app/Models/Bucket.php
Normal file
167
app/Models/Bucket.php
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\BucketAllocationTypeEnum;
|
||||||
|
use App\Enums\BucketTypeEnum;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Database\Factories\BucketFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $uuid
|
||||||
|
* @property int $scenario_id
|
||||||
|
* @property BucketTypeEnum $type
|
||||||
|
* @property Scenario $scenario
|
||||||
|
* @property string $name
|
||||||
|
* @property int $priority
|
||||||
|
* @property BucketAllocationTypeEnum $allocation_type
|
||||||
|
* @property int $starting_amount
|
||||||
|
* @property int|null $allocation_value
|
||||||
|
* @property float $buffer_multiplier
|
||||||
|
*
|
||||||
|
* @method static BucketFactory factory()
|
||||||
|
*/
|
||||||
|
class Bucket extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<BucketFactory> */
|
||||||
|
use HasFactory, HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'scenario_id',
|
||||||
|
'name',
|
||||||
|
'type',
|
||||||
|
'priority',
|
||||||
|
'sort_order',
|
||||||
|
'allocation_type',
|
||||||
|
'allocation_value',
|
||||||
|
'buffer_multiplier',
|
||||||
|
'starting_amount',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'type' => BucketTypeEnum::class,
|
||||||
|
'priority' => 'integer',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
'allocation_value' => 'integer',
|
||||||
|
'buffer_multiplier' => 'decimal:2',
|
||||||
|
'starting_amount' => 'integer',
|
||||||
|
'allocation_type' => BucketAllocationTypeEnum::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
public function scenario(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Scenario::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the draws for the bucket.
|
||||||
|
*/
|
||||||
|
public function draws(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Draw::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the outflows for the bucket.
|
||||||
|
*/
|
||||||
|
public function outflows(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Outflow::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to get buckets ordered by priority.
|
||||||
|
*/
|
||||||
|
public function scopeOrderedByPriority($query)
|
||||||
|
{
|
||||||
|
return $query->orderBy('priority');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to get buckets ordered by sort order for UI display.
|
||||||
|
*/
|
||||||
|
public function scopeOrderedBySortOrder($query)
|
||||||
|
{
|
||||||
|
return $query->orderBy('sort_order')->orderBy('priority');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current balance of the bucket.
|
||||||
|
* Calculates starting amount plus total draws (money allocated to bucket) minus total outflows (money spent from bucket).
|
||||||
|
*/
|
||||||
|
public function getCurrentBalance(): int
|
||||||
|
{
|
||||||
|
$totalDraws = $this->draws()->sum('amount');
|
||||||
|
$totalOutflows = $this->outflows()->sum('amount');
|
||||||
|
|
||||||
|
return $this->starting_amount + $totalDraws - $totalOutflows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the effective capacity including buffer, in cents.
|
||||||
|
* Formula: allocation_value * (1 + buffer_multiplier)
|
||||||
|
*/
|
||||||
|
public function getEffectiveCapacity(): int
|
||||||
|
{
|
||||||
|
if ($this->allocation_type !== BucketAllocationTypeEnum::FIXED_LIMIT) {
|
||||||
|
return PHP_INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
$base = $this->allocation_value ?? 0;
|
||||||
|
|
||||||
|
return (int) round($base * (1 + (float) $this->buffer_multiplier));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the bucket can accept more money (for fixed_limit buckets).
|
||||||
|
*/
|
||||||
|
public function hasAvailableSpace(): bool
|
||||||
|
{
|
||||||
|
if ($this->allocation_type !== BucketAllocationTypeEnum::FIXED_LIMIT) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getCurrentBalance() < $this->getEffectiveCapacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get available space in cents for fixed_limit buckets.
|
||||||
|
*/
|
||||||
|
public function getAvailableSpace(): int
|
||||||
|
{
|
||||||
|
if ($this->allocation_type !== BucketAllocationTypeEnum::FIXED_LIMIT) {
|
||||||
|
return PHP_INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max(0, $this->getEffectiveCapacity() - $this->getCurrentBalance());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this bucket has a finite capacity (fixed_limit only).
|
||||||
|
*/
|
||||||
|
public function hasFiniteCapacity(): bool
|
||||||
|
{
|
||||||
|
return $this->allocation_type === BucketAllocationTypeEnum::FIXED_LIMIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get display label for allocation type.
|
||||||
|
*/
|
||||||
|
public function getAllocationTypeLabel(): string
|
||||||
|
{
|
||||||
|
return $this->allocation_type->getLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get allocation value validation rules based on type.
|
||||||
|
*/
|
||||||
|
public static function allocationValueRules(BucketAllocationTypeEnum $allocationType): array
|
||||||
|
{
|
||||||
|
return $allocationType->getAllocationValueRules();
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Models/Draw.php
Normal file
58
app/Models/Draw.php
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Traits\HasAmount;
|
||||||
|
use App\Models\Traits\HasProjectionStatus;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Database\Factories\DrawFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $uuid
|
||||||
|
* @property Bucket $bucket
|
||||||
|
* @property int $priority_order
|
||||||
|
* @property float $amount
|
||||||
|
* @property Carbon $date
|
||||||
|
* @property string $description
|
||||||
|
* @property bool $is_projected
|
||||||
|
*
|
||||||
|
* @method static create(array $array)
|
||||||
|
*/
|
||||||
|
class Draw extends Model
|
||||||
|
{
|
||||||
|
use HasAmount;
|
||||||
|
|
||||||
|
/** @use HasFactory<DrawFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
use HasProjectionStatus;
|
||||||
|
use HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'bucket_id',
|
||||||
|
'amount',
|
||||||
|
'date',
|
||||||
|
'description',
|
||||||
|
'is_projected',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'amount' => 'integer',
|
||||||
|
'date' => 'date',
|
||||||
|
'is_projected' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function bucket(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Bucket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scenario(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->bucket->scenario();
|
||||||
|
}
|
||||||
|
}
|
||||||
51
app/Models/Inflow.php
Normal file
51
app/Models/Inflow.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Traits\HasAmount;
|
||||||
|
use App\Models\Traits\HasProjectionStatus;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $uuid
|
||||||
|
* @property int $stream_id
|
||||||
|
* @property Stream $stream
|
||||||
|
* @property float $amount
|
||||||
|
* @property Carbon $date
|
||||||
|
* @property string $description
|
||||||
|
* @property bool $is_projected
|
||||||
|
*/
|
||||||
|
class Inflow extends Model
|
||||||
|
{
|
||||||
|
use HasAmount;
|
||||||
|
use HasProjectionStatus;
|
||||||
|
use HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'stream_id',
|
||||||
|
'amount',
|
||||||
|
'date',
|
||||||
|
'description',
|
||||||
|
'is_projected',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'amount' => 'integer',
|
||||||
|
'date' => 'date',
|
||||||
|
'is_projected' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function stream(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Stream::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scenario(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->stream->scenario();
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Models/Outflow.php
Normal file
65
app/Models/Outflow.php
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Traits\HasAmount;
|
||||||
|
use App\Models\Traits\HasProjectionStatus;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Database\Factories\OutflowFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $uuid
|
||||||
|
* @property int $stream_id
|
||||||
|
* @property Stream $stream
|
||||||
|
* @property int $amount
|
||||||
|
* @property Carbon $date
|
||||||
|
* @property string $description
|
||||||
|
* @property bool $is_projected
|
||||||
|
*
|
||||||
|
* @method static create(array $array)
|
||||||
|
*/
|
||||||
|
class Outflow extends Model
|
||||||
|
{
|
||||||
|
use HasAmount;
|
||||||
|
|
||||||
|
/** @use HasFactory<OutflowFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
use HasProjectionStatus;
|
||||||
|
use HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'stream_id',
|
||||||
|
'bucket_id',
|
||||||
|
'amount',
|
||||||
|
'date',
|
||||||
|
'description',
|
||||||
|
'is_projected',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'amount' => 'integer',
|
||||||
|
'date' => 'date',
|
||||||
|
'is_projected' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function stream(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Stream::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bucket(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Bucket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scenario(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->stream->scenario();
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Models/Scenario.php
Normal file
58
app/Models/Scenario.php
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Database\Factories\ScenarioFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $uuid
|
||||||
|
* @property DistributionModeEnum $distribution_mode
|
||||||
|
* @property Collection<Bucket> $buckets
|
||||||
|
*
|
||||||
|
* @method static create(array $data)
|
||||||
|
*/
|
||||||
|
class Scenario extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<ScenarioFactory> */
|
||||||
|
use HasFactory, HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'distribution_mode',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'distribution_mode' => DistributionModeEnum::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buckets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Bucket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function streams(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Stream::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inflows(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Inflow::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function outflows(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Outflow::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Models/Stream.php
Normal file
91
app/Models/Stream.php
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\StreamFrequencyEnum;
|
||||||
|
use App\Enums\StreamTypeEnum;
|
||||||
|
use App\Models\Traits\HasAmount;
|
||||||
|
use App\Models\Traits\HasUuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $amount
|
||||||
|
* @property string $uuid
|
||||||
|
* @property StreamFrequencyEnum $frequency
|
||||||
|
* @property Carbon $start_date
|
||||||
|
*/
|
||||||
|
class Stream extends Model
|
||||||
|
{
|
||||||
|
use HasAmount, HasFactory, HasUuid;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'scenario_id',
|
||||||
|
'name',
|
||||||
|
'type',
|
||||||
|
'amount',
|
||||||
|
'frequency',
|
||||||
|
'start_date',
|
||||||
|
'end_date',
|
||||||
|
'bucket_id',
|
||||||
|
'description',
|
||||||
|
'is_active',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'type' => StreamTypeEnum::class,
|
||||||
|
'frequency' => StreamFrequencyEnum::class,
|
||||||
|
'amount' => 'integer',
|
||||||
|
'start_date' => 'date',
|
||||||
|
'end_date' => 'date',
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function scenario(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Scenario::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bucket(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Bucket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTypes(): array
|
||||||
|
{
|
||||||
|
return StreamTypeEnum::labels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFrequencies(): array
|
||||||
|
{
|
||||||
|
return StreamFrequencyEnum::labels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTypeLabel(): string
|
||||||
|
{
|
||||||
|
return $this->type?->label() ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFrequencyLabel(): string
|
||||||
|
{
|
||||||
|
return $this->frequency?->label() ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMonthlyEquivalent(): float
|
||||||
|
{
|
||||||
|
if (! $this->frequency) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->amount * $this->frequency->getMonthlyEquivalentMultiplier();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SCOPES */
|
||||||
|
|
||||||
|
public function scopeByType($query, string $type)
|
||||||
|
{
|
||||||
|
return $query->where('type', $type);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Models/Traits/HasAmount.php
Normal file
31
app/Models/Traits/HasAmount.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Traits;
|
||||||
|
|
||||||
|
trait HasAmount
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get amount in currency units (stored as minor units/cents).
|
||||||
|
*/
|
||||||
|
public function getAmountCurrencyAttribute(): float
|
||||||
|
{
|
||||||
|
return $this->amount / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set amount from currency units (stores as minor units/cents).
|
||||||
|
*/
|
||||||
|
public function setAmountCurrencyAttribute($value): void
|
||||||
|
{
|
||||||
|
$this->attributes['amount'] = round($value * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format amount for display with proper currency formatting.
|
||||||
|
* This can be extended later to support different currencies.
|
||||||
|
*/
|
||||||
|
public function getFormattedAmountAttribute(): string
|
||||||
|
{
|
||||||
|
return number_format($this->amount / 100, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
app/Models/Traits/HasProjectionStatus.php
Normal file
69
app/Models/Traits/HasProjectionStatus.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Traits;
|
||||||
|
|
||||||
|
trait HasProjectionStatus
|
||||||
|
{
|
||||||
|
public function initializeHasProjectionStatus(): void
|
||||||
|
{
|
||||||
|
$this->fillable = array_merge($this->fillable ?? [], [
|
||||||
|
'is_projected',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->casts = array_merge($this->casts ?? [], [
|
||||||
|
'is_projected' => 'boolean',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to filter projected transactions
|
||||||
|
*/
|
||||||
|
public function scopeProjected($query)
|
||||||
|
{
|
||||||
|
return $query->where('is_projected', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to filter actual transactions
|
||||||
|
*/
|
||||||
|
public function scopeActual($query)
|
||||||
|
{
|
||||||
|
return $query->where('is_projected', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this transaction is projected
|
||||||
|
*/
|
||||||
|
public function isProjected(): bool
|
||||||
|
{
|
||||||
|
return $this->is_projected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this transaction is actual
|
||||||
|
*/
|
||||||
|
public function isActual(): bool
|
||||||
|
{
|
||||||
|
return ! $this->is_projected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark transaction as projected
|
||||||
|
*/
|
||||||
|
public function markAsProjected(): self
|
||||||
|
{
|
||||||
|
$this->update(['is_projected' => true]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark transaction as actual
|
||||||
|
*/
|
||||||
|
public function markAsActual(): self
|
||||||
|
{
|
||||||
|
$this->update(['is_projected' => false]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Models/Traits/HasUuid.php
Normal file
22
app/Models/Traits/HasUuid.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
trait HasUuid
|
||||||
|
{
|
||||||
|
public static function bootHasUuid(): void
|
||||||
|
{
|
||||||
|
static::creating(function ($model) {
|
||||||
|
if (empty($model->uuid)) {
|
||||||
|
$model->uuid = (string) Str::orderedUuid();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRouteKeyName(): string
|
||||||
|
{
|
||||||
|
return 'uuid';
|
||||||
|
}
|
||||||
|
}
|
||||||
52
app/Models/User.php
Normal file
52
app/Models/User.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||||
|
|
||||||
|
class User extends Authenticatable
|
||||||
|
{
|
||||||
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||||
|
use HasFactory, Notifiable, TwoFactorAuthenticatable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'email',
|
||||||
|
'password',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be hidden for serialization.
|
||||||
|
*
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected $hidden = [
|
||||||
|
'password',
|
||||||
|
'two_factor_secret',
|
||||||
|
'two_factor_recovery_codes',
|
||||||
|
'remember_token',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'email_verified_at' => 'datetime',
|
||||||
|
'password' => 'hashed',
|
||||||
|
'two_factor_confirmed_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Providers/AppServiceProvider.php
Normal file
24
app/Providers/AppServiceProvider.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class AppServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap any application services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Providers/FortifyServiceProvider.php
Normal file
91
app/Providers/FortifyServiceProvider.php
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Actions\Fortify\CreateNewUser;
|
||||||
|
use App\Actions\Fortify\ResetUserPassword;
|
||||||
|
use Illuminate\Cache\RateLimiting\Limit;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Laravel\Fortify\Features;
|
||||||
|
use Laravel\Fortify\Fortify;
|
||||||
|
|
||||||
|
class FortifyServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap any application services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
$this->configureActions();
|
||||||
|
$this->configureViews();
|
||||||
|
$this->configureRateLimiting();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure Fortify actions.
|
||||||
|
*/
|
||||||
|
private function configureActions(): void
|
||||||
|
{
|
||||||
|
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
||||||
|
Fortify::createUsersUsing(CreateNewUser::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure Fortify views.
|
||||||
|
*/
|
||||||
|
private function configureViews(): void
|
||||||
|
{
|
||||||
|
Fortify::loginView(fn (Request $request) => Inertia::render('auth/login', [
|
||||||
|
'canResetPassword' => Features::enabled(Features::resetPasswords()),
|
||||||
|
'canRegister' => Features::enabled(Features::registration()),
|
||||||
|
'status' => $request->session()->get('status'),
|
||||||
|
]));
|
||||||
|
|
||||||
|
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/reset-password', [
|
||||||
|
'email' => $request->email,
|
||||||
|
'token' => $request->route('token'),
|
||||||
|
]));
|
||||||
|
|
||||||
|
Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/forgot-password', [
|
||||||
|
'status' => $request->session()->get('status'),
|
||||||
|
]));
|
||||||
|
|
||||||
|
Fortify::verifyEmailView(fn (Request $request) => Inertia::render('auth/verify-email', [
|
||||||
|
'status' => $request->session()->get('status'),
|
||||||
|
]));
|
||||||
|
|
||||||
|
Fortify::registerView(fn () => Inertia::render('auth/register'));
|
||||||
|
|
||||||
|
Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/two-factor-challenge'));
|
||||||
|
|
||||||
|
Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure rate limiting.
|
||||||
|
*/
|
||||||
|
private function configureRateLimiting(): void
|
||||||
|
{
|
||||||
|
RateLimiter::for('two-factor', function (Request $request) {
|
||||||
|
return Limit::perMinute(5)->by($request->session()->get('login.id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
RateLimiter::for('login', function (Request $request) {
|
||||||
|
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
|
||||||
|
|
||||||
|
return Limit::perMinute(5)->by($throttleKey);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
100
app/Repositories/StreamRepository.php
Normal file
100
app/Repositories/StreamRepository.php
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Models\Stream;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class StreamRepository
|
||||||
|
{
|
||||||
|
public function getForScenario(Scenario $scenario): Collection
|
||||||
|
{
|
||||||
|
return $scenario->streams()
|
||||||
|
->with('bucket:id,uuid,name')
|
||||||
|
->orderBy('type')
|
||||||
|
->orderBy('name')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Scenario $scenario, array $data): Stream
|
||||||
|
{
|
||||||
|
$this->resolveBucketId($data);
|
||||||
|
|
||||||
|
return $scenario->streams()->create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Stream $stream, array $data): Stream
|
||||||
|
{
|
||||||
|
$this->resolveBucketId($data);
|
||||||
|
|
||||||
|
$stream->update($data);
|
||||||
|
|
||||||
|
return $stream->fresh('bucket');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(Stream $stream): bool
|
||||||
|
{
|
||||||
|
return $stream->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleActive(Stream $stream): Stream
|
||||||
|
{
|
||||||
|
$stream->update([
|
||||||
|
'is_active' => ! $stream->is_active,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $stream->fresh('bucket');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a bucket belongs to the scenario
|
||||||
|
*/
|
||||||
|
public function bucketBelongsToScenario(Scenario $scenario, ?string $bucketUuid): bool
|
||||||
|
{
|
||||||
|
if (! $bucketUuid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $scenario->buckets()
|
||||||
|
->where('uuid', $bucketUuid)
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveBucketId(array &$data): void
|
||||||
|
{
|
||||||
|
if (! empty($data['bucket_id'])) {
|
||||||
|
$data['bucket_id'] = Bucket::where('uuid', $data['bucket_id'])->value('id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get streams grouped by type
|
||||||
|
*/
|
||||||
|
public function getGroupedByType(Scenario $scenario): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'income' => $scenario->streams()
|
||||||
|
->with('bucket:id,uuid,name')
|
||||||
|
->byType(Stream::TYPE_INCOME)
|
||||||
|
->orderBy('name')
|
||||||
|
->get(),
|
||||||
|
'expense' => $scenario->streams()
|
||||||
|
->with('bucket:id,uuid,name')
|
||||||
|
->byType(Stream::TYPE_EXPENSE)
|
||||||
|
->orderBy('name')
|
||||||
|
->get(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get streams for a specific bucket
|
||||||
|
*/
|
||||||
|
public function getForBucket(int $bucketId): Collection
|
||||||
|
{
|
||||||
|
return Stream::where('bucket_id', $bucketId)
|
||||||
|
->where('is_active', true)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
}
|
||||||
215
app/Services/Projection/PipelineAllocationService.php
Normal file
215
app/Services/Projection/PipelineAllocationService.php
Normal file
|
|
@ -0,0 +1,215 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Projection;
|
||||||
|
|
||||||
|
use App\Enums\BucketTypeEnum;
|
||||||
|
use App\Enums\DistributionModeEnum;
|
||||||
|
use App\Models\Bucket;
|
||||||
|
use App\Models\Draw;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
readonly class PipelineAllocationService
|
||||||
|
{
|
||||||
|
private const string CAP_BASE = 'base';
|
||||||
|
|
||||||
|
private const string CAP_FILL = 'fill';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate an inflow amount across scenario buckets using phased distribution.
|
||||||
|
*
|
||||||
|
* Phases:
|
||||||
|
* 1. Needs to base (allocation_value)
|
||||||
|
* 2. Wants to base (allocation_value)
|
||||||
|
* 3. Needs to buffer (getEffectiveCapacity)
|
||||||
|
* 4. Wants to buffer (getEffectiveCapacity)
|
||||||
|
* 5. Overflow (all remaining)
|
||||||
|
*
|
||||||
|
* @return Collection<int, Draw> Collection of Draw models (unsaved)
|
||||||
|
*/
|
||||||
|
public function allocateInflow(Scenario $scenario, int $amount, ?Carbon $date = null, ?string $description = null): Collection
|
||||||
|
{
|
||||||
|
if ($amount <= 0) {
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$buckets = $scenario->buckets()
|
||||||
|
->orderBy('priority')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
if ($buckets->isEmpty()) {
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mode = $scenario->distribution_mode ?? DistributionModeEnum::EVEN;
|
||||||
|
$allocationDate = $date ?? now();
|
||||||
|
$allocationDescription = $description ?? 'Allocation from inflow';
|
||||||
|
|
||||||
|
// Track cumulative allocations per bucket across phases
|
||||||
|
/** @var array<int, int> $allocated bucket_id => total allocated cents */
|
||||||
|
$allocated = [];
|
||||||
|
|
||||||
|
$needs = $buckets->filter(fn (Bucket $b) => $b->type === BucketTypeEnum::NEED);
|
||||||
|
$wants = $buckets->filter(fn (Bucket $b) => $b->type === BucketTypeEnum::WANT);
|
||||||
|
$overflow = $buckets->first(fn (Bucket $b) => $b->type === BucketTypeEnum::OVERFLOW);
|
||||||
|
|
||||||
|
$remaining = $amount;
|
||||||
|
|
||||||
|
// Phases 1-4: needs/wants to base/buffer
|
||||||
|
$phases = [
|
||||||
|
[$needs, self::CAP_BASE],
|
||||||
|
[$wants, self::CAP_BASE],
|
||||||
|
[$needs, self::CAP_FILL],
|
||||||
|
[$wants, self::CAP_FILL],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($phases as [$group, $cap]) {
|
||||||
|
$remaining = $this->allocateToGroup($group, $remaining, $mode, $cap, $allocated);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phase 5: Overflow
|
||||||
|
if ($remaining > 0 && $overflow !== null) {
|
||||||
|
$allocated[$overflow->id] = ($allocated[$overflow->id] ?? 0) + $remaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build Draw models from cumulative allocations
|
||||||
|
$draws = collect();
|
||||||
|
foreach ($allocated as $bucketId => $totalAmount) {
|
||||||
|
if ($totalAmount <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$draws->push(new Draw([
|
||||||
|
'bucket_id' => $bucketId,
|
||||||
|
'amount' => $totalAmount,
|
||||||
|
'date' => $allocationDate,
|
||||||
|
'description' => $allocationDescription,
|
||||||
|
'is_projected' => true,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $draws;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate money to a group of buckets up to a capacity target.
|
||||||
|
*
|
||||||
|
* @param Collection<int, Bucket> $buckets Buckets ordered by priority
|
||||||
|
* @param int $amount Available money in cents
|
||||||
|
* @param DistributionModeEnum $mode Even or priority distribution
|
||||||
|
* @param string $capMethod self::CAP_BASE = allocation_value, self::CAP_FILL = getEffectiveCapacity()
|
||||||
|
* @param array<int, int> &$allocated Cumulative allocations per bucket (mutated)
|
||||||
|
* @return int Remaining amount after allocation
|
||||||
|
*/
|
||||||
|
private function allocateToGroup(Collection $buckets, int $amount, DistributionModeEnum $mode, string $capMethod, array &$allocated): int
|
||||||
|
{
|
||||||
|
if ($amount <= 0 || $buckets->isEmpty()) {
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match ($mode) {
|
||||||
|
DistributionModeEnum::PRIORITY => $this->allocatePriority($buckets, $amount, $capMethod, $allocated),
|
||||||
|
DistributionModeEnum::EVEN => $this->allocateEven($buckets, $amount, $capMethod, $allocated),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Priority mode: fill highest-priority bucket first, then next.
|
||||||
|
*/
|
||||||
|
private function allocatePriority(Collection $buckets, int $amount, string $capMethod, array &$allocated): int
|
||||||
|
{
|
||||||
|
$remaining = $amount;
|
||||||
|
|
||||||
|
foreach ($buckets as $bucket) {
|
||||||
|
if ($remaining <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$space = $this->getAvailableSpace($bucket, $capMethod, $allocated);
|
||||||
|
if ($space <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$allocation = min($space, $remaining);
|
||||||
|
$allocated[$bucket->id] = ($allocated[$bucket->id] ?? 0) + $allocation;
|
||||||
|
$remaining -= $allocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $remaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even mode: split evenly across eligible buckets, redistributing when one fills up.
|
||||||
|
*/
|
||||||
|
private function allocateEven(Collection $buckets, int $amount, string $capMethod, array &$allocated): int
|
||||||
|
{
|
||||||
|
$remaining = $amount;
|
||||||
|
|
||||||
|
// Filter to buckets that still have space
|
||||||
|
$eligible = $buckets->filter(fn (Bucket $b) => $this->getAvailableSpace($b, $capMethod, $allocated) > 0);
|
||||||
|
|
||||||
|
while ($remaining > 0 && $eligible->isNotEmpty()) {
|
||||||
|
$share = intdiv($remaining, $eligible->count());
|
||||||
|
$remainder = $remaining % $eligible->count();
|
||||||
|
|
||||||
|
$spent = 0;
|
||||||
|
$filledUp = [];
|
||||||
|
|
||||||
|
foreach ($eligible as $index => $bucket) {
|
||||||
|
$bucketShare = $share + ($remainder > 0 ? 1 : 0);
|
||||||
|
if ($remainder > 0) {
|
||||||
|
$remainder--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bucketShare <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$space = $this->getAvailableSpace($bucket, $capMethod, $allocated);
|
||||||
|
$allocation = min($bucketShare, $space);
|
||||||
|
|
||||||
|
if ($allocation > 0) {
|
||||||
|
$allocated[$bucket->id] = ($allocated[$bucket->id] ?? 0) + $allocation;
|
||||||
|
$spent += $allocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($allocation >= $space) {
|
||||||
|
$filledUp[] = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining -= $spent;
|
||||||
|
|
||||||
|
if (empty($filledUp)) {
|
||||||
|
// No bucket filled up, so we're done (all money placed or share was 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove filled buckets and retry with remaining money
|
||||||
|
$eligible = $eligible->forget($filledUp)->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $remaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get available space for a bucket given the cap method and already-allocated amounts.
|
||||||
|
*/
|
||||||
|
private function getAvailableSpace(Bucket $bucket, string $capMethod, array $allocated): int
|
||||||
|
{
|
||||||
|
// Non-fixed-limit buckets (percentage, unlimited) have no meaningful cap in phased distribution
|
||||||
|
if (! $bucket->hasFiniteCapacity()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cap = $capMethod === self::CAP_BASE
|
||||||
|
? ($bucket->allocation_value ?? 0)
|
||||||
|
: $bucket->getEffectiveCapacity();
|
||||||
|
|
||||||
|
$currentBalance = $bucket->getCurrentBalance();
|
||||||
|
$alreadyAllocated = $allocated[$bucket->id] ?? 0;
|
||||||
|
|
||||||
|
return max(0, $cap - $currentBalance - $alreadyAllocated);
|
||||||
|
}
|
||||||
|
}
|
||||||
145
app/Services/Projection/ProjectionGeneratorService.php
Normal file
145
app/Services/Projection/ProjectionGeneratorService.php
Normal file
|
|
@ -0,0 +1,145 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Projection;
|
||||||
|
|
||||||
|
use App\Enums\StreamFrequencyEnum;
|
||||||
|
use App\Enums\StreamTypeEnum;
|
||||||
|
use App\Models\Inflow;
|
||||||
|
use App\Models\Outflow;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
use App\Models\Stream;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class ProjectionGeneratorService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly PipelineAllocationService $pipelineAllocationService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function generateProjections(Scenario $scenario, Carbon $startDate, Carbon $endDate): array
|
||||||
|
{
|
||||||
|
$inflows = collect();
|
||||||
|
$outflows = collect();
|
||||||
|
$draws = collect();
|
||||||
|
|
||||||
|
// Get active streams
|
||||||
|
$activeStreams = $scenario->streams()
|
||||||
|
->where('is_active', true)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Process each day in the range
|
||||||
|
$currentDate = $startDate->copy();
|
||||||
|
while ($currentDate <= $endDate) {
|
||||||
|
// Process all streams that fire on this date
|
||||||
|
foreach ($activeStreams as $stream) {
|
||||||
|
if ($this->streamFiresOnDate($stream, $currentDate)) {
|
||||||
|
if ($stream->type === StreamTypeEnum::INCOME) {
|
||||||
|
// Create and save inflow
|
||||||
|
$inflow = Inflow::create([
|
||||||
|
'stream_id' => $stream->id,
|
||||||
|
'amount' => $stream->amount,
|
||||||
|
'date' => $currentDate->copy(),
|
||||||
|
'description' => "Projected income from {$stream->name}",
|
||||||
|
'is_projected' => true,
|
||||||
|
]);
|
||||||
|
$inflows->push($inflow);
|
||||||
|
|
||||||
|
// Immediately allocate this income to buckets
|
||||||
|
$dailyDraws = $this->pipelineAllocationService->allocateInflow(
|
||||||
|
$scenario,
|
||||||
|
$inflow->amount
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set date and description for each draw and save
|
||||||
|
foreach ($dailyDraws as $draw) {
|
||||||
|
$draw->date = $currentDate->copy();
|
||||||
|
$draw->description = "Allocation from {$stream->name}";
|
||||||
|
$draw->is_projected = true;
|
||||||
|
$draw->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$draws = $draws->merge($dailyDraws);
|
||||||
|
} else {
|
||||||
|
// Create and save outflow
|
||||||
|
$outflow = Outflow::create([
|
||||||
|
'stream_id' => $stream->id,
|
||||||
|
'bucket_id' => $stream->bucket_id,
|
||||||
|
'amount' => $stream->amount,
|
||||||
|
'date' => $currentDate->copy(),
|
||||||
|
'description' => "Projected expense from {$stream->name}",
|
||||||
|
'is_projected' => true,
|
||||||
|
]);
|
||||||
|
$outflows->push($outflow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move to next day
|
||||||
|
$currentDate->addDay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate summary statistics
|
||||||
|
$summary = [
|
||||||
|
'total_inflow' => $inflows->sum('amount'),
|
||||||
|
'total_outflow' => $outflows->sum('amount'),
|
||||||
|
'total_allocated' => $draws->sum('amount'),
|
||||||
|
'net_cashflow' => $inflows->sum('amount') - $outflows->sum('amount'),
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'inflows' => $inflows->sortBy('date')->values(),
|
||||||
|
'outflows' => $outflows->sortBy('date')->values(),
|
||||||
|
'draws' => $draws->sortBy('date')->values(),
|
||||||
|
'summary' => $summary,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function streamFiresOnDate(Stream $stream, Carbon $date): bool
|
||||||
|
{
|
||||||
|
// Check if date is within stream's active period
|
||||||
|
if ($date->lt($stream->start_date)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($stream->end_date && $date->gt($stream->end_date)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check frequency-specific rules
|
||||||
|
return match ($stream->frequency) {
|
||||||
|
StreamFrequencyEnum::DAILY => true,
|
||||||
|
StreamFrequencyEnum::WEEKLY => $this->isWeeklyOccurrence($stream, $date),
|
||||||
|
StreamFrequencyEnum::MONTHLY => $this->isMonthlyOccurrence($stream, $date),
|
||||||
|
StreamFrequencyEnum::YEARLY => $this->isYearlyOccurrence($stream, $date),
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isWeeklyOccurrence(Stream $stream, Carbon $date): bool
|
||||||
|
{
|
||||||
|
// Check if it's the same day of week as the start date
|
||||||
|
return $date->dayOfWeek === $stream->start_date->dayOfWeek;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isMonthlyOccurrence(Stream $stream, Carbon $date): bool
|
||||||
|
{
|
||||||
|
// Check if it's the same day of month as the start date
|
||||||
|
// Handle end-of-month cases (e.g., 31st in months with fewer days)
|
||||||
|
$targetDay = $stream->start_date->day;
|
||||||
|
$lastDayOfMonth = $date->copy()->endOfMonth()->day;
|
||||||
|
|
||||||
|
if ($targetDay > $lastDayOfMonth) {
|
||||||
|
// If the target day doesn't exist in this month, use the last day
|
||||||
|
return $date->day === $lastDayOfMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date->day === $targetDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isYearlyOccurrence(Stream $stream, Carbon $date): bool
|
||||||
|
{
|
||||||
|
// Check if it's the same month and day as the start date
|
||||||
|
return $date->month === $stream->start_date->month
|
||||||
|
&& $date->day === $stream->start_date->day;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Services/Streams/StatsService.php
Normal file
34
app/Services/Streams/StatsService.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Streams;
|
||||||
|
|
||||||
|
use App\Enums\StreamTypeEnum;
|
||||||
|
use App\Models\Scenario;
|
||||||
|
|
||||||
|
readonly class StatsService
|
||||||
|
{
|
||||||
|
public function getSummaryStats(Scenario $scenario): array
|
||||||
|
{
|
||||||
|
$streams = $scenario->streams()
|
||||||
|
->where('is_active', true)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$totalMonthlyIncome = $streams
|
||||||
|
->where('type', StreamTypeEnum::INCOME)
|
||||||
|
->sum(fn ($stream) => $stream->getMonthlyEquivalent());
|
||||||
|
|
||||||
|
$totalMonthlyExpenses = $streams
|
||||||
|
->where('type', StreamTypeEnum::EXPENSE)
|
||||||
|
->sum(fn ($stream) => $stream->getMonthlyEquivalent());
|
||||||
|
|
||||||
|
return [
|
||||||
|
'total_streams' => $streams->count(),
|
||||||
|
'active_streams' => $streams->where('is_active', true)->count(),
|
||||||
|
'income_streams' => $streams->where('type', StreamTypeEnum::INCOME)->count(),
|
||||||
|
'expense_streams' => $streams->where('type', StreamTypeEnum::EXPENSE)->count(),
|
||||||
|
'monthly_income' => $totalMonthlyIncome,
|
||||||
|
'monthly_expenses' => $totalMonthlyExpenses,
|
||||||
|
'monthly_net' => $totalMonthlyIncome - $totalMonthlyExpenses,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
18
artisan
Executable file
18
artisan
Executable file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Symfony\Component\Console\Input\ArgvInput;
|
||||||
|
|
||||||
|
define('LARAVEL_START', microtime(true));
|
||||||
|
|
||||||
|
// Register the Composer autoloader...
|
||||||
|
require __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
|
// Bootstrap Laravel and handle the command...
|
||||||
|
/** @var Application $app */
|
||||||
|
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||||
|
|
||||||
|
$status = $app->handleCommand(new ArgvInput);
|
||||||
|
|
||||||
|
exit($status);
|
||||||
21
bin/console
21
bin/console
|
|
@ -1,21 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
use App\Kernel;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
||||||
|
|
||||||
if (!is_dir(dirname(__DIR__).'/vendor')) {
|
|
||||||
throw new LogicException('Dependencies are missing. Try running "composer install".');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
|
|
||||||
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
|
|
||||||
|
|
||||||
return function (array $context) {
|
|
||||||
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
|
|
||||||
|
|
||||||
return new Application($kernel);
|
|
||||||
};
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
|
|
||||||
27
bootstrap/app.php
Normal file
27
bootstrap/app.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Middleware\HandleAppearance;
|
||||||
|
use App\Http\Middleware\HandleInertiaRequests;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
|
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
|
||||||
|
|
||||||
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
|
->withRouting(
|
||||||
|
web: __DIR__.'/../routes/web.php',
|
||||||
|
commands: __DIR__.'/../routes/console.php',
|
||||||
|
health: '/up',
|
||||||
|
)
|
||||||
|
->withMiddleware(function (Middleware $middleware): void {
|
||||||
|
$middleware->encryptCookies(except: ['appearance', 'sidebar_state']);
|
||||||
|
|
||||||
|
$middleware->web(append: [
|
||||||
|
HandleAppearance::class,
|
||||||
|
HandleInertiaRequests::class,
|
||||||
|
AddLinkHeadersForPreloadedAssets::class,
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
->withExceptions(function (Exceptions $exceptions): void {
|
||||||
|
//
|
||||||
|
})->create();
|
||||||
2
bootstrap/cache/.gitignore
vendored
Normal file
2
bootstrap/cache/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!.gitignore
|
||||||
6
bootstrap/providers.php
Normal file
6
bootstrap/providers.php
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
App\Providers\AppServiceProvider::class,
|
||||||
|
App\Providers\FortifyServiceProvider::class,
|
||||||
|
];
|
||||||
21
components.json
Normal file
21
components.json
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
|
"style": "new-york",
|
||||||
|
"rsc": false,
|
||||||
|
"tsx": true,
|
||||||
|
"tailwind": {
|
||||||
|
"config": "",
|
||||||
|
"css": "resources/css/app.css",
|
||||||
|
"baseColor": "neutral",
|
||||||
|
"cssVariables": true,
|
||||||
|
"prefix": ""
|
||||||
|
},
|
||||||
|
"aliases": {
|
||||||
|
"components": "@/components",
|
||||||
|
"utils": "@/lib/utils",
|
||||||
|
"ui": "@/components/ui",
|
||||||
|
"lib": "@/lib",
|
||||||
|
"hooks": "@/hooks"
|
||||||
|
},
|
||||||
|
"iconLibrary": "lucide"
|
||||||
|
}
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
---
|
|
||||||
# Development environment override
|
|
||||||
services:
|
|
||||||
php:
|
|
||||||
image: ${IMAGES_PREFIX:-}app-php-dev
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
target: frankenphp_dev
|
|
||||||
volumes:
|
|
||||||
- ./:/app
|
|
||||||
- ./frankenphp/Caddyfile:/etc/frankenphp/Caddyfile:ro
|
|
||||||
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
|
|
||||||
# Keep var/ off the bind-mount for faster I/O on Mac/Windows; comment to inspect from the host.
|
|
||||||
- /app/var
|
|
||||||
# If you develop on Mac or Windows you can remove the vendor/ directory
|
|
||||||
# from the bind-mount for better performance by enabling the next line:
|
|
||||||
#- /app/vendor
|
|
||||||
ports:
|
|
||||||
# HTTP-only in dev — no 443 mapping (SERVER_NAME ":80" means nothing listens there).
|
|
||||||
- "${HTTP_PORT:-8100}:80"
|
|
||||||
environment:
|
|
||||||
# HTTP-only in dev (no TLS, no HTTP→HTTPS redirect). App served on http://localhost:8100.
|
|
||||||
SERVER_NAME: ":80"
|
|
||||||
FRANKENPHP_WORKER_CONFIG: watch
|
|
||||||
FRANKENPHP_SITE_CONFIG: hot_reload
|
|
||||||
MERCURE_EXTRA_DIRECTIVES: demo
|
|
||||||
# See https://xdebug.org/docs/all_settings#mode
|
|
||||||
XDEBUG_MODE: "${XDEBUG_MODE:-develop}"
|
|
||||||
APP_ENV: "${APP_ENV:-dev}"
|
|
||||||
extra_hosts:
|
|
||||||
# Ensure that host.docker.internal is correctly defined on Linux
|
|
||||||
- host.docker.internal:host-gateway
|
|
||||||
tty: true
|
|
||||||
###> symfony/mercure-bundle ###
|
|
||||||
###< symfony/mercure-bundle ###
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
---
|
|
||||||
# Production environment override
|
|
||||||
services:
|
|
||||||
php:
|
|
||||||
image: ${IMAGES_PREFIX:-}app-php-prod
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
target: frankenphp_prod
|
|
||||||
ports:
|
|
||||||
- "${HTTP_PORT:-80}:80"
|
|
||||||
- "${HTTPS_PORT:-443}:443"
|
|
||||||
- "${HTTP3_PORT:-443}:443/udp"
|
|
||||||
environment:
|
|
||||||
APP_SECRET: ${APP_SECRET}
|
|
||||||
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
|
|
||||||
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
|
|
||||||
52
compose.yaml
52
compose.yaml
|
|
@ -1,52 +0,0 @@
|
||||||
---
|
|
||||||
services:
|
|
||||||
php:
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
|
|
||||||
DEFAULT_URI: https://${SERVER_NAME:-localhost}:${HTTPS_PORT:-443}
|
|
||||||
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
|
|
||||||
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
|
|
||||||
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
|
|
||||||
DATABASE_URL: postgresql://${POSTGRES_USER:-buckets}:${POSTGRES_PASSWORD:-buckets}@database:5432/${POSTGRES_DB:-buckets}?serverVersion=${POSTGRES_VERSION:-16}&charset=${POSTGRES_CHARSET:-utf8}
|
|
||||||
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
|
|
||||||
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
|
|
||||||
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}:${HTTPS_PORT:-443}/.well-known/mercure}
|
|
||||||
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
|
|
||||||
volumes:
|
|
||||||
- caddy_data:/data
|
|
||||||
- caddy_config:/config
|
|
||||||
# Ports are declared per-environment: compose.override.yaml (dev, HTTP-only)
|
|
||||||
# and compose.prod.yaml (prod, HTTPS). Keeps each env from publishing ports
|
|
||||||
# nothing listens on.
|
|
||||||
depends_on:
|
|
||||||
database:
|
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
database:
|
|
||||||
image: postgres:16-alpine
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB:-buckets}
|
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-buckets}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-buckets}
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-buckets} -d ${POSTGRES_DB:-buckets}"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
start_period: 30s
|
|
||||||
volumes:
|
|
||||||
- database_data:/var/lib/postgresql/data
|
|
||||||
ports:
|
|
||||||
- "${DB_PORT:-5433}:5432"
|
|
||||||
|
|
||||||
# Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service
|
|
||||||
###> symfony/mercure-bundle ###
|
|
||||||
###< symfony/mercure-bundle ###
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
caddy_data:
|
|
||||||
caddy_config:
|
|
||||||
database_data:
|
|
||||||
###> symfony/mercure-bundle ###
|
|
||||||
###< symfony/mercure-bundle ###
|
|
||||||
154
composer.json
154
composer.json
|
|
@ -1,101 +1,99 @@
|
||||||
{
|
{
|
||||||
|
"$schema": "https://getcomposer.org/schema.json",
|
||||||
|
"name": "laravel/react-starter-kit",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"license": "proprietary",
|
"description": "The skeleton application for the Laravel framework.",
|
||||||
"minimum-stability": "stable",
|
"keywords": [
|
||||||
"prefer-stable": true,
|
"laravel",
|
||||||
|
"framework"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.4",
|
"php": "^8.3",
|
||||||
"ext-ctype": "*",
|
"inertiajs/inertia-laravel": "^2.0",
|
||||||
"ext-iconv": "*",
|
"laravel/fortify": "^1.30",
|
||||||
"api-platform/doctrine-orm": "^4.3",
|
"laravel/framework": "^12.0",
|
||||||
"api-platform/symfony": "^4.3",
|
"laravel/tinker": "^2.10.1",
|
||||||
"doctrine/doctrine-bundle": "^3.2",
|
"laravel/wayfinder": "^0.1.9"
|
||||||
"doctrine/doctrine-migrations-bundle": "^4.0",
|
|
||||||
"doctrine/orm": "^3.6",
|
|
||||||
"nelmio/cors-bundle": "^2.6",
|
|
||||||
"phpdocumentor/reflection-docblock": "^6.0",
|
|
||||||
"phpstan/phpdoc-parser": "^2.3",
|
|
||||||
"symfony/asset": "8.1.*",
|
|
||||||
"symfony/console": "8.1.*",
|
|
||||||
"symfony/dotenv": "8.1.*",
|
|
||||||
"symfony/expression-language": "8.1.*",
|
|
||||||
"symfony/flex": "^2",
|
|
||||||
"symfony/framework-bundle": "8.1.*",
|
|
||||||
"symfony/monolog-bundle": "^4.0",
|
|
||||||
"symfony/property-access": "8.1.*",
|
|
||||||
"symfony/property-info": "8.1.*",
|
|
||||||
"symfony/runtime": "8.1.*",
|
|
||||||
"symfony/security-bundle": "8.1.*",
|
|
||||||
"symfony/serializer": "8.1.*",
|
|
||||||
"symfony/twig-bundle": "8.1.*",
|
|
||||||
"symfony/uid": "8.1.*",
|
|
||||||
"symfony/validator": "8.1.*",
|
|
||||||
"symfony/yaml": "8.1.*"
|
|
||||||
},
|
},
|
||||||
"config": {
|
"require-dev": {
|
||||||
"allow-plugins": {
|
"fakerphp/faker": "^1.23",
|
||||||
"php-http/discovery": true,
|
"larastan/larastan": "^3.9",
|
||||||
"phpstan/extension-installer": true,
|
"laravel/pail": "^1.2.2",
|
||||||
"symfony/flex": true,
|
"laravel/pint": "^1.24",
|
||||||
"symfony/runtime": true
|
"laravel/sail": "^1.41",
|
||||||
},
|
"mockery/mockery": "^1.6",
|
||||||
"bump-after-update": true,
|
"nunomaduro/collision": "^8.6",
|
||||||
"sort-packages": true
|
"phpstan/phpstan-mockery": "^2.0",
|
||||||
|
"phpunit/phpunit": "^11.5.3"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "src/"
|
"App\\": "app/",
|
||||||
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\Tests\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"replace": {
|
|
||||||
"symfony/polyfill-ctype": "*",
|
|
||||||
"symfony/polyfill-iconv": "*",
|
|
||||||
"symfony/polyfill-php72": "*",
|
|
||||||
"symfony/polyfill-php73": "*",
|
|
||||||
"symfony/polyfill-php74": "*",
|
|
||||||
"symfony/polyfill-php80": "*",
|
|
||||||
"symfony/polyfill-php81": "*",
|
|
||||||
"symfony/polyfill-php82": "*",
|
|
||||||
"symfony/polyfill-php83": "*",
|
|
||||||
"symfony/polyfill-php84": "*"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"auto-scripts": {
|
"setup": [
|
||||||
"cache:clear": "symfony-cmd",
|
"composer install",
|
||||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
|
||||||
},
|
"@php artisan key:generate",
|
||||||
"post-install-cmd": [
|
"@php artisan migrate --force",
|
||||||
"@auto-scripts"
|
"npm install",
|
||||||
|
"npm run build"
|
||||||
|
],
|
||||||
|
"dev": [
|
||||||
|
"Composer\\Config::disableProcessTimeout",
|
||||||
|
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
|
||||||
|
],
|
||||||
|
"dev:ssr": [
|
||||||
|
"npm run build:ssr",
|
||||||
|
"Composer\\Config::disableProcessTimeout",
|
||||||
|
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"php artisan inertia:start-ssr\" --names=server,queue,logs,ssr --kill-others"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"@php artisan config:clear --ansi",
|
||||||
|
"@php artisan test"
|
||||||
|
],
|
||||||
|
"post-autoload-dump": [
|
||||||
|
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||||
|
"@php artisan package:discover --ansi"
|
||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"@auto-scripts"
|
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||||
|
],
|
||||||
|
"post-root-package-install": [
|
||||||
|
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||||
|
],
|
||||||
|
"post-create-project-cmd": [
|
||||||
|
"@php artisan key:generate --ansi",
|
||||||
|
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
|
||||||
|
"@php artisan migrate --graceful --ansi"
|
||||||
|
],
|
||||||
|
"pre-package-uninstall": [
|
||||||
|
"Illuminate\\Foundation\\ComposerScripts::prePackageUninstall"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"conflict": {
|
|
||||||
"symfony/symfony": "*"
|
|
||||||
},
|
|
||||||
"extra": {
|
"extra": {
|
||||||
"symfony": {
|
"laravel": {
|
||||||
"allow-contrib": false,
|
"dont-discover": []
|
||||||
"require": "8.1.*",
|
|
||||||
"docker": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"config": {
|
||||||
"dama/doctrine-test-bundle": "^8.6",
|
"optimize-autoloader": true,
|
||||||
"friendsofphp/php-cs-fixer": "^3.95",
|
"preferred-install": "dist",
|
||||||
"phpstan/extension-installer": "^1.4",
|
"sort-packages": true,
|
||||||
"phpstan/phpstan": "^2.2",
|
"allow-plugins": {
|
||||||
"phpstan/phpstan-doctrine": "^2.0",
|
"pestphp/pest-plugin": true,
|
||||||
"phpstan/phpstan-symfony": "^2.0",
|
"php-http/discovery": true
|
||||||
"phpunit/phpunit": "^13.2",
|
|
||||||
"symfony/browser-kit": "8.1.*",
|
|
||||||
"symfony/css-selector": "8.1.*",
|
|
||||||
"symfony/maker-bundle": "^1.67"
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12025
composer.lock
generated
12025
composer.lock
generated
File diff suppressed because it is too large
Load diff
126
config/app.php
Normal file
126
config/app.php
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Name
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value is the name of your application, which will be used when the
|
||||||
|
| framework needs to place the application's name in a notification or
|
||||||
|
| other UI elements where an application name needs to be displayed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'name' => env('APP_NAME', 'Laravel'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Environment
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value determines the "environment" your application is currently
|
||||||
|
| running in. This may determine how you prefer to configure various
|
||||||
|
| services the application utilizes. Set this in your ".env" file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'env' => env('APP_ENV', 'production'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Debug Mode
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When your application is in debug mode, detailed error messages with
|
||||||
|
| stack traces will be shown on every error that occurs within your
|
||||||
|
| application. If disabled, a simple generic error page is shown.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'debug' => (bool) env('APP_DEBUG', false),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application URL
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This URL is used by the console to properly generate URLs when using
|
||||||
|
| the Artisan command line tool. You should set this to the root of
|
||||||
|
| the application so that it's available within Artisan commands.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'url' => env('APP_URL', 'http://localhost'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Timezone
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the default timezone for your application, which
|
||||||
|
| will be used by the PHP date and date-time functions. The timezone
|
||||||
|
| is set to "UTC" by default as it is suitable for most use cases.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'timezone' => 'UTC',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application Locale Configuration
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The application locale determines the default locale that will be used
|
||||||
|
| by Laravel's translation / localization methods. This option can be
|
||||||
|
| set to any locale for which you plan to have translation strings.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'locale' => env('APP_LOCALE', 'en'),
|
||||||
|
|
||||||
|
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
|
||||||
|
|
||||||
|
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Encryption Key
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This key is utilized by Laravel's encryption services and should be set
|
||||||
|
| to a random, 32 character string to ensure that all encrypted values
|
||||||
|
| are secure. You should do this prior to deploying the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'cipher' => 'AES-256-CBC',
|
||||||
|
|
||||||
|
'key' => env('APP_KEY'),
|
||||||
|
|
||||||
|
'previous_keys' => [
|
||||||
|
...array_filter(
|
||||||
|
explode(',', (string) env('APP_PREVIOUS_KEYS', ''))
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Maintenance Mode Driver
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| These configuration options determine the driver used to determine and
|
||||||
|
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||||
|
| allow maintenance mode to be controlled across multiple machines.
|
||||||
|
|
|
||||||
|
| Supported drivers: "file", "cache"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'maintenance' => [
|
||||||
|
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
|
||||||
|
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
115
config/auth.php
Normal file
115
config/auth.php
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Authentication Defaults
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the default authentication "guard" and password
|
||||||
|
| reset "broker" for your application. You may change these values
|
||||||
|
| as required, but they're a perfect start for most applications.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'defaults' => [
|
||||||
|
'guard' => env('AUTH_GUARD', 'web'),
|
||||||
|
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Authentication Guards
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Next, you may define every authentication guard for your application.
|
||||||
|
| Of course, a great default configuration has been defined for you
|
||||||
|
| which utilizes session storage plus the Eloquent user provider.
|
||||||
|
|
|
||||||
|
| All authentication guards have a user provider, which defines how the
|
||||||
|
| users are actually retrieved out of your database or other storage
|
||||||
|
| system used by the application. Typically, Eloquent is utilized.
|
||||||
|
|
|
||||||
|
| Supported: "session"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'guards' => [
|
||||||
|
'web' => [
|
||||||
|
'driver' => 'session',
|
||||||
|
'provider' => 'users',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| User Providers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| All authentication guards have a user provider, which defines how the
|
||||||
|
| users are actually retrieved out of your database or other storage
|
||||||
|
| system used by the application. Typically, Eloquent is utilized.
|
||||||
|
|
|
||||||
|
| If you have multiple user tables or models you may configure multiple
|
||||||
|
| providers to represent the model / table. These providers may then
|
||||||
|
| be assigned to any extra authentication guards you have defined.
|
||||||
|
|
|
||||||
|
| Supported: "database", "eloquent"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'providers' => [
|
||||||
|
'users' => [
|
||||||
|
'driver' => 'eloquent',
|
||||||
|
'model' => env('AUTH_MODEL', App\Models\User::class),
|
||||||
|
],
|
||||||
|
|
||||||
|
// 'users' => [
|
||||||
|
// 'driver' => 'database',
|
||||||
|
// 'table' => 'users',
|
||||||
|
// ],
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Resetting Passwords
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| These configuration options specify the behavior of Laravel's password
|
||||||
|
| reset functionality, including the table utilized for token storage
|
||||||
|
| and the user provider that is invoked to actually retrieve users.
|
||||||
|
|
|
||||||
|
| The expiry time is the number of minutes that each reset token will be
|
||||||
|
| considered valid. This security feature keeps tokens short-lived so
|
||||||
|
| they have less time to be guessed. You may change this as needed.
|
||||||
|
|
|
||||||
|
| The throttle setting is the number of seconds a user must wait before
|
||||||
|
| generating more password reset tokens. This prevents the user from
|
||||||
|
| quickly generating a very large amount of password reset tokens.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'passwords' => [
|
||||||
|
'users' => [
|
||||||
|
'provider' => 'users',
|
||||||
|
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
|
||||||
|
'expire' => 60,
|
||||||
|
'throttle' => 60,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Password Confirmation Timeout
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may define the number of seconds before a password confirmation
|
||||||
|
| window expires and users are asked to re-enter their password via the
|
||||||
|
| confirmation screen. By default, the timeout lasts for three hours.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),
|
||||||
|
|
||||||
|
];
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
|
||||||
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
|
|
||||||
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
|
|
||||||
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
|
|
||||||
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
|
|
||||||
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
|
|
||||||
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
|
|
||||||
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
|
||||||
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
|
|
||||||
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
|
|
||||||
];
|
|
||||||
117
config/cache.php
Normal file
117
config/cache.php
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default Cache Store
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option controls the default cache store that will be used by the
|
||||||
|
| framework. This connection is utilized if another isn't explicitly
|
||||||
|
| specified when running a cache operation inside the application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => env('CACHE_STORE', 'database'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Cache Stores
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may define all of the cache "stores" for your application as
|
||||||
|
| well as their drivers. You may even define multiple stores for the
|
||||||
|
| same cache driver to group types of items stored in your caches.
|
||||||
|
|
|
||||||
|
| Supported drivers: "array", "database", "file", "memcached",
|
||||||
|
| "redis", "dynamodb", "octane",
|
||||||
|
| "failover", "null"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'stores' => [
|
||||||
|
|
||||||
|
'array' => [
|
||||||
|
'driver' => 'array',
|
||||||
|
'serialize' => false,
|
||||||
|
],
|
||||||
|
|
||||||
|
'database' => [
|
||||||
|
'driver' => 'database',
|
||||||
|
'connection' => env('DB_CACHE_CONNECTION'),
|
||||||
|
'table' => env('DB_CACHE_TABLE', 'cache'),
|
||||||
|
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
|
||||||
|
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'file' => [
|
||||||
|
'driver' => 'file',
|
||||||
|
'path' => storage_path('framework/cache/data'),
|
||||||
|
'lock_path' => storage_path('framework/cache/data'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'memcached' => [
|
||||||
|
'driver' => 'memcached',
|
||||||
|
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||||
|
'sasl' => [
|
||||||
|
env('MEMCACHED_USERNAME'),
|
||||||
|
env('MEMCACHED_PASSWORD'),
|
||||||
|
],
|
||||||
|
'options' => [
|
||||||
|
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||||
|
],
|
||||||
|
'servers' => [
|
||||||
|
[
|
||||||
|
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('MEMCACHED_PORT', 11211),
|
||||||
|
'weight' => 100,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'redis' => [
|
||||||
|
'driver' => 'redis',
|
||||||
|
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
|
||||||
|
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'dynamodb' => [
|
||||||
|
'driver' => 'dynamodb',
|
||||||
|
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||||
|
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||||
|
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||||
|
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||||
|
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'octane' => [
|
||||||
|
'driver' => 'octane',
|
||||||
|
],
|
||||||
|
|
||||||
|
'failover' => [
|
||||||
|
'driver' => 'failover',
|
||||||
|
'stores' => [
|
||||||
|
'database',
|
||||||
|
'array',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Cache Key Prefix
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
|
||||||
|
| stores, there might be other applications using the same cache. For
|
||||||
|
| that reason, you may prefix every cache key to avoid collisions.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'prefix' => env('CACHE_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-cache-'),
|
||||||
|
|
||||||
|
];
|
||||||
183
config/database.php
Normal file
183
config/database.php
Normal file
|
|
@ -0,0 +1,183 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default Database Connection Name
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which of the database connections below you wish
|
||||||
|
| to use as your default connection for database operations. This is
|
||||||
|
| the connection which will be utilized unless another connection
|
||||||
|
| is explicitly specified when you execute a query / statement.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => env('DB_CONNECTION', 'sqlite'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Database Connections
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Below are all of the database connections defined for your application.
|
||||||
|
| An example configuration is provided for each database system which
|
||||||
|
| is supported by Laravel. You're free to add / remove connections.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'connections' => [
|
||||||
|
|
||||||
|
'sqlite' => [
|
||||||
|
'driver' => 'sqlite',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||||
|
'prefix' => '',
|
||||||
|
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||||
|
'busy_timeout' => null,
|
||||||
|
'journal_mode' => null,
|
||||||
|
'synchronous' => null,
|
||||||
|
'transaction_mode' => 'DEFERRED',
|
||||||
|
],
|
||||||
|
|
||||||
|
'mysql' => [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT', '3306'),
|
||||||
|
'database' => env('DB_DATABASE', 'laravel'),
|
||||||
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
|
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||||
|
'prefix' => '',
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
'strict' => true,
|
||||||
|
'engine' => null,
|
||||||
|
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||||
|
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||||
|
]) : [],
|
||||||
|
],
|
||||||
|
|
||||||
|
'mariadb' => [
|
||||||
|
'driver' => 'mariadb',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT', '3306'),
|
||||||
|
'database' => env('DB_DATABASE', 'laravel'),
|
||||||
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
|
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||||
|
'prefix' => '',
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
'strict' => true,
|
||||||
|
'engine' => null,
|
||||||
|
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||||
|
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||||
|
]) : [],
|
||||||
|
],
|
||||||
|
|
||||||
|
'pgsql' => [
|
||||||
|
'driver' => 'pgsql',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT', '5432'),
|
||||||
|
'database' => env('DB_DATABASE', 'laravel'),
|
||||||
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8'),
|
||||||
|
'prefix' => '',
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
'search_path' => 'public',
|
||||||
|
'sslmode' => 'prefer',
|
||||||
|
],
|
||||||
|
|
||||||
|
'sqlsrv' => [
|
||||||
|
'driver' => 'sqlsrv',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'host' => env('DB_HOST', 'localhost'),
|
||||||
|
'port' => env('DB_PORT', '1433'),
|
||||||
|
'database' => env('DB_DATABASE', 'laravel'),
|
||||||
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8'),
|
||||||
|
'prefix' => '',
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||||
|
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Migration Repository Table
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This table keeps track of all the migrations that have already run for
|
||||||
|
| your application. Using this information, we can determine which of
|
||||||
|
| the migrations on disk haven't actually been run on the database.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'migrations' => [
|
||||||
|
'table' => 'migrations',
|
||||||
|
'update_date_on_publish' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Redis Databases
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Redis is an open source, fast, and advanced key-value store that also
|
||||||
|
| provides a richer body of commands than a typical key-value system
|
||||||
|
| such as Memcached. You may define your connection settings here.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'redis' => [
|
||||||
|
|
||||||
|
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||||
|
|
||||||
|
'options' => [
|
||||||
|
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||||
|
'prefix' => env('REDIS_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-database-'),
|
||||||
|
'persistent' => env('REDIS_PERSISTENT', false),
|
||||||
|
],
|
||||||
|
|
||||||
|
'default' => [
|
||||||
|
'url' => env('REDIS_URL'),
|
||||||
|
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||||
|
'username' => env('REDIS_USERNAME'),
|
||||||
|
'password' => env('REDIS_PASSWORD'),
|
||||||
|
'port' => env('REDIS_PORT', '6379'),
|
||||||
|
'database' => env('REDIS_DB', '0'),
|
||||||
|
'max_retries' => env('REDIS_MAX_RETRIES', 3),
|
||||||
|
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
|
||||||
|
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
|
||||||
|
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
|
||||||
|
],
|
||||||
|
|
||||||
|
'cache' => [
|
||||||
|
'url' => env('REDIS_URL'),
|
||||||
|
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||||
|
'username' => env('REDIS_USERNAME'),
|
||||||
|
'password' => env('REDIS_PASSWORD'),
|
||||||
|
'port' => env('REDIS_PORT', '6379'),
|
||||||
|
'database' => env('REDIS_CACHE_DB', '1'),
|
||||||
|
'max_retries' => env('REDIS_MAX_RETRIES', 3),
|
||||||
|
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
|
||||||
|
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
|
||||||
|
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
80
config/filesystems.php
Normal file
80
config/filesystems.php
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default Filesystem Disk
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the default filesystem disk that should be used
|
||||||
|
| by the framework. The "local" disk, as well as a variety of cloud
|
||||||
|
| based disks are available to your application for file storage.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Filesystem Disks
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Below you may configure as many filesystem disks as necessary, and you
|
||||||
|
| may even configure multiple disks for the same driver. Examples for
|
||||||
|
| most supported storage drivers are configured here for reference.
|
||||||
|
|
|
||||||
|
| Supported drivers: "local", "ftp", "sftp", "s3"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'disks' => [
|
||||||
|
|
||||||
|
'local' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => storage_path('app/private'),
|
||||||
|
'serve' => true,
|
||||||
|
'throw' => false,
|
||||||
|
'report' => false,
|
||||||
|
],
|
||||||
|
|
||||||
|
'public' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => storage_path('app/public'),
|
||||||
|
'url' => env('APP_URL').'/storage',
|
||||||
|
'visibility' => 'public',
|
||||||
|
'throw' => false,
|
||||||
|
'report' => false,
|
||||||
|
],
|
||||||
|
|
||||||
|
's3' => [
|
||||||
|
'driver' => 's3',
|
||||||
|
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||||
|
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||||
|
'region' => env('AWS_DEFAULT_REGION'),
|
||||||
|
'bucket' => env('AWS_BUCKET'),
|
||||||
|
'url' => env('AWS_URL'),
|
||||||
|
'endpoint' => env('AWS_ENDPOINT'),
|
||||||
|
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||||
|
'throw' => false,
|
||||||
|
'report' => false,
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Symbolic Links
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may configure the symbolic links that will be created when the
|
||||||
|
| `storage:link` Artisan command is executed. The array keys should be
|
||||||
|
| the locations of the links and the values should be their targets.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'links' => [
|
||||||
|
public_path('storage') => storage_path('app/public'),
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
157
config/fortify.php
Normal file
157
config/fortify.php
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Fortify\Features;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Fortify Guard
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which authentication guard Fortify will use while
|
||||||
|
| authenticating users. This value should correspond with one of your
|
||||||
|
| guards that is already present in your "auth" configuration file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'guard' => 'web',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Fortify Password Broker
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which password broker Fortify can use when a user
|
||||||
|
| is resetting their password. This configured value should match one
|
||||||
|
| of your password brokers setup in your "auth" configuration file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'passwords' => 'users',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Username / Email
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value defines which model attribute should be considered as your
|
||||||
|
| application's "username" field. Typically, this might be the email
|
||||||
|
| address of the users but you are free to change this value here.
|
||||||
|
|
|
||||||
|
| Out of the box, Fortify expects forgot password and reset password
|
||||||
|
| requests to have a field named 'email'. If the application uses
|
||||||
|
| another name for the field you may define it below as needed.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'username' => 'email',
|
||||||
|
|
||||||
|
'email' => 'email',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Lowercase Usernames
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This value defines whether usernames should be lowercased before saving
|
||||||
|
| them in the database, as some database system string fields are case
|
||||||
|
| sensitive. You may disable this for your application if necessary.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'lowercase_usernames' => true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Home Path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may configure the path where users will get redirected during
|
||||||
|
| authentication or password reset when the operations are successful
|
||||||
|
| and the user is authenticated. You are free to change this value.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'home' => '/',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Fortify Routes Prefix / Subdomain
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which prefix Fortify will assign to all the routes
|
||||||
|
| that it registers with the application. If necessary, you may change
|
||||||
|
| subdomain under which all of the Fortify routes will be available.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'prefix' => '',
|
||||||
|
|
||||||
|
'domain' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Fortify Routes Middleware
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify which middleware Fortify will assign to the routes
|
||||||
|
| that it registers with the application. If necessary, you may change
|
||||||
|
| these middleware but typically this provided default is preferred.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'middleware' => ['web'],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Rate Limiting
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| By default, Fortify will throttle logins to five requests per minute for
|
||||||
|
| every email and IP address combination. However, if you would like to
|
||||||
|
| specify a custom rate limiter to call then you may specify it here.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'limiters' => [
|
||||||
|
'login' => 'login',
|
||||||
|
'two-factor' => 'two-factor',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register View Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify if the routes returning views should be disabled as
|
||||||
|
| you may not need them when building your own application. This may be
|
||||||
|
| especially true if you're writing a custom single-page application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'views' => true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Features
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Some of the Fortify features are optional. You may disable the features
|
||||||
|
| by removing them from this array. You're free to only remove some of
|
||||||
|
| these features, or you can even remove all of these if you need to.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'features' => [
|
||||||
|
Features::registration(),
|
||||||
|
Features::resetPasswords(),
|
||||||
|
Features::emailVerification(),
|
||||||
|
Features::twoFactorAuthentication([
|
||||||
|
'confirm' => true,
|
||||||
|
'confirmPassword' => true,
|
||||||
|
// 'window' => 0
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
55
config/inertia.php
Normal file
55
config/inertia.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Server Side Rendering
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| These options configures if and how Inertia uses Server Side Rendering
|
||||||
|
| to pre-render each initial request made to your application's pages
|
||||||
|
| so that server rendered HTML is delivered for the user's browser.
|
||||||
|
|
|
||||||
|
| See: https://inertiajs.com/server-side-rendering
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'ssr' => [
|
||||||
|
'enabled' => true,
|
||||||
|
'url' => 'http://127.0.0.1:13714',
|
||||||
|
// 'bundle' => base_path('bootstrap/ssr/ssr.mjs'),
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Testing
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The values described here are used to locate Inertia components on the
|
||||||
|
| filesystem. For instance, when using `assertInertia`, the assertion
|
||||||
|
| attempts to locate the component as a file relative to the paths.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'testing' => [
|
||||||
|
|
||||||
|
'ensure_pages_exist' => true,
|
||||||
|
|
||||||
|
'page_paths' => [
|
||||||
|
resource_path('js/pages'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'page_extensions' => [
|
||||||
|
'js',
|
||||||
|
'jsx',
|
||||||
|
'svelte',
|
||||||
|
'ts',
|
||||||
|
'tsx',
|
||||||
|
'vue',
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
132
config/logging.php
Normal file
132
config/logging.php
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Monolog\Handler\NullHandler;
|
||||||
|
use Monolog\Handler\StreamHandler;
|
||||||
|
use Monolog\Handler\SyslogUdpHandler;
|
||||||
|
use Monolog\Processor\PsrLogMessageProcessor;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default Log Channel
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the default log channel that is utilized to write
|
||||||
|
| messages to your logs. The value provided here should match one of
|
||||||
|
| the channels present in the list of "channels" configured below.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => env('LOG_CHANNEL', 'stack'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Deprecations Log Channel
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option controls the log channel that should be used to log warnings
|
||||||
|
| regarding deprecated PHP and library features. This allows you to get
|
||||||
|
| your application ready for upcoming major versions of dependencies.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'deprecations' => [
|
||||||
|
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||||
|
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Log Channels
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may configure the log channels for your application. Laravel
|
||||||
|
| utilizes the Monolog PHP logging library, which includes a variety
|
||||||
|
| of powerful log handlers and formatters that you're free to use.
|
||||||
|
|
|
||||||
|
| Available drivers: "single", "daily", "slack", "syslog",
|
||||||
|
| "errorlog", "monolog", "custom", "stack"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'channels' => [
|
||||||
|
|
||||||
|
'stack' => [
|
||||||
|
'driver' => 'stack',
|
||||||
|
'channels' => explode(',', (string) env('LOG_STACK', 'single')),
|
||||||
|
'ignore_exceptions' => false,
|
||||||
|
],
|
||||||
|
|
||||||
|
'single' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/laravel.log'),
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
'daily' => [
|
||||||
|
'driver' => 'daily',
|
||||||
|
'path' => storage_path('logs/laravel.log'),
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'days' => env('LOG_DAILY_DAYS', 14),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
'slack' => [
|
||||||
|
'driver' => 'slack',
|
||||||
|
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||||
|
'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
|
||||||
|
'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
|
||||||
|
'level' => env('LOG_LEVEL', 'critical'),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
'papertrail' => [
|
||||||
|
'driver' => 'monolog',
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||||
|
'handler_with' => [
|
||||||
|
'host' => env('PAPERTRAIL_URL'),
|
||||||
|
'port' => env('PAPERTRAIL_PORT'),
|
||||||
|
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||||
|
],
|
||||||
|
'processors' => [PsrLogMessageProcessor::class],
|
||||||
|
],
|
||||||
|
|
||||||
|
'stderr' => [
|
||||||
|
'driver' => 'monolog',
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'handler' => StreamHandler::class,
|
||||||
|
'handler_with' => [
|
||||||
|
'stream' => 'php://stderr',
|
||||||
|
],
|
||||||
|
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||||
|
'processors' => [PsrLogMessageProcessor::class],
|
||||||
|
],
|
||||||
|
|
||||||
|
'syslog' => [
|
||||||
|
'driver' => 'syslog',
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
'errorlog' => [
|
||||||
|
'driver' => 'errorlog',
|
||||||
|
'level' => env('LOG_LEVEL', 'debug'),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
'null' => [
|
||||||
|
'driver' => 'monolog',
|
||||||
|
'handler' => NullHandler::class,
|
||||||
|
],
|
||||||
|
|
||||||
|
'emergency' => [
|
||||||
|
'path' => storage_path('logs/laravel.log'),
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
118
config/mail.php
Normal file
118
config/mail.php
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default Mailer
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option controls the default mailer that is used to send all email
|
||||||
|
| messages unless another mailer is explicitly specified when sending
|
||||||
|
| the message. All additional mailers can be configured within the
|
||||||
|
| "mailers" array. Examples of each type of mailer are provided.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'default' => env('MAIL_MAILER', 'log'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Mailer Configurations
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may configure all of the mailers used by your application plus
|
||||||
|
| their respective settings. Several examples have been configured for
|
||||||
|
| you and you are free to add your own as your application requires.
|
||||||
|
|
|
||||||
|
| Laravel supports a variety of mail "transport" drivers that can be used
|
||||||
|
| when delivering an email. You may specify which one you're using for
|
||||||
|
| your mailers below. You may also add additional mailers if needed.
|
||||||
|
|
|
||||||
|
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||||
|
| "postmark", "resend", "log", "array",
|
||||||
|
| "failover", "roundrobin"
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'mailers' => [
|
||||||
|
|
||||||
|
'smtp' => [
|
||||||
|
'transport' => 'smtp',
|
||||||
|
'scheme' => env('MAIL_SCHEME'),
|
||||||
|
'url' => env('MAIL_URL'),
|
||||||
|
'host' => env('MAIL_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('MAIL_PORT', 2525),
|
||||||
|
'username' => env('MAIL_USERNAME'),
|
||||||
|
'password' => env('MAIL_PASSWORD'),
|
||||||
|
'timeout' => null,
|
||||||
|
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
|
||||||
|
],
|
||||||
|
|
||||||
|
'ses' => [
|
||||||
|
'transport' => 'ses',
|
||||||
|
],
|
||||||
|
|
||||||
|
'postmark' => [
|
||||||
|
'transport' => 'postmark',
|
||||||
|
// 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'),
|
||||||
|
// 'client' => [
|
||||||
|
// 'timeout' => 5,
|
||||||
|
// ],
|
||||||
|
],
|
||||||
|
|
||||||
|
'resend' => [
|
||||||
|
'transport' => 'resend',
|
||||||
|
],
|
||||||
|
|
||||||
|
'sendmail' => [
|
||||||
|
'transport' => 'sendmail',
|
||||||
|
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'log' => [
|
||||||
|
'transport' => 'log',
|
||||||
|
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'array' => [
|
||||||
|
'transport' => 'array',
|
||||||
|
],
|
||||||
|
|
||||||
|
'failover' => [
|
||||||
|
'transport' => 'failover',
|
||||||
|
'mailers' => [
|
||||||
|
'smtp',
|
||||||
|
'log',
|
||||||
|
],
|
||||||
|
'retry_after' => 60,
|
||||||
|
],
|
||||||
|
|
||||||
|
'roundrobin' => [
|
||||||
|
'transport' => 'roundrobin',
|
||||||
|
'mailers' => [
|
||||||
|
'ses',
|
||||||
|
'postmark',
|
||||||
|
],
|
||||||
|
'retry_after' => 60,
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Global "From" Address
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You may wish for all emails sent by your application to be sent from
|
||||||
|
| the same address. Here you may specify a name and address that is
|
||||||
|
| used globally for all emails that are sent by your application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'from' => [
|
||||||
|
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||||
|
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
api_platform:
|
|
||||||
title: Buckets API Platform
|
|
||||||
version: 1.0.0
|
|
||||||
defaults:
|
|
||||||
stateless: false
|
|
||||||
cache_headers:
|
|
||||||
vary: ['Content-Type', 'Authorization', 'Origin']
|
|
||||||
formats:
|
|
||||||
jsonld: ['application/ld+json']
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
framework:
|
|
||||||
cache:
|
|
||||||
# Unique name of your app: used to compute stable namespaces for cache keys.
|
|
||||||
#prefix_seed: your_vendor_name/app_name
|
|
||||||
|
|
||||||
# The "app" cache stores to the filesystem by default.
|
|
||||||
# The data in this cache should persist between deploys.
|
|
||||||
# Other options include:
|
|
||||||
|
|
||||||
# Redis
|
|
||||||
#app: cache.adapter.redis
|
|
||||||
#default_redis_provider: redis://localhost
|
|
||||||
|
|
||||||
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
|
||||||
#app: cache.adapter.apcu
|
|
||||||
|
|
||||||
# Namespaced pools use the above "app" backend by default
|
|
||||||
#pools:
|
|
||||||
#my.dedicated.cache: null
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
when@test:
|
|
||||||
dama_doctrine_test:
|
|
||||||
enable_static_connection: true
|
|
||||||
enable_static_meta_data_cache: true
|
|
||||||
enable_static_query_cache: true
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
doctrine:
|
|
||||||
dbal:
|
|
||||||
url: '%env(resolve:DATABASE_URL)%'
|
|
||||||
|
|
||||||
# IMPORTANT: You MUST configure your server version,
|
|
||||||
# either here or in the DATABASE_URL env var (see .env file)
|
|
||||||
#server_version: '16'
|
|
||||||
|
|
||||||
profiling_collect_backtrace: '%kernel.debug%'
|
|
||||||
orm:
|
|
||||||
validate_xml_mapping: true
|
|
||||||
naming_strategy: doctrine.orm.naming_strategy.underscore
|
|
||||||
identity_generation_preferences:
|
|
||||||
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
|
|
||||||
auto_mapping: true
|
|
||||||
mappings:
|
|
||||||
App:
|
|
||||||
type: attribute
|
|
||||||
is_bundle: false
|
|
||||||
dir: '%kernel.project_dir%/src/Entity'
|
|
||||||
prefix: 'App\Entity'
|
|
||||||
alias: App
|
|
||||||
|
|
||||||
when@test:
|
|
||||||
doctrine:
|
|
||||||
dbal:
|
|
||||||
# "TEST_TOKEN" is typically set by ParaTest
|
|
||||||
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
|
|
||||||
|
|
||||||
when@prod:
|
|
||||||
doctrine:
|
|
||||||
orm:
|
|
||||||
query_cache_driver:
|
|
||||||
type: pool
|
|
||||||
pool: doctrine.system_cache_pool
|
|
||||||
result_cache_driver:
|
|
||||||
type: pool
|
|
||||||
pool: doctrine.result_cache_pool
|
|
||||||
|
|
||||||
framework:
|
|
||||||
cache:
|
|
||||||
pools:
|
|
||||||
doctrine.result_cache_pool:
|
|
||||||
adapter: cache.app
|
|
||||||
doctrine.system_cache_pool:
|
|
||||||
adapter: cache.system
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
doctrine_migrations:
|
|
||||||
migrations_paths:
|
|
||||||
# namespace is arbitrary but should be different from App\Migrations
|
|
||||||
# as migrations classes should NOT be autoloaded
|
|
||||||
'DoctrineMigrations': '%kernel.project_dir%/migrations'
|
|
||||||
enable_profiler: false
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
|
||||||
framework:
|
|
||||||
secret: '%env(APP_SECRET)%'
|
|
||||||
|
|
||||||
# Note that the session will be started ONLY if you read or write from it.
|
|
||||||
session:
|
|
||||||
# Same-origin SPA cookie session: not readable by JS, sent on same-site
|
|
||||||
# navigations. cookie_secure: auto → Secure flag only over HTTPS (prod),
|
|
||||||
# so local HTTP dev still works.
|
|
||||||
cookie_httponly: true
|
|
||||||
cookie_samesite: lax
|
|
||||||
cookie_secure: auto
|
|
||||||
|
|
||||||
#esi: true
|
|
||||||
#fragments: true
|
|
||||||
|
|
||||||
when@test:
|
|
||||||
framework:
|
|
||||||
test: true
|
|
||||||
session:
|
|
||||||
storage_factory_id: session.storage.factory.mock_file
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue