https://github.com/mchestr/plefi
Plex Subscriptions Management
https://github.com/mchestr/plefi
docker golang plex stripe
Last synced: 4 months ago
JSON representation
Plex Subscriptions Management
- Host: GitHub
- URL: https://github.com/mchestr/plefi
- Owner: mchestr
- License: mit
- Created: 2025-04-13T02:46:27.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-06T16:12:26.000Z (8 months ago)
- Last Synced: 2025-11-06T18:14:05.225Z (8 months ago)
- Topics: docker, golang, plex, stripe
- Language: JavaScript
- Homepage:
- Size: 22 MB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[
]()
# `PleFi`
#### Integrate Stripe payments with Plex servers for subscription-based access!
_Built with:_
## 🔗 Table of Contents
I. [📍 Overview](#-overview)
II. [👾 Features](#-features)
III. [📁 Project Structure](#-project-structure)
IV. [🚀 Getting Started](#-getting-started)
V. [🔧 Configuration](#-configuration)
VI. [📡 API Endpoints](#-api-endpoints)
VII. [🔰 Contributing](#-contributing)
VIII. [🎗 License](#-license)
---
## 📍 Overview
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.
---
## 👾 Features
| | Feature | Summary |
| :--- | :---: | :--- |
| 🔐 | **Authentication** |
- Plex user authentication using OAuth
- Secure session management with encryption
| 💳 | **Payments** |
- Stripe subscription management and payment processing
- Configurable subscription plans
| 🔄 | **Webhooks** |
- Webhook support for Stripe events
- Automated user access management based on subscription status
| 🛠️ | **Configuration** |
- Hierarchical configuration system with environment variables
- Development and production modes
| 🔌 | **API** |
- RESTful endpoints for authentication and payment flows
- Health check endpoints for monitoring
---
## 📁 Project Structure
```sh
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
```
### 📂 Project Index
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
---
## 🚀 Getting Started
### ☑️ Prerequisites
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)
### ⚙️ Installation
1. Clone the repository:
```sh
❯ git clone https://github.com/mchestr/plefi.git
❯ cd plefi
```
2. Install backend dependencies:
```sh
❯ go mod download
```
3. Create a `.env` file in the project root with your configuration:
```sh
❯ 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
```
4. Install frontend dependencies:
```sh
❯ cd frontend
❯ npm install
```
5. Return to the root:
```sh
❯ cd ..
```
### 🤖 Usage
**Run frontend in development mode:**
```sh
❯ cd frontend
❯ npm run start
```
**Run backend locally:**
```sh
❯ go run api/main.go
```
**Run backend in development mode:**
```sh
❯ go run api/main.go -e development
```
**Using Docker:**
```sh
❯ docker build -t plefi .
❯ docker run -p 8080:8080 --env-file .env plefi
```
## 🔧 Configuration
PleFi uses a hierarchical configuration system:
1. Default values
2. Configuration files in `api/config/` directory
3. Environment variables (prefixed with `PLEFI_`)
### Environment Variables Reference
Server Configuration
- `PLEFI_SERVER__MODE` - Server mode (debug, release)
- `PLEFI_SERVER__ADDRESS` - Server bind address (default: `:8080`)
- `PLEFI_SERVER__HOSTNAME` - Server hostname for callbacks
- `PLEFI_SERVER__SESSION_SECRET` - Secret for session encryption
- `PLEFI_SERVER__TRUSTED_PROXIES` - Comma-separated list of trusted proxy IPs
Stripe Configuration
- `PLEFI_STRIPE__SECRET_KEY` - Stripe API secret key
- `PLEFI_STRIPE__WEBHOOK_SECRET` - Stripe webhook signing secret
- `PLEFI_STRIPE__DEFAULT_PRICE_ID` - Default subscription price ID
Plex Configuration
- `PLEFI_PLEX__CLIENT_ID` - Plex client identifier
- `PLEFI_PLEX__PRODUCT` - Plex product name
Logging Configuration
- `PLEFI_LOG__LEVEL` - Logging level (debug, info, warn, error)
- `PLEFI_LOG__FORMAT` - Logging format (json, text)
## 📡 API Endpoints
Application
- `GET /` - Landing page
- `GET /health` - Health check endpoint
Plex Authentication
- `GET /plex/auth` - Initiate Plex authentication
- `GET /plex/callback` - Plex authentication callback
Stripe
- `POST /stripe/webhook` - Stripe webhook endpoint for subscription events
- `GET /stripe/checkout` - Create a Stripe checkout session for subscription
- `GET /stripe/success` - Handle successful subscription checkout
- `GET /stripe/cancel` - Handle cancelled subscription checkout
---
## 🔰 Contributing
Contributions are welcome! Please follow these steps:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
Contributing Guidelines
1. **Fork the Repository**: Start by forking the project repository to your GitHub account.
2. **Clone Locally**: Clone the forked repository to your local machine.
```sh
git clone https://github.com/yourusername/plefi.git
```
3. **Create a New Branch**: Always work on a new branch.
```sh
git checkout -b feature/amazing-feature
```
4. **Make Your Changes**: Develop and test your changes locally.
5. **Commit Your Changes**: Commit with a clear message.
```sh
git commit -m 'Add amazing feature'
```
6. **Push to GitHub**: Push the changes to your forked repository.
```sh
git push origin feature/amazing-feature
```
7. **Submit a Pull Request**: Create a PR against the original project repository.
---
## 🎗 License
See the [LICENSE](LICENSE) file for details.
---