improve project structure for api

This commit is contained in:
lilly 2026-05-03 20:57:13 +02:00
commit 7fa9867a38
Signed by: lilly
SSH key fingerprint: SHA256:y9T5GFw2A20WVklhetIxG1+kcg/Ce0shnQmbu1LQ37g
7 changed files with 42 additions and 11 deletions

9
.envrc.dist Normal file
View file

@ -0,0 +1,9 @@
# integrate this into your own .envrc file with `source_env .envrc.dist`
watch_file api/pyproject.toml \
api/uv.lock
export UV_PROJECT=$(realpath ./api)
uv venv --allow-existing
uv sync

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.envrc
.direnv/
**/__pycache__
api/dist

View file

@ -9,3 +9,13 @@ Project structure:
├── api # Python application interacting with HomeMatic and providing the API.
└── app # Web UI
```
## API Development
Most things should automatically be set up with the included [direnv script](./.envrc.dist) but if you don't use that, take the following steps:
1. Go to the api/ directory
2. Run `uv venv` to create a python virtual environment
3. Install all dependencies of the dooris project into that virtual environment with `uv sync`
4. Run a development server `uv run uvicorn dooris_api:app --reload`

View file

@ -8,3 +8,12 @@ dependencies = [
"simple-openid-connect>=2.4.0",
"uvicorn>=0.46.0",
]
classifiers = ["Private :: Do Not Upload"]
[project.scripts]
"dooris-api" = "dooris_api:main"
[build-system]
requires = ["flit_core >=3.11,<5"]
build-backend = "flit_core.buildapi"

View file

@ -0,0 +1,8 @@
from dooris_api.app import app
def main():
import uvicorn
config = uvicorn.Config(app, port=8000, log_level="info")
server = uvicorn.Server(config)
server.run()

10
api/main.py → api/src/dooris_api/app.py Executable file → Normal file
View file

@ -53,13 +53,3 @@ async def login_callback(req: Request, resp: Response):
else:
return {"authenticated": False}
def main():
import uvicorn
config = uvicorn.Config(app, port=8000, log_level="info")
server = uvicorn.Server(config)
server.run()
if __name__ == "__main__":
main()

2
api/uv.lock generated
View file

@ -233,7 +233,7 @@ wheels = [
[[package]]
name = "dooris-api"
version = "0.1.0"
source = { virtual = "." }
source = { editable = "." }
dependencies = [
{ name = "fastapi" },
{ name = "simple-openid-connect" },