Skip to content

Commit 57c2a93

Browse files
authored
Refactor backend (#18)
* Rename function/export to export * Add function/driver base * Migrate from namedtuples to dataclasses * Add Driver * Add aiohttp to dependencies * Clean up function names of CLI handlers * Add execute function and Config model to function * Add "function" CLI handler * Mark function.execute as not implemented yet * Use Pydantic's BaseModel directly * Rename TableBase to BaseTable * Clean up function CLI * Rename api's Settings to Config * Rename database's Settings to Config * Rename database/provision's Settings to Config * Rename export's Settings to Config * Rename file/driver's Settings to Config * Rename file's Settings to Config * Rename user's Settings to Config * Factor out user/auth config * Simplify routes by exporting only the router * Rename config.py files to _config.py * Clean up "api" * Clean up database/provision * Clean up database utility function names * Clean up database/provision usage * Clean up database * Clean up api * Clean up file/driver * Clean up file * Fix auth.Config * Add an example export.config.toml * Clean up user/auth * Clean up database/provision * Clean up database * Clean up export * Clean up file/driver * Clean up file * Clean up function and function/driver * Clean up user/auth * Clean up user * Rehash password on password sign in * Clean up modules * Fix circular imports in user/auth * Fix circular imports in file/driver * Fix circular imports in file * Move base Driver classes a separate file * Clean up file/driver * Add DockerDriver base * Add function/driver/helper base * Add in.json testdata to function/driver/helper * Remove the function CLI implementation for now * Fix in.json * Move helper functions to the helper module * Fix file.driver.FileSystemDriver to use aiofiles for mkdir * Implement execute function in helper * Add model exports to helper * Move yama_executable to driver's config * Change helper's behavior towards temp dir and unreadable output files * Draft a function driver implementation * Remove function implementation * Simplify file names * Simplify file names * Clean up api * Clean up database/provision * Clean up database * Clean up export, file, file/driver * Decompose user to solve circular imports * Rename user/auth to auth * Merge file/driver into file * Fix auth module name usages * Rename settings to config in identifiers * Rename settings to config in strings * Update README.md * Update README.md
1 parent 6c7c93e commit 57c2a93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2307
-1197
lines changed

backend/README.md

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,30 @@
11
# Yama
22

3-
The backend server is a FastAPI application with a modular architecture inspired
4-
by Netflix's [dispatch](https://github.com/Netflix/dispatch). Each module has a
5-
consistent and straightforward structure:
6-
7-
- `routes.py` for FastAPI routes.
8-
- `dependencies.py` for FastAPI dependencies.
9-
- `utils.py` for *utility* functions (also collectively known as a service,
10-
these shouldn't be confused with helper functions, these are functions with
11-
exposed module-specific business logic that can be used by other modules).
12-
- `models.py` for SQLAlchemy and Pydantic models.
13-
- `settings.py` for settings.
14-
15-
<blockquote>
16-
<details>
17-
<summary>Why <code>utils.py</code> and not <code>service.py</code>?</summary>
18-
19-
Taste. And a bit of inspiration by
20-
<a href="https://tailwindcss.com/">Tailwind's</a> usage of the word "utility".
21-
Besides, generally it's not a good idea to have random <code>utils.py</code>
22-
with generic helper functions all over your project anyways.
23-
</details>
24-
</blockquote>
3+
The backend server is a FastAPI application with modular architecture inspired
4+
by Go.
255

266
Noteworthy modules:
277

288
- [`api`](yama/api) is responsible for the FastAPI application itself.
299

3010
It collects routes from other modules and manages application's lifetime
31-
dependencies, such as the database engine and module settings.
11+
dependencies, such as the database engine and module configuration.
3212

3313
- [`database`](yama/database) provides other modules with database connections.
3414

35-
- [`database/provision`](yama/database/provision) provisions the Postgres database.
15+
- [`database/provision`](yama/database/provision) provisions the Postgres
16+
database.
3617

37-
It uses [golang-migrate](https://github.com/golang-migrate/migrate) for database migrations.
18+
It uses [golang-migrate](https://github.com/golang-migrate/migrate) for
19+
database migrations.
3820

39-
- [`user`](yama/user) manages users.
40-
41-
- [`user/auth`](yama/user/auth) provides user authorization based on OAuth2.
21+
- [`auth`](yama/auth) provides user authorization based on OAuth2.
4222

4323
It supports password and refresh token grants and has an ability to revoke an
4424
issued refresh token.
4525

26+
- [`user`](yama/user) manages users.
27+
4628
- [`file`](yama/file) manages a virtual file system for notes.
4729

4830
The system is implemented from scratch and optimized for read operations. It
@@ -56,15 +38,16 @@ Noteworthy modules:
5638

5739
A function is a (potentially) external program that operates on Markdown
5840
files. The external program could be vulnerable and untrusted, and so are the
59-
Markdown files. To get out of this pickle the functions are executed in a safe
60-
environment using Docker to keep them isolated from the application.
41+
Markdown files. To get out of this pickle the functions are executed in a
42+
safe environment using Docker to keep them isolated from the application.
43+
44+
The module provides 2 functions: import and export. These functions are
45+
implemented as separate modules and made available via the API.
6146

62-
- [`function/import_`](yama/function/import_) implements the import function
63-
that accepts a Microsoft Word document and converts it to Markdown using
64-
[Pandoc](https://pandoc.org/).
47+
- [`import_`](yama/import_) takes a Microsoft Word document and converts it to
48+
Markdown using [Pandoc](https://pandoc.org/).
6549

66-
- [`function/export`](yama/function/export) implements the export function that
67-
accepts a Markdown document and converts it to PDF using
50+
- [`export`](yama/export) takes a Markdown document and converts it to PDF using
6851
[Pandoc](https://pandoc.org/) and [LaTeX](https://www.latex-project.org/).
6952

7053
## Installation and Running

backend/example.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ YAMA__API__HOST=localhost
1414
YAMA__API__PORT=8000
1515
YAMA__API__RELOAD=true
1616
YAMA__USER__PUBLIC_USER_ID=00000000-0000-0000-0000-000000000000
17-
YAMA__USER__AUTH__ACCESS_TOKEN__KEY=abc
18-
YAMA__USER__AUTH__ACCESS_TOKEN__EXPIRE_SECONDS=1800
19-
YAMA__USER__AUTH__REFRESH_TOKEN__KEY=xyz
20-
YAMA__USER__AUTH__REFRESH_TOKEN__EXPIRE_SECONDS=604800
17+
YAMA__AUTH__ACCESS_TOKEN__KEY=abc
18+
YAMA__AUTH__ACCESS_TOKEN__EXPIRE_SECONDS=1800
19+
YAMA__AUTH__REFRESH_TOKEN__KEY=xyz
20+
YAMA__AUTH__REFRESH_TOKEN__EXPIRE_SECONDS=604800
2121
YAMA__FILE__FILES_BASE_URL=http://localhost:8000/files
2222
YAMA__FILE__ROOT_FILE_ID=00000000-0000-0000-0000-111111111111
2323
YAMA__FILE__DRIVER__TYPE=file-system

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies = [
1717
"aiofiles",
1818
"argon2-cffi",
1919
"python-jose[cryptography]",
20+
"aiohttp[speedups]",
2021
]
2122
optional-dependencies.dev = [
2223
"anyio",

0 commit comments

Comments
 (0)