Backend API built with Laravel 12 for two modules currently present in codebase:
- Trello-style project/task management (Sanctum protected)
- Job board search + AI summary endpoints (public, throttled)
- PHP 8.2+
- Laravel 12
- MySQL 8
- Laravel Sanctum (token auth)
- Laravel Scout + Meilisearch (job search)
- Redis/Cache support
- Pest + PHPUnit for testing
- Docker / Docker Compose
- GitHub Actions CI/CD
- Terraform (AWS EC2 + Security Group)
- Kubernetes manifest (MySQL deployment/service)
POST /api/auth/registerPOST /api/auth/loginGET /api/auth/me(auth:sanctum)POST /api/auth/logout(auth:sanctum)- Project CRUD under
/api/projects - Task CRUD under
/api/projects/{project}/tasks - Task statuses endpoint:
GET /api/statuses - Policy-based authorization for user-owned resources
- Form Request validation + unified API error responses
All under throttle:60,1:
GET /api/jobs(supportssearch,location,per_page)POST /api/jobsPOST /api/jobs/{id}/summarizeGET /api/jobs/{id}/summary
Details:
- Search uses Scout (
Job::search) and Meilisearch driver in normal env. - Summary generation uses queued
SummarizeJobwith retry/backoff. - AI abstraction via
AIServiceInterfacebound toGeminiService. - Summary is cached (
job_summary_{id}, TTL 1 hour).
Global custom middleware:
X-Frame-Options: DENYX-Content-Type-Options: nosniffX-XSS-Protection: 1; mode=block
Configured in bootstrap/app.php.
Base URL:
http://127.0.0.1:8000Set token after login/register:
TOKEN="paste_your_bearer_token_here"POST /api/auth/register
curl -X POST http://127.0.0.1:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"name":"Aldo",
"email":"[email protected]",
"password":"Password123!",
"password_confirmation":"Password123!"
}'POST /api/auth/login
curl -X POST http://127.0.0.1:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email":"[email protected]",
"password":"Password123!"
}'GET /api/auth/me
curl http://127.0.0.1:8000/api/auth/me \
-H "Authorization: Bearer $TOKEN"POST /api/auth/logout
curl -X POST http://127.0.0.1:8000/api/auth/logout \
-H "Authorization: Bearer $TOKEN"GET /api/projects
curl http://127.0.0.1:8000/api/projects \
-H "Authorization: Bearer $TOKEN"POST /api/projects
curl -X POST http://127.0.0.1:8000/api/projects \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name":"Sprint Board",
"description":"Tasks for sprint 1"
}'GET /api/projects/{project}
curl http://127.0.0.1:8000/api/projects/1 \
-H "Authorization: Bearer $TOKEN"PUT /api/projects/{project}
curl -X PUT http://127.0.0.1:8000/api/projects/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name":"Sprint Board v2",
"description":"Updated sprint board"
}'DELETE /api/projects/{project}
curl -X DELETE http://127.0.0.1:8000/api/projects/1 \
-H "Authorization: Bearer $TOKEN"GET /api/statuses
curl http://127.0.0.1:8000/api/statuses \
-H "Authorization: Bearer $TOKEN"GET /api/projects/{project}/tasks
curl http://127.0.0.1:8000/api/projects/1/tasks \
-H "Authorization: Bearer $TOKEN"POST /api/projects/{project}/tasks
curl -X POST http://127.0.0.1:8000/api/projects/1/tasks \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title":"Build login page",
"description":"Implement login UI + validation",
"status":"pending",
"due_date":"2026-03-10"
}'GET /api/projects/{project}/tasks/{task}
curl http://127.0.0.1:8000/api/projects/1/tasks/1 \
-H "Authorization: Bearer $TOKEN"PUT /api/projects/{project}/tasks/{task}
curl -X PUT http://127.0.0.1:8000/api/projects/1/tasks/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title":"Build login page",
"description":"Done backend integration",
"status":"in_progress"
}'DELETE /api/projects/{project}/tasks/{task}
curl -X DELETE http://127.0.0.1:8000/api/projects/1/tasks/1 \
-H "Authorization: Bearer $TOKEN"GET /api/jobs
curl "http://127.0.0.1:8000/api/jobs?search=laravel&location=remote&per_page=10"POST /api/jobs
curl -X POST http://127.0.0.1:8000/api/jobs \
-H "Content-Type: application/json" \
-d '{
"title":"Laravel Developer",
"location":"Remote",
"description":"Build and maintain Laravel APIs",
"company_id":1
}'POST /api/jobs/{id}/summarize
curl -X POST http://127.0.0.1:8000/api/jobs/1/summarizeGET /api/jobs/{id}/summary
curl http://127.0.0.1:8000/api/jobs/1/summary- Install dependencies
composer install- Copy env and configure
cp .env.example .envSet at minimum:
APP_NAME=TrelloLite
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=trello_test_aldo
DB_USERNAME=root
DB_PASSWORD=
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=masterKey
GEMINI_API_KEY=- App key + migrate
php artisan key:generate
php artisan migrate- Run app
php artisan serve- Docker with the Compose plugin (
docker compose version). - Ports free on the host: HTTP (see
APP_PORTbelow, default 8080), 7700 (Meilisearch), 6380 (Redis mapped from container 6379).
| Service | Role |
|---|---|
nginx-gateway |
Nginx → app:9000 (PHP-FPM); publishes ${APP_PORT:-80}:80 |
app |
Laravel (PHP-FPM) |
worker |
php artisan queue:work (queues, e.g. job summaries) |
db |
MySQL 8 (master / writes) |
mysql-slave |
MySQL 8 (read replica; manual sync—see below) |
redis |
Cache, sessions, queues |
meilisearch |
Scout search |
From the project root:
cp .env.example .envFor containers talking to each other on the Compose network, set service names as hosts (not 127.0.0.1). Align DB credentials with docker-compose.yml (MYSQL_* on the db service: database trello_test_aldo, user/password root / root as configured there).
Minimal Docker-oriented values (adjust APP_PORT / APP_URL if you change the host port):
APP_URL=http://localhost:8080
APP_PORT=8080
DB_CONNECTION=mysql
DB_HOST=db
# Local dev without replication: use `db` so reads see migrated tables. Use `mysql-slave` only after syncing (see "MySQL Master/Slave").
DB_SLAVE_HOST=db
DB_PORT=3306
DB_DATABASE=trello_test_aldo
DB_USERNAME=root
DB_PASSWORD=root
REDIS_HOST=redis
REDIS_PORT=6379
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700
MEILISEARCH_KEY=masterKey
GEMINI_API_KEY= # required for /api/jobs/{id}/summarize when using the default AI bindingdocker compose up -d --buildapp and worker use a named Docker volume for vendor/ so Composer packages are not read from the Windows/macOS bind mount (that mount is very slow for thousands of PHP files). The copy of vendor/ on your laptop is ignored inside the container—always install and update PHP dependencies in the container:
docker compose exec app composer install
# After changing composer.json / composer.lock on the host:
docker compose exec app composer updateRebuild images after Dockerfile changes: docker compose build --no-cache app worker (or docker compose up -d --build).
If API times are seconds while SQL is only milliseconds:
vendor/volume (above) avoids slow cross-OS file I/O for dependencies.- Telescope: keep
TELESCOPE_ENABLED=truewhile debugging or demoing (request/query inspection). Setfalseonly when you want to measure raw API speed—Telescope records every request and adds overhead by design. - Best: keep the project clone on the Linux filesystem inside WSL2 (e.g.
~/projects/...), not onD:\mounted as/mnt/d, for the fastest bind mount. - Rebuild after this repo’s Docker changes:
docker compose up -d --build.
Wait a few seconds for MySQL to accept connections, then:
docker compose exec app php artisan key:generate
docker compose exec app php artisan migrateOptional: if you use Scout with jobs data, import the index when needed (use the short model name so Scout resolves App\Models\Job correctly; avoid passing the full class in PowerShell):
docker compose exec app php artisan scout:import Job- HTTP base URL:
http://localhost:8080ifAPP_PORT=8080in.env(orhttp://localhostifAPP_PORTis unset and Compose defaults to port 80). - Meilisearch UI / host access:
http://127.0.0.1:7700(mapped in Compose). - Redis from the host:
127.0.0.1:6380(container Redis is stillredis:6379from PHP).
Example:
curl http://127.0.0.1:8080/api/jobsdocker compose logs -f app worker
docker compose exec app php artisan tinker
docker compose downThe worker service runs the queue; job summarization and other queued work need it running (included in docker compose up).
This project uses Laravel read/write splitting on the mysql connection:
- write host:
DB_HOST=db(master) - read host:
DB_SLAVE_HOST=mysql-slave(slave) sticky=trueis enabled- non-Docker/CI fallback: set
DB_SLAVE_HOST=127.0.0.1(or same asDB_HOST)
Important:
DB::connection()->getConfig('host')is config fallback only.- To verify real active server, query
@@hostnamefrom write/read PDO.
docker-compose.yml stores data under the project directory:
- Master:
./mysql-data→/var/lib/mysqlondb - Slave:
./mysql-slave→/var/lib/mysqlonmysql-slave
Docker creates these folders on first start. To use fixed paths on another drive (e.g. D:\docker-data\...), change the volume entries in docker-compose.yml and create those directories before docker compose up.
- Check container hostnames in PowerShell:
docker inspect -f "{{.Config.Hostname}}" laravel-db
docker inspect -f "{{.Config.Hostname}}" laravel-db-slave- Open tinker inside Docker app container:
docker compose exec app php artisan tinker- In Tinker, check write and read hosts:
DB::connection('mysql')->getPdo()->query("select @@hostname")->fetchColumn(); // write PDO (master)
DB::connection('mysql')->getReadPdo()->query("select @@hostname")->fetchColumn(); // read PDO (slave)If the returned hostname matches:
laravel-dbhostname => masterlaravel-db-slavehostname => slave
Since replication is not configured, run manual sync after schema/data changes:
.\scripts\sync-master-to-slave.ps1Typical flow:
docker compose exec app php artisan migrate(master only).\scripts\sync-master-to-slave.ps1
# Run the full test suite (SQLite in-memory, no external services needed)
docker compose exec app php artisan test
# Security audit only
docker compose exec app composer audit
# Both together (mirrors CI)
docker compose exec app composer audit && docker compose exec app php artisan testThe test job in .github/workflows/deploy.yml runs on every push/PR to main with real MySQL + Meilisearch service containers, composer audit, and php artisan test.
- Feature:
JobSearchTest,SecurityTest - Unit:
JobServiceTest
Test environment notes:
phpunit.xmluses SQLite in-memorySCOUT_DRIVER=collectionin tests (prevents Meilisearch dependency)
GET /api/db-check — verifies that Laravel's read/write splitting is active and that the write connection hits the RDS master while the read connection hits the replica.
Example response when replication is active:
{
"read_write_splitting": true,
"write_connection": { "hostname": "ip-10-0-...", "read_only": "OFF", "role": "MASTER" },
"read_connection": { "hostname": "ip-10-0-...", "read_only": "ON", "role": "SLAVE" },
"config": { "DB_HOST": "...master...", "DB_SLAVE_HOST": "...replica...", "sticky": true }
}When both point to the same host (replica disabled), read_write_splitting returns false and both roles show MASTER.
To enable the replica: set enable_rds_read_replica = true in terraform.tfvars, run terraform apply, then update DB_SLAVE_HOST in the SSM parameter to the replica endpoint from terraform output rds_replica_endpoint.
- OpenAPI file:
docs/swagger.yaml - Source of truth is split for readability:
docs/swagger.yaml(root)docs/paths/*.yaml(auth, projects, tasks, jobs)docs/components.yaml(index)docs/schemas/*.yaml(common, auth, projects, tasks, jobs)
- Web route for docs UI page:
/docs - Swagger file route:
/docs/swagger.yaml
Workflow: .github/workflows/deploy.yml
test— on push/PR tomain: MySQL + Meilisearch services,composer audit,php artisan testdeploy— on push tomainonly:aws deploy create-deployment(CodeDeploy revision from GitHub), then waits until deployment succeeds
AWS setup (new IAM, CodeDeploy agent, SSM, Terraform): see docs/DEPLOY.md.
Upon every git push, the scripts/restart_server.sh automation script executes the following lifecycle:
- Dynamic Secrets Retrieval: Securely pulls production environment variables from AWS SSM Parameter Store.
- Container Orchestration: Triggers automated rebuilds and force-recreates the service stack to ensure environment parity and clean deployment.
- Automated Post-Deployment Hooks:
- Optimization: Optimizes Composer autoloader for production performance.
- Security & Cache: stable
APP_KEYfrom SSM; config/route/view cache after deploy. - Database Integrity: Executes automated database migrations exclusively on the Master node.
This project is deployed using a High-Availability (HA) architecture on AWS, focusing on security, resilience, and scalability:
- Deployment Strategy: Fully automated pipeline via GitHub Actions and AWS CodeDeploy, implementing a Zero-Downtime deployment mindset.
- Dynamic Secret Management: Integrated with AWS SSM Parameter Store. Sensitive credentials are never stored in the repository or hardcoded on the server; they are fetched dynamically into the container environment at runtime.
- Database Scalability: Implements MySQL Master-Slave Replication with Read/Write Splitting. The application intelligently routes write operations to the Master node and read queries to the Slave replicas to optimize performance.
- Reverse Proxy: A dedicated Nginx Docker container serves as the primary gateway, handling traffic routing on port 80.
- Self-Hosted Runner: Deployment orchestration is managed via a dedicated runner configured on an EC2 instance, providing full control over the build environment and security.
graph TD
User((User/Client)) -->|Port 80| Nginx[Nginx Container]
subgraph "EC2 Instances (Multi-AZ)"
Nginx -->|Proxy Pass| App[Laravel App Container]
App -->|Fetch at Runtime| SSM[AWS SSM Parameter Store]
App -->|Jobs/Cache| Redis[(Redis Container)]
App -->|Search Index| Meili[(Meilisearch Container)]
end
subgraph "Database Layer (AWS RDS Master-Slave)"
App -->|Write Ops| Master[(MySQL Master)]
App -->|Read Ops| Slave[(MySQL Slave)]
Master -.->|Replication| Slave
end
subgraph "CI/CD Pipeline"
GH[GitHub Repo] -->|Push| GHA[GitHub Actions]
GHA -->|Trigger| CD[AWS CodeDeploy]
CD -->|Execute| Script[restart_server.sh]
Script -->|Inject| SSM
end
To keep this README concise, Terraform commands are documented in:
Quick start:
cd terraform
terraform init
terraform plan
terraform apply
terraform output- Terraform:
terraform/main.tf- 2 EC2 instances (instance type from
terraform/variables.tf) - Security group allowing inbound 80/tcp
- 2 EC2 instances (instance type from
- Kubernetes:
k8s/mysql-deployment.yml- MySQL Deployment + Service
app/Http/Controllers(Auth, Project, Task, Job)app/Http/Requests(validation, includingStoreJobRequest)app/Services(JobService,GeminiService, others)app/Jobs/SummarizeJob.phpapp/Http/Middleware/SecurityHeaders.phproutes/api.phproutes/web.phptests/Feature,tests/Unitdocs/swagger.yaml