A Vapor-based backend server for the MahJong Scores iOS application, using SwiftOpenAPI for type-safe API implementation.
- RESTful API for tournament management
- SwiftOpenAPI-generated types and routes from OpenAPI specification
- In-memory storage (can be replaced with a database)
- CORS enabled for development
- Swift 6.2 or later
- macOS 14.0 or later
- Navigate to the backend directory:
cd /Users/rob/Projects/Swift/Apps/MahJongScoresBackend- Resolve dependencies:
swift package resolve- Build the project:
swift buildStart the server with:
swift runThe server will start on http://localhost:8080
GET /tournaments
POST /tournaments
Content-Type: application/json
{
"id": "uuid-string",
"scheduleItem": 0,
"ruleSet": "INTERNATIONAL",
"fpName": "Player 1",
"spName": "Player 2",
...
}
GET /tournaments/{tournamentId}
PUT /tournaments/{tournamentId}
Content-Type: application/json
{
"id": "uuid-string",
...
}
DELETE /tournaments/{tournamentId}
The API is defined in Sources/MahJongScoresBackend/openapi.yaml. When you modify this file:
- The SwiftOpenAPI generator plugin will automatically regenerate types and protocol
- Update the
TournamentAPIHandler.swiftto implement any new endpoints - Rebuild the project
The iOS app includes:
TournamentDTO.swift- Codable transfer objects for JSON serializationTournamentAPIService.swift- API client for communicating with the backendSyncTournamentView.swift- UI for uploading tournaments to the server
To sync tournaments from the iOS app:
- Open the app
- Tap the sync button in the toolbar
- Configure the server URL (default: http://localhost:8080)
- Select tournaments to upload
- Tap "Upload"
MahJongScoresBackend/
├── Package.swift # Swift package manifest
├── Sources/
│ └── MahJongScoresBackend/
│ ├── MahJongScoresBackend.swift # Main application entry point
│ ├── TournamentAPIHandler.swift # API implementation
│ ├── openapi.yaml # OpenAPI specification
│ └── openapi-generator-config.yaml # Generator configuration
└── README.md
Before deploying to production:
- Replace in-memory storage with a proper database (PostgreSQL, MySQL, etc.)
- Add authentication and authorization
- Configure CORS to only allow your app's domain
- Add logging and monitoring
- Set up SSL/TLS for HTTPS
- Add rate limiting to prevent abuse
- Implement proper error handling and validation
This project is part of the MahJong Scores application.