89 lines
2.1 KiB
Markdown
89 lines
2.1 KiB
Markdown
# Micro-API
|
|
|
|
Lightweight FastAPI micro-service foundation. Docker-ready, zero-cost deployment.
|
|
|
|
## Stack
|
|
|
|
- **Python 3.12** — slim Docker image
|
|
- **FastAPI** — async web framework
|
|
- **Uvicorn** — ASGI server
|
|
- **SQLite** — local database (swap to Postgres via `DATABASE_URL`)
|
|
- **Docker + Docker Compose** — containerized deployment
|
|
|
|
## Quick Start
|
|
|
|
### Local dev
|
|
|
|
```bash
|
|
python -m venv .venv
|
|
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
pip install -r requirements.txt -r requirements-dev.txt
|
|
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
|
```
|
|
|
|
Open http://localhost:8000/api/health
|
|
|
|
### Docker
|
|
|
|
```bash
|
|
docker compose up --build
|
|
```
|
|
|
|
### Tests
|
|
|
|
```bash
|
|
pytest -v
|
|
```
|
|
|
|
## Endpoints
|
|
|
|
| Method | Path | Description |
|
|
|--------|----------------|-----------------|
|
|
| GET | `/` | Service info |
|
|
| GET | `/api/health` | Health check |
|
|
|
|
## Environment
|
|
|
|
Copy `.env.example` to `.env` and adjust:
|
|
|
|
| Variable | Default | Description |
|
|
|----------------|-------------------------|----------------------|
|
|
| `DATABASE_URL` | `sqlite:///data/app.db` | Database connection |
|
|
| `DEBUG` | `false` | Enable debug mode |
|
|
| `API_PORT` | `8000` | Host port binding |
|
|
|
|
## Deployment
|
|
|
|
See [ARCHITECTURE.md](ARCHITECTURE.md) for the full deployment plan.
|
|
|
|
```bash
|
|
# On the VPS
|
|
git clone <repo-url> /opt/micro-api
|
|
cd /opt/micro-api
|
|
docker compose up -d --build
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
micro-api/
|
|
├── app/
|
|
│ ├── __init__.py
|
|
│ ├── main.py # FastAPI app entry point
|
|
│ ├── routes.py # API routes
|
|
│ ├── models.py # Pydantic schemas
|
|
│ ├── database.py # SQLite utilities
|
|
│ └── config.py # App settings
|
|
├── tests/
|
|
│ ├── __init__.py
|
|
│ └── test_main.py # API tests
|
|
├── Dockerfile
|
|
├── docker-compose.yml
|
|
├── requirements.txt
|
|
├── requirements-dev.txt
|
|
├── .env.example
|
|
├── .gitignore
|
|
├── README.md
|
|
└── ARCHITECTURE.md
|
|
```
|