_Built with:_
I. π Overview II. πΎ Features III. π Project Structure IV. π Getting Started V. π§ Configuration VI. π‘ API Endpoints VII. π° Contributing VIII. π License
PleFi is a service that integrates Stripe payment processing with Plex media server, enabling subscription-based access management for Plex servers. It provides user authentication, payment handling, and subscription management to automate Plex server access control.
Feature | Summary | |
---|---|---|
π | Authentication |
|
π³ | Payments |
|
π | Webhooks |
|
π οΈ | Configuration |
|
π | API |
|
plefi
βββ internal/ # Backend application code
β βββ config/ # Configuration files and setup
β β βββ config.go
β β βββ default.yaml
β β βββ development.yaml
β βββ controllers/ # Request handlers
β β βββ controller.go
β β βββ api/
β β β βββ controller.go
β β βββ plex/
β β β βββ controller.go
β β βββ stripe/
β β βββ controller.go
β βββ model/ # Data models
β β βββ user_info.go
β βββ services/ # Service implementations
β β βββ services.go
β β βββ plex.go
β βββ views/ # HTML templates
β β βββ index.tmpl
β β βββ stripe_success.tmpl
β β βββ stripe_cancel.tmpl
β βββ router.go # Route definitions
β βββ main.go # Application entry point
βββ go.mod # Go module definition
βββ go.sum # Go dependency checksums
βββ Dockerfile # Container definition
βββ .env # Environment variables (not in git)
βββ .gitignore # Git ignore rules
βββ frontend/ # React frontend application
β βββ public/ # Static assets & index.html
β βββ src/ # React source code (pages, components, styles)
β βββ webpack.config.js # Frontend build configuration
β βββ package.json # Frontend dependencies & scripts
β βββ ... # other frontend files
βββ README.md # Project documentation
PleFi/
__root__
server.go Server initialization with graceful shutdown Dockerfile Container definition for building and running the PleFi application go.mod Go module definition specifying dependencies go.sum Go dependency checksums ensuring consistent builds
api/
config/
config.go Configuration initialization and management from files and environment variables default.yaml Default configuration values for all environments development.yaml Development-specific configuration settings controllers/
controller.go Main application controller handling common functionality api/
controller.go API controller implementation for general endpoints plex/
controller.go Plex controller handling OAuth authentication stripe/
controller.go Stripe controller for payment processing and webhooks services/
services.go Service container for dependency injection plex.go Plex service for interacting with Plex API views/
index.tmpl Main landing page template stripe_success.tmpl Subscription success page stripe_cancel.tmpl Subscription cancellation page model/
user_info.go User information model router.go
router.go Route definitions main.go
main.go Application entry point that initializes configuration, services, and the HTTP server
frontend/
public/ Static assets & index.html src/ React source code (pages, components, styles) webpack.config.js Frontend build configuration package.json Frontend dependencies & scripts
Before getting started with PleFi, ensure your runtime environment meets the following requirements:
- Go 1.24 or higher
- Node.js 16+
- npm or Yarn
- Stripe account with webhook setup
- Plex account and server (optional for development)
-
Clone the repository:
β― git clone https://github.com/mchestr/plefi.git β― cd plefi
-
Install backend dependencies:
β― go mod download
-
Create a
.env
file in the project root with your configuration:β― cat > .env << EOL PLEFI_STRIPE__SECRET_KEY="sk_test_your_stripe_secret_key" PLEFI_STRIPE__WEBHOOK_SECRET="whsec_your_stripe_webhook_secret" PLEFI_STRIPE__DEFAULT_PRICE_ID="price_your_default_price_id" PLEFI_PLEX__CLIENT_ID="your_plex_client_id" PLEFI_PLEX__PRODUCT="Your Plex Server Name" PLEFI_SERVER__HOSTNAME="your-server-hostname.com" PLEFI_SERVER__SESSION_SECRET="generate_a_random_secret_key" PLEFI_SERVER__MODE="development" EOL
-
Install frontend dependencies:
β― cd frontend β― npm install
-
Return to the root:
β― cd ..
Run frontend in development mode:
β― cd frontend
β― npm run start
Run backend locally:
β― go run api/main.go
Run backend in development mode:
β― go run api/main.go -e development
Using Docker:
β― docker build -t plefi .
β― docker run -p 8080:8080 --env-file .env plefi
PleFi uses a hierarchical configuration system:
- Default values
- Configuration files in
api/config/
directory - Environment variables (prefixed with
PLEFI_
)
Server Configuration
PLEFI_SERVER__MODE
- Server mode (debug, release)PLEFI_SERVER__ADDRESS
- Server bind address (default::8080
)PLEFI_SERVER__HOSTNAME
- Server hostname for callbacksPLEFI_SERVER__SESSION_SECRET
- Secret for session encryptionPLEFI_SERVER__TRUSTED_PROXIES
- Comma-separated list of trusted proxy IPs
Stripe Configuration
PLEFI_STRIPE__SECRET_KEY
- Stripe API secret keyPLEFI_STRIPE__WEBHOOK_SECRET
- Stripe webhook signing secretPLEFI_STRIPE__DEFAULT_PRICE_ID
- Default subscription price ID
Plex Configuration
PLEFI_PLEX__CLIENT_ID
- Plex client identifierPLEFI_PLEX__PRODUCT
- Plex product name
Logging Configuration
PLEFI_LOG__LEVEL
- Logging level (debug, info, warn, error)PLEFI_LOG__FORMAT
- Logging format (json, text)
Application
GET /
- Landing pageGET /health
- Health check endpoint
Plex Authentication
GET /plex/auth
- Initiate Plex authenticationGET /plex/callback
- Plex authentication callback
Stripe
POST /stripe/webhook
- Stripe webhook endpoint for subscription eventsGET /stripe/checkout
- Create a Stripe checkout session for subscriptionGET /stripe/success
- Handle successful subscription checkoutGET /stripe/cancel
- Handle cancelled subscription checkout
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your GitHub account.
- Clone Locally: Clone the forked repository to your local machine.
git clone https://github.com/yourusername/plefi.git
- Create a New Branch: Always work on a new branch.
git checkout -b feature/amazing-feature
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message.
git commit -m 'Add amazing feature'
- Push to GitHub: Push the changes to your forked repository.
git push origin feature/amazing-feature
- Submit a Pull Request: Create a PR against the original project repository.
See the LICENSE file for details.