chore: add READMEs for clarity

This commit is contained in:
2025-07-25 02:01:50 +00:00
parent 26dd45ae95
commit 6476333846
5 changed files with 245 additions and 124 deletions

166
README.md
View File

@@ -1,130 +1,110 @@
# minxa.lol URL Shortener
# minxa.lol URL Shortener
minxa.lol is a lightweight and efficient URL shortening service built with **FastAPI**, **SQLAlchemy**, and **Hashids**. It converts long URLs into short, shareable codes and provides redirection to the original URLs.
<p align="center">
<img src="logo.png" alt="minxa.lol logo" width="300" height="300" />
</p>
**minxa.lol** is a lightweight and modern URL shortening service built with **FastAPI** and **React**. It transforms long URLs into compact, unique shortcodes and offers instant redirection.
---
## Features
## Features
* 🔗 Shorten URLs into unique shortcodes
* 🚀 Redirect to original URLs using the shortcode
* ✅ Validates shortcode format
* 🛠 Built with modern async Python stack
* 🧂 Configurable encoding via `hashids`
* 🔗 Shorten long URLs to human-friendly shortcodes
* 🚀 Redirects that are fast and reliable
* 🖥 Frontend with React, TypeScript, Tailwind CSS
* ⚙️ Environment-based configuration
* 🔐 Validation and error handling out of the box
* 🧩 Modular backend with Hashids encoding
---
## Tech Stack
## 🧰 Tech Stack
* FastAPI
* SQLAlchemy (async + sync)
* PostgreSQL
* Hashids
* Alembic (for migrations)
* Pydantic / Pydantic Settings
* Uvicorn (ASGI server)
### Backend
* **FastAPI** Async-first Python web framework
* **SQLAlchemy (async)** ORM for PostgreSQL
* **Hashids** Generates non-sequential codes
* **Alembic** DB migrations
* **Uvicorn** ASGI server
### Frontend
* **React** + **Vite** Fast SPA setup
* **Redux Toolkit** State management
* **Tailwind CSS** Modern utility styling
* **TypeScript** Typed components
---
## Getting Started
## 🚀 How to Run (Docker)
### 1. Clone the repository
### 1. Clone the Repository
```bash
git clone https://github.com/yourusername/minxa.git
cd minxa
git clone https://github.com/yourusername/minxa.lol.git
cd minxa.lol
```
### 2. Create and configure your environment file
### 2. Generate Environment Files
Copy the example file and update it with your local settings:
Use the helper script to generate `.env` files for both the frontend and backend:
```bash
cp .env.example .env
python generate_configs.py
```
Required variables in `.env`:
This will auto-populate required environment variables based on example templates.
```env
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/minxa
ENVIRONMENT=dev
HASHIDS_SALT=your-secret-salt
ENCODER_ALPHABET=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
```
### 3. Install dependencies
### 3. Start the Project with Docker Compose
```bash
pip install -r requirements.txt
docker compose -f docker-compose.generated.yml up --build -d
```
### 4. Run the application
Docker will spin up both frontend and backend containers with the correct configuration.
```bash
uvicorn app.main:app --reload
### 4. Access the App
* Frontend: [http://localhost:3000](http://localhost:3000)
* Backend API: [http://localhost:8000](http://localhost:8000)
Ensure Docker is installed and running on your machine before executing these steps.
---
## 📁 Project Structure
```
minxa.lol/
├── backend/
│ ├── db/ # DB connection
│ ├── models/ # SQLAlchemy models
│ ├── routes/ # FastAPI routers
│ ├── schemas/ # Pydantic schemas
│ ├── services/ # Business logic
│ └── utils/ # Encoding, helpers
├── frontend/
│ ├── src/
│ │ ├── api/ # API layer
│ │ ├── app/ # Redux store
│ │ ├── features/ # Feature slices
│ │ ├── pages/ # React pages
│ │ └── utils/ # Client utilities
└── generate_configs.py # Env setup script
```
---
## API Endpoints
## 📄 License
### `POST /`
Create a new shortened URL.
**Request Body:**
```json
{
"url": "https://example.com"
}
```
**Response:**
```json
{
"shortcode": "abc123",
"url": "https://example.com"
}
```
Licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
---
### `GET /{shortcode}`
## 🤝 Contributing
Redirects to the original URL associated with the given shortcode.
**Example:**
```bash
curl -v http://localhost:8000/abc123
```
Returns a `302` redirect to the original URL.
---
## Project Structure
```
app/
├── main.py # FastAPI entry point
├── config.py # Environment and settings
├── database.py # Database setup
├── models/ # SQLAlchemy models
├── routes/ # API endpoints
├── services/ # URL logic
├── schemas/ # Pydantic schemas
├── utils/ # Encoder logic using hashids
├── exceptions.py # Custom exceptions
```
---
## Development Notes
* Database tables auto-create in development mode
* Encoder uses Hashids for deterministic, unique shortcodes
* Uses `pydantic` for validation and FastAPI's dependency injection
* Alembic is available for database migrations
Pull requests are welcome. For major changes, open an issue first to discuss improvements or features.

86
backend/README.md Normal file
View File

@@ -0,0 +1,86 @@
# minxa.lol Backend
This is the **FastAPI-based** backend service for [minxa.lol](https://minxa.lol), a modern and lightweight URL shortener.
---
## 🧰 Tech Stack
* **FastAPI** Async web framework
* **SQLAlchemy (async)** Database ORM
* **PostgreSQL** Primary data store
* **Hashids** Encodes IDs into short strings
* **Alembic** Database migrations
* **Uvicorn** ASGI server
---
## ⚙️ Environment Setup
### 1. Create a virtual environment
```bash
python3 -m venv venv
source venv/bin/activate
```
### 2. Install dependencies
```bash
pip install -r requirements.txt
```
### 3. Create `.env` file
```bash
cp .env.example .env
```
Edit the `.env` file to include your local database connection:
```env
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/minxadatabase
```
---
## 🚀 Running the Backend
### Development Server
```bash
uvicorn backend.main:app --reload --app-dir ..
```
### Production Server (via Docker Compose)
From the root of the project:
```bash
python generate_configs.py
docker compose -f docker-compose.generated.yml up --build -d
```
---
## 📁 Directory Overview
```
backend/
├── db/ # DB engine & session
├── models/ # SQLAlchemy models
├── routes/ # FastAPI routers
├── schemas/ # Pydantic request/response schemas
├── services/ # Business logic
├── utils/ # Hashid encoder and other helpers
├── main.py # FastAPI entrypoint
├── config.py # Environment configuration
└── requirements.txt
```
---
## 🧪 Testing (Coming Soon)
Unit and integration tests will be added using **pytest**.

View File

@@ -1,46 +1,96 @@
# Getting Started with Create React App
# minxa.lol Frontend
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This is the **React-based frontend** for [minxa.lol](https://minxa.lol), a modern and lightweight URL shortener.
## Available Scripts
---
In the project directory, you can run:
## 🧰 Tech Stack
### `npm start`
* **React** Frontend UI framework
* **TypeScript** Typed JavaScript
* **Create React App** App bootstrap and tooling
* **Tailwind CSS** Utility-first styling
* **Redux Toolkit** State management
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
---
The page will reload if you make edits.\
You will also see any lint errors in the console.
## ⚙️ Environment Setup
### `npm test`
### 1. Install Dependencies
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
```bash
npm install
```
### `npm run build`
### 2. Create `.env` File
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
```bash
cp .env.example .env
```
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
Edit the `.env` file to configure the API URL:
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
```env
REACT_APP_API_BASE_URL=http://localhost:8000
```
### `npm run eject`
---
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
## 🚀 Running the Frontend
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
### Development Server
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
```bash
npm start
```
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
This starts the development server on [http://localhost:3000](http://localhost:3000).
## Learn More
### Production Build
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
```bash
npm run build
```
To learn React, check out the [React documentation](https://reactjs.org/).
### Test
```bash
npm test
```
### Docker (via Docker Compose)
From the root of the project:
```bash
python generate_configs.py
docker compose -f docker-compose.generated.yml up --build -d
```
---
## 📁 Directory Overview
```
frontend/
├── public/ # Static assets
├── src/
│ ├── api/ # API functions
│ ├── app/ # Redux store and hooks
│ ├── features/ # Feature slices
│ ├── pages/ # Page components
│ ├── routes/ # App router
│ └── utils/ # Client-side utilities
├── .env.example # Sample environment file
├── package.json # Project config and scripts
├── tailwind.config.js
├── tsconfig.json
└── README.md
```
---
## 🧪 Testing (Coming Soon)
Testing will be supported via **React Testing Library** and **Jest**.

View File

@@ -2,9 +2,14 @@ import secrets
import random
from pathlib import Path
# === Prompt user input === #
react_api_url = input("🔧 Enter the REACT_APP_API_BASE_URL (e.g. https://minxa.wtf): ").strip()
allow_origins = input("🔒 Enter allowed CORS origins for the backend comma-separated (e.g. https://minxa.lol,https://minxo.lol): ").strip()
# === Prompt user input with defaults === #
react_api_url = input("🔧 Enter the REACT_APP_API_BASE_URL (default: http://localhost:8000): ").strip()
if not react_api_url:
react_api_url = "http://localhost:8000"
allow_origins = input("🔒 Enter allowed CORS origins (comma-separated) (default: http://localhost:3000,http://127.0.0.1:3000): ").strip()
if not allow_origins:
allow_origins = "http://localhost:3000,http://127.0.0.1:3000"
# Ask for environment and validate input
valid_envs = ["dev", "stage", "prod"]
@@ -63,7 +68,7 @@ compose_yml = f"""services:
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", {db_user}, "-d", {db_name}]
test: ["CMD", "pg_isready", "-U", "{db_user}", "-d", "{db_name}"]
interval: 5s
timeout: 5s
retries: 5
@@ -108,4 +113,4 @@ compose_path.write_text(compose_yml)
print(f"✅ docker-compose.generated.yml written")
print("\n🎉 All files generated! Run your stack with:\n")
print("docker compose -f docker-compose.generated.yml up --build")
print(" docker compose -f docker-compose.generated.yml up --build -d")

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB