💧 A Vapor Swift backend for ProxLock, providing API proxy functionality with authentication, device validation, and usage tracking.
This is the backend service for ProxLock, built with the Vapor web framework. It provides a robust API proxy solution with features including:
- User authentication via Clerk
- API key management
- Device validation using Apple DeviceCheck
- Project and usage tracking
- Request proxying with rate limiting
Before you begin, ensure you have the following installed:
- Swift 6.1+ - Download Swift
- PostgreSQL 16+ - Download PostgreSQL
- macOS 13+ (for local development)
- Docker (optional, for containerized development)
-
Clone the repository
git clone <repository-url> cd backend
-
Install dependencies
swift package resolve
-
Set up PostgreSQL database
Create a PostgreSQL database for the application:
createdb proxlock_dev
-
Configure environment variables
Create a
.envfile in the root directory with the following variables:DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=proxlock_dev DATABASE_USERNAME=your_postgres_username DATABASE_PASSWORD=your_postgres_password CLERK_WEBHOOK_SECRET=your_clerk_webhook_secret
-
Run database migrations
The application will automatically run migrations on startup, or you can run them manually:
swift run ProxLock migrate
-
Start the server
swift run
The server will start on
http://localhost:8080by default.
-
Set up environment variables
Create a
.envfile or export the following environment variables:export DATABASE_NAME=proxlock export DATABASE_USERNAME=vapor export DATABASE_PASSWORD=password export CLERK_WEBHOOK_SECRET=your_clerk_webhook_secret
-
Build and start services
docker compose build docker compose up
-
Access the application
The API will be available at
http://localhost:8080
| Variable | Description | Required | Default |
|---|---|---|---|
DATABASE_HOST |
PostgreSQL hostname | No | localhost |
DATABASE_PORT |
PostgreSQL port | No | 5432 |
DATABASE_NAME |
Database name | Yes | - |
DATABASE_USERNAME |
Database username | Yes | - |
DATABASE_PASSWORD |
Database password | Yes | - |
CLERK_WEBHOOK_SECRET |
Clerk webhook secret for authentication | Yes | - |
swift buildswift runswift testswift run ProxLock migrateswift run ProxLock migrate --revertbackend/
├── Sources/
│ └── ProxLock/
│ ├── Controllers/ # Request handlers
│ ├── DTOs/ # Data transfer objects
│ ├── Middlewear/ # Custom middleware
│ ├── Migrations/ # Database migrations
│ ├── Models/ # Database models
│ ├── Webhooks/ # Webhook handlers
│ ├── configure.swift # Application configuration
│ ├── entrypoint.swift # Application entry point
│ └── routes.swift # Route definitions
├── Tests/ # Test files
├── Dockerfile # Docker build configuration
├── docker-compose.yml # Docker Compose configuration
└── Package.swift # Swift package dependencies
We welcome contributions to ProxLock! Here's how you can help:
-
Fork the repository and clone your fork
-
Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name # or git checkout -b fix/your-bug-fix -
Make your changes following these guidelines:
- Follow Swift style conventions
- Write clear, descriptive commit messages
- Add comments for complex logic
- Ensure your code compiles without warnings
-
Test your changes
- Run the test suite:
swift test - Test manually if applicable
- Ensure migrations work correctly if you've modified the database schema
- Run the test suite:
-
Submit a pull request
- Push your branch to your fork
- Create a pull request with a clear description of your changes
- Reference any related issues
- Use Swift 6.1+ features and best practices
- Follow Vapor conventions for route and controller structure
- Keep controllers focused and single-responsibility
- Use DTOs for request/response data
- Add appropriate error handling
- Document public APIs and complex logic
If you're modifying the database schema:
- Create a new migration in the respective model's file within
Sources/ProxLock/Migrations/ - Follow the existing migration patterns
- Test migrations both forward and backward
- Update model files if needed
- Write tests for new features when possible
- Ensure existing tests pass
- Test edge cases and error conditions
If you have questions or need help, please:
- Open an issue for bugs or feature requests
- Check existing issues and discussions
- Review the Vapor documentation
See the License file for details.