Tea Charlie is a Swift Vapor web application backend that provides a RESTful API for managing user accounts, authentication, and tea-related game data. The application uses PostgreSQL for data persistence with Fluent ORM.
- User Authentication: JWT-like session token system with multi-device support (up to 3 concurrent sessions)
- Real-time Updates: WebSocket integration for live position tracking
- Game Data Management: User positions, coins, tea creation, and achievements
- Statistics: User and session analytics
- Security: Password hashing, token-based authentication, environment-based secrets
- CORS Support: Configured for cross-origin requests
- Swift 6.0+
- PostgreSQL database
- Docker (optional, for containerized deployment)
-
Clone the repository
git clone <repository-url> cd backend
-
Set up environment variables
cp .env.example .env # Edit .env with your database configuration -
Install dependencies and build
swift build
-
Run database migrations
swift run backend migrate --yes
-
Start the server
swift run backend serve --env development --hostname 0.0.0.0 --port 8080
-
Start with Docker Compose
# Start database and application docker compose up app # Or start only database docker compose up db
-
Run migrations
docker compose run migrate
| Variable | Description | Default |
|---|---|---|
DB_USERNAME |
Database username | - |
DB_PASSWORD |
Database password | - |
DB_NAME |
Database name | - |
DB_HOSTNAME |
Database host | localhost |
DB_PORT |
Database port | 5432 |
DB_DELETE_TOKEN |
Database deletion operations token | - |
DB_WRITE_TOKEN |
Database write operations token | - |
ADMIN_PANEL_TOKEN |
Admin panel access token | - |
MAX_LOGIN_DEVICES |
Maximum concurrent login sessions per user | 3 |
DEFAULT_COINS |
Starting coins for new users | 400 |
LOGIN_TOKEN_TTL |
Token time-to-live in days | 7 |
POST /auth/register- User registrationPOST /auth/login- User authenticationPOST /auth/logout- Session terminationGET /auth/validate- Token validation
GET /user/position- Get user positionPUT /user/move- Update user positionGET /user/coins- Get user coinsPUT /user/coins- Update user coinsWS /user/position/ws- Real-time position updates
GET /stats/users- User and session statistics
Detailed API documentation is available in the docs/ directory:
- Entry Point:
Sources/backend/entrypoint.swift- Main application entry point - Configuration:
Sources/backend/configure.swift- Database setup and middleware - Routes:
Sources/backend/routes.swift- API route definitions - Controllers: User authentication, data management, and statistics
- Models: Core data models with Fluent ORM
- Migrations: Database schema definitions
- users - User accounts (email, password, username)
- tokens - Session management tokens
- user_data - Game data (coins, position, achievements)
# Build the application
swift build
# Run in development mode
swift run backend serve --env development --hostname 0.0.0.0 --port 8080
# Run database migrations
swift run backend migrate --yes
# Revert migrations
swift run backend migrate --revert --yes# Build Docker images
docker compose build
# Start services
docker compose up app
# Stop services
docker compose down
# Stop services and remove volumes
docker compose down -v- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
© Makabaka1880, 2025. All rights reserved.