Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
AtticusZeller committed Jan 28, 2025
1 parent 83402a2 commit e51c83e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FIRST_SUPERUSER_PASSWORD=admin12345
# API URL
SUPABASE_URL=http://localhost:54321
# service_role key
SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
SUPABASE_KEY=eeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU

# Postgres
# DB URL: postgresql://postgres:[email protected]:54322/postgres
Expand Down
192 changes: 25 additions & 167 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,185 +1,43 @@
<p align="center">
<img src="docs/assets/logo.png" alt="Logo">
</p>
# FastAPI Supbase Template

<p align="center">
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT">
</a>
<a href="https://codecov.io/gh/Atticuszz/fastapi_supabase_template">
<img src="https://codecov.io/gh/Atticuszz/fastapi_supabase_template/branch/main/graph/badge.svg?token=YOUR_TOKEN" alt="codecov">
</a>
<a href="https://github.com/Atticuszz/fastapi_supabase_template/actions">
<img src="https://github.com/Atticuszz/fastapi_supabase_template/actions/workflows/ci.yml/badge.svg" alt="CI">
</a>
<a href="https://github.com/Atticuszz/fastapi_supabase_template/releases/">
<img src="https://img.shields.io/github/release/Atticuszz/fastapi_supabase_template.svg" alt="GitHub release">
</a>
<img src="https://img.shields.io/badge/python-3.10|3.11|3.12-blue.svg" alt="Python">
<a href="https://supabase.com">
<img src="https://supabase.com/badge-made-with-supabase-dark.svg" alt="Made with Supabase">
</a>
</p>
## Environment

# ⚑SupaFast⚑
### Python

___
> supabase & fastapi crud template
> [uv](https://github.com/astral-sh/uv) is an extremely fast Python package and project manager, written in Rust.
![supafast.drawio.png](docs/assets/supafast.drawio.png)

## Features πŸš€

___

### FastAPI&supabase

1. works of authorization all handled by supabase-py and fastapi **dependency** without any extra code
2. supabase-py crud integration with **pydantic** model validation

### Pytest

1. pytest integration with **pytest-cov**
2. pytest **fixtures** for fastapi client and supabase client
3. pytest **fixtures** for access_token and refresh_token
4. test for **CRUD** operations
5. test for **api** operations

### CI/CD

1. **codecov** for coverage report
2. **poetry** for dependency management and pytest integration
3. **pre-commit** for code quality
4. **latest_changes.yml** for auto update README.md
5. **Semantic Release** for auto release and changelog
6. **docker** for deployment

## How to use it

___
![](docs/assets/usage.gif)

1. create your github repo and config it
1. allow ci to access your repo
![img.png](docs/assets/img.png)
2. config ci_tokens
1. `CODECOV_TOKEN` for codecov in `.github/workflows/ci.yml` ,`semantic-release` is optional for auto release
2. `ATTICUS_PAT`should replace with your GitHub token for latest_changes.yml in `.github/workflows/latest_changes.yml`
3. `DOCKER_USERNAME` and `DOCKER_PASSWORD` for docker-image.yml in `.github/workflows/docker-image.yml`
4. replace `tags: atticuszhou/supafast:latest` with your docker repo in `.github/workflows/docker-image.yml`
3. config fastapi setting in `your_project\src\app\core\config.py`
4. config `pyproject.toml` with your project name and description,etc

2. cd your repo and install dependencies with [uv](https://github.com/astral-sh/uv), which is an extremely fast Python package and project manager, written in Rust.

```shell
uv sync
```bash
cd backend
uv sync --all-groups --dev
```

3. [start your supabase locally](https://supabase.com/docs/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux&queryGroups=access-method&access-method=postgres)
### [Supabase](https://supabase.com/docs/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux&queryGroups=access-method&access-method=postgres)

install supabase-cli

```bash
# brew in linux https://brew.sh/
brew install supabase/tap/supabase
supabase init
supabase start
```

4. set your supabase env
launch supabase docker containers

```shell
export SUPABASE_URL=your_supabase_url
export SUPABASE_KEY=your_supabase_key
export SUPERUSER_EMAIL=your_superuser_email
export SUPERUSER_PASSWORD=your_superuser_password
```bash
# under repo root dir
supabase start
```

5. config fastapi settings

```python
# src/app/core/config.py
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
SUPABASE_URL: str = Field(default_factory=lambda: os.getenv("SUPABASE_URL"))
SUPABASE_KEY: str = Field(default_factory=lambda: os.getenv("SUPABASE_KEY"))
SUPERUSER_EMAIL: str = Field(default_factory=lambda: os.getenv("SUPERUSER_EMAIL"))
SUPERUSER_PASSWORD: str = Field(default=lambda: os.getenv("SUPERUSER_PASSWORD"))
# SERVER_NAME: str
SERVER_HOST: AnyHttpUrl = "https://localhost"
SERVER_PORT: int = 8000
BACKEND_CORS_ORIGINS: list[AnyHttpUrl] = []
PROJECT_NAME: str = "fastapi supabase template"
Config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
```
> [!NOTE]
> modify the `.env` from the output of `supabase start` or run `supabase status` manually.
6. run server
## Test

```shell
uv run uvicorn app.main:app --reload
```bash
cd backend
# test connection of db and migration
scripts/pre-start.sh
# unit test
scripts/test.sh
# test connection of db and unit test
scripts/tests-start.sh
```

## Roadmap 🫢

___

- [x] FastAPI backend
- [x] **standard** structure
for <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">**FastAPI**</a> project

```text
── src
β”‚ └── app
β”‚ β”œβ”€β”€ api
β”‚ β”‚ β”œβ”€β”€ api_v1
β”‚ β”‚ β”‚ β”œβ”€β”€ endpoints
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”‚ β”‚ └── items.py
β”‚ β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”‚ └── api.py
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ └── deps.py
β”‚ β”œβ”€β”€ core
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”œβ”€β”€ config.py
β”‚ β”‚ └── events.py
β”‚ β”œβ”€β”€ crud
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”œβ”€β”€ base.py
β”‚ β”‚ └── crud_item.py
β”‚ β”œβ”€β”€ schemas
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”œβ”€β”€ auth.py
β”‚ β”‚ β”œβ”€β”€ base.py
β”‚ β”‚ β”œβ”€β”€ item.py
β”‚ β”‚ └── msg.py
β”‚ β”œβ”€β”€ services
β”‚ β”‚ └── __init__.py
β”‚ β”œβ”€β”€ utils
β”‚ β”‚ └── __init__.py
β”‚ β”œβ”€β”€ __init__.py
β”‚ └── main.py
...
```

- [x] **auto-auth** by fastapi dependency with supabase-auth
- [x] **CRUD** operations pytest
- [x] **api** requests pytest
- [ ] Supabase integration
- [x] crud supabase-postgresql
- [ ] websocket with supabase-realtime
- [ ] curd supabase-storage
- [ ] supafunc integration
- [x] deployment
- [x] Full **Docker** integration (Docker based).
- [ ] clone
- [ ] cookiecutter

## Release Notes πŸ₯Έ

___

### Latest Changes

## License

This project is licensed under the terms of the MIT license.
1 change: 1 addition & 0 deletions backend/app/alembic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.

0 comments on commit e51c83e

Please sign in to comment.