Talos Pioneers is the backend API for a blueprint sharing platform for Arknights Endfield. The platform allows players to create, share, like, and comment on game blueprints (base designs/builds) using shareable codes that can be pasted directly into the game. Users can organize blueprints into collections, upload new blueprints, and interact with the community through comments and likes.
- Tech Stack
- Prerequisites
- Installation & Setup
- Environment Variables
- Database
- API Endpoints
- Authentication
- Features & Models
- Development
- Testing
- Permissions & Roles
- Additional Information
- Framework: Laravel 12
- PHP: 8.2+
- Database: SQLite
- Authentication: Laravel Sanctum (Cookied Based)
- OAuth: Laravel Socialite (Discord, Google)
- Testing: Pest PHP 4
- Code Style: Laravel Pint
- Frontend: Vite, Tailwind CSS 4
- Content Moderation: OpenAI API
- Media Management: Spatie Media Library
- Permissions: Spatie Laravel Permission
- Other Packages:
- Spatie Tags
- Spatie Translatable
- Spatie Query Builder
- Spatie Sluggable
- BeyondCode Comments
- Laravel Magic Link
Before you begin, ensure you have the following installed:
- PHP 8.2 or higher
- Composer (PHP dependency manager)
- Node.js and npm (for frontend assets)
- SQLite (for development) or another supported database (MySQL, PostgreSQL)
- OpenAI API Key (optional, for content moderation)
git clone <repository-url>
cd backendInstall PHP dependencies:
composer installInstall Node.js dependencies:
npm installCopy the environment file:
cp .env.example .envGenerate the application key:
php artisan key:generateEdit the .env file with your configuration. See Environment Variables section for details.
Create the database file (if using SQLite):
touch database/database.sqliteRun migrations:
php artisan migrateSeed the database with initial data:
php artisan db:seedThis will seed:
- Roles and permissions (Admin, Moderator, User)
- Initial tags
For development:
npm run devFor production:
npm run buildYou can use the provided setup script that handles most of the above:
composer run setupThis script will:
- Install Composer dependencies
- Copy
.env.exampleto.envif it doesn't exist - Generate application key
- Run migrations
- Install npm dependencies
- Build frontend assets
APP_NAME="Talos Pioneers"
APP_ENV=local
APP_KEY= # Generated via `php artisan key:generate`
APP_DEBUG=true
APP_URL=http://localhost:8000
DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite # For SQLiteSANCTUM_STATEFUL_DOMAINS=localhost,localhost:3000,127.0.0.1,127.0.0.1:8000DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
DISCORD_REDIRECT_URI=http://localhost:8000/auth/discord/callback
DISCORD_AVATAR_GIF=false
DISCORD_EXTENSION_DEFAULT=webpGOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=OPENAI_API_KEY=
AUTO_MOD_ENABLED=trueFRONTEND_URL=http://localhost:3000Run migrations:
php artisan migrateThe application includes the following seeders:
- RolePermissionSeeder: Creates roles (Admin, Moderator, User) and permissions
- TagSeeder: Seeds initial blueprint tags
Run all seeders:
php artisan db:seedRun a specific seeder:
php artisan db:seed --class=RolePermissionSeederKey tables:
users- User accountsblueprints- Game blueprints (base designs)blueprint_collections- Collections of blueprintsblueprint_likes- User likes on blueprintsblueprint_copies- Blueprint copy trackingblueprint_facilities- Blueprint-facility relationshipsblueprint_item_inputs- Blueprint input itemsblueprint_item_outputs- Blueprint output itemscomments- Comments on blueprintsfacilities- Game facilitiesitems- Game itemstags- Tags for categorizationmodel_has_tags- Tag relationshipsroles- User rolespermissions- Permissionsmodel_has_permissions- Permission assignments
All API endpoints are versioned under /api/v1/. Authentication is handled via Laravel Sanctum tokens.
These routes handle user authentication:
| Method | Endpoint | Description |
|---|---|---|
| POST | /login |
User login (email/password) |
| POST | /register |
User registration |
| GET | /auth/{provider}/redirect |
OAuth provider redirect (e.g., Discord) |
| GET | /auth/{provider}/callback |
OAuth provider callback |
These endpoints are publicly accessible:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/blueprints |
List published blueprints (with filtering, sorting, pagination) |
| GET | /api/v1/blueprints/{id} |
Get blueprint details |
Query Parameters for /api/v1/blueprints:
filter[region]- Filter by region (valley_iv, wuling)filter[version]- Filter by game version (cbt_3)filter[is_anonymous]- Filter anonymous blueprints (true/false)filter[author_id]- Filter by author IDfilter[facility]- Filter by facility slugs (comma-separated)filter[item_input]- Filter by input item slugs (comma-separated)filter[item_output]- Filter by output item slugs (comma-separated)filter[tags.id]- Filter by tag IDs (comma-separated)sort- Sort by:created_at,updated_at,title,likes_count,copies_countpage- Page number for pagination
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/collections |
List collections |
| GET | /api/v1/collections/{id} |
Get collection details |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/facilities |
List facilities |
| GET | /api/v1/facilities/{slug} |
Get facility details by slug |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/items |
List items |
| GET | /api/v1/items/{slug} |
Get item details by slug |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/tags |
List tags |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/blueprints/{blueprint}/comments |
List comments for a blueprint |
| GET | /api/v1/blueprints/{blueprint}/comments/{comment} |
Get a specific comment |
These endpoints require authentication via Sanctum token. Include the token in the Authorization header:
Authorization: Bearer {token}
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/profile |
Get authenticated user's profile |
| PUT | /api/v1/profile |
Update authenticated user's profile |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/blueprints |
Create a new blueprint |
| PUT | /api/v1/blueprints/{id} |
Update a blueprint (own or with permission) |
| DELETE | /api/v1/blueprints/{id} |
Delete a blueprint (own or with permission) |
| POST | /api/v1/blueprints/{blueprint}/like |
Like/unlike a blueprint |
| POST | /api/v1/blueprints/{blueprint}/copy |
Copy a blueprint (track usage) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/my/blueprints |
Get authenticated user's blueprints |
| GET | /api/v1/my/collections |
Get authenticated user's collections |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/collections |
Create a new collection |
| PUT | /api/v1/collections/{id} |
Update a collection (own or with permission) |
| DELETE | /api/v1/collections/{id} |
Delete a collection (own or with permission) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/blueprints/{blueprint}/comments |
Create a comment on a blueprint |
| PUT | /api/v1/blueprints/{blueprint}/comments/{comment} |
Update a comment (own or with permission) |
| DELETE | /api/v1/blueprints/{blueprint}/comments/{comment} |
Delete a comment (own or with permission) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/tags |
Create a tag (requires permission) |
| PUT | /api/v1/tags/{id} |
Update a tag (requires permission) |
| DELETE | /api/v1/tags/{id} |
Delete a tag (requires permission) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/users/{user}/upgrade-to-moderator |
Upgrade a user to moderator role (requires permission) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/user |
Get authenticated user (Sanctum) |
| GET | /up |
Health check endpoint |
The API uses Laravel Sanctum for token-based authentication. After logging in via /login or OAuth, you'll receive a token that should be included in subsequent requests:
Authorization: Bearer {your-token-here}The application supports OAuth authentication via Discord and Google, the process is the same :
- Register your application with Discord and Google
- Configure
.envvariables based on .env.example - Set the redirect URI to:
http://your-domain/auth/{provider}/callback - Users can authenticate via:
GET /auth/{provider}/redirect
The application includes support for magic link authentication via cesargb/laravel-magiclink. Users can request a magic link to log in without a password.
Blueprints are the core entity representing game base designs/builds. Each blueprint includes:
- Code: Shareable code that can be pasted into Arknights Endfield
- Title: Blueprint title
- Description: Optional description
- Status:
draft,published, orarchived - Version: Game version (currently
cbt_3) - Region: Game region (
valley_ivorwuling) - Facilities: Associated facilities with quantities
- Item Inputs: Required input items with quantities
- Item Outputs: Produced output items with quantities
- Tags: Categorization tags
- Gallery: Media images
- Is Anonymous: Option to post anonymously
- Creator: User who created the blueprint
- Likes: Users who liked the blueprint
- Copies: Copy tracking for usage statistics
Collections allow users to organize multiple blueprints into groups. Collections can be:
- Public or private
- Shared with the community
- Managed by the creator or moderators/admins
Users can comment on blueprints. Comments support:
- Auto-moderation (via OpenAI)
- Auto-approval for trusted users
- Editing and deletion by comment author or moderators
Tags are used to categorize blueprints. Tags can be:
- Created by users with
manage_tagspermission - Applied to blueprints
- Filtered in blueprint listings
Game data from Arknights Endfield:
- Facilities: Production facilities in the game
- Items: Materials, currency, and other game items
- Both support translations for multi-language support
- Used in blueprints to define inputs/outputs
The application uses a role-based permission system:
- Admin: Full access to all features
- Moderator: Can manage all blueprints, collections, and comments
- User: Standard user with basic permissions
manage_tags- Create, update, delete tagsupgrade_users- Upgrade users to moderatormanage_all_blueprints- Manage any blueprint (not just own)manage_all_collections- Manage any collection (not just own)manage_comments- Manage any comment (not just own)
The application includes OpenAI-powered content moderation for:
- Blueprint titles and descriptions
- Blueprint gallery images
- Comments
Moderation can be enabled/disabled via AUTO_MOD_ENABLED environment variable.
Use the provided development script that runs multiple services concurrently:
composer run devThis runs:
- Laravel development server (
php artisan serve) - Queue worker (
php artisan queue:listen) - Log viewer (
php artisan pail) - Vite dev server (
npm run dev)
Laravel Server:
php artisan serveQueue Worker:
php artisan queue:workVite Dev Server:
npm run devFormat code using Laravel Pint:
vendor/bin/pintFormat only changed files:
vendor/bin/pint --dirtyThe application uses Laravel queues for background jobs. Run the queue worker:
php artisan queue:workOr use the queue listener:
php artisan queue:listenView logs in real-time:
php artisan pailLogs are stored in storage/logs/laravel.log.
Create a migration:
php artisan make:migration create_example_tableCreate a model with migration:
php artisan make:model Example -mCreate a seeder:
php artisan make:seeder ExampleSeederThe application uses Pest PHP 4 for testing.
Run all tests:
php artisan testRun a specific test file:
php artisan test tests/Feature/BlueprintControllerTest.phpRun tests matching a filter:
php artisan test --filter=BlueprintController-
Feature Tests: Located in
tests/Feature/Auth/- Authentication testsBlueprintControllerTest.php- Blueprint API testsBlueprintCollectionControllerTest.php- Collection API testsCommentControllerTest.php- Comment API testsFacilityControllerTest.php- Facility API testsItemControllerTest.php- Item API testsMyBlueprintsControllerTest.php- User blueprints testsMyCollectionsControllerTest.php- User collections testsProfileControllerTest.php- Profile API testsTagControllerTest.php- Tag API testsUserControllerTest.php- User management tests
-
Unit Tests: Located in
tests/Unit/
Tests use an in-memory SQLite database configured in phpunit.xml. The database is automatically migrated and seeded before each test run.
- Models (
app/Models/): Eloquent models representing database entities - Controllers (
app/Http/Controllers/V1/): API controllers organized by version - Requests (
app/Http/Requests/): Form request classes for validation - Resources (
app/Http/Resources/): API resource classes for data transformation - Policies (
app/Policies/): Authorization policies - Services (
app/Services/): Business logic services (e.g., AutoMod) - Enums (
app/Enums/): Type-safe enumerations
-
Admin
- All permissions
- Can manage tags
- Can upgrade users to moderator
- Can manage all blueprints and collections
- Can manage all comments
-
Moderator
- Can manage all blueprints and collections
- Can manage all comments
- Cannot manage tags or upgrade users
-
User
- Can create and manage own blueprints
- Can create and manage own collections
- Can comment on blueprints
- Can like and copy blueprints
Permissions are managed via Spatie Laravel Permission:
- Permissions are defined in
App\Enums\Permission - Roles and permissions are seeded via
RolePermissionSeeder - Policies enforce permissions at the controller level
Content moderation is powered by OpenAI's moderation API:
- Validates blueprint titles, descriptions, and images
- Validates comments
- Can be enabled/disabled via
AUTO_MOD_ENABLED - Requires
OPENAI_API_KEYwhen enabled
The application uses Spatie Media Library for managing blueprint gallery images:
- Images are stored in
storage/app/public - Automatic image conversions (thumbnails, optimized versions)
- WebP format for optimized images
- Gallery images are associated with blueprints
Game data (facilities and items) supports translations:
- Uses Spatie Translatable
- Supports multiple locales
- Translation files in
lang/directory
The API is versioned under /api/v1/. Future versions can be added by creating new route files in routes/api/.
- Regions:
- Valley IV
- Wuling
- Game Version: Currently supports CBT_3 (Closed Beta Test 3)
Blueprints contain a code field that stores the shareable code. This code can be copied from the game and pasted into the platform, or copied from the platform and pasted into the game.
This is a multi-developer project. When contributing:
- Follow Laravel conventions
- Write tests for new features
- Run
vendor/bin/pintbefore committing - Ensure all tests pass:
php artisan test - Follow the existing code structure and patterns
TBD