86 lines
1.7 KiB
Markdown
86 lines
1.7 KiB
Markdown
# 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**. |