-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
222 lines (147 loc) · 7.69 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---
title: "FastAPI, Jinja2, PostgreSQL Webapp Template"
---

## Quickstart
This quickstart guide provides a high-level overview. See the full documentation for comprehensive information on [features](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/index.html), [installation](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/installation.html), [architecture](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/architecture.html), [conventions, code style, and customization](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/customization.html), [deployment to cloud platforms](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/deployment.html), and [contributing](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/contributing.html).
## Features
This template combines three of the most lightweight and performant open-source web development frameworks into a customizable webapp template with:
- Pure Python backend
- Minimal-Javascript frontend
- Powerful, easy-to-manage database
The template also includes full-featured secure auth with:
- Token-based authentication
- Password recovery flow
- Role-based access control system
## Design Philosophy
The design philosophy of the template is to prefer low-level, best-in-class open-source frameworks that offer flexibility, scalability, and performance without vendor-lock-in. You'll find the template amazingly easy not only to understand and customize, but also to deploy to any major cloud hosting platform.
## Tech Stack
**Core frameworks:**
- [FastAPI](https://fastapi.tiangolo.com/): scalable, high-performance, type-annotated Python web backend framework
- [PostgreSQL](https://www.postgresql.org/): the world's most advanced open-source database engine
- [Jinja2](https://jinja.palletsprojects.com/en/3.1.x/): frontend HTML templating engine
- [SQLModel](https://sqlmodel.tiangolo.com/): easy-to-use Python ORM
**Additional technologies:**
- [uv](https://docs.astral.sh/uv/): Python dependency manager
- [Pytest](https://docs.pytest.org/en/7.4.x/): testing framework
- [Docker](https://www.docker.com/): development containerization
- [Github Actions](https://docs.github.com/en/actions): CI/CD pipeline
- [Quarto](https://quarto.org/docs/): simple documentation website renderer
- [MyPy](https://mypy.readthedocs.io/en/stable/): static type checker for Python
- [Bootstrap](https://getbootstrap.com/): HTML/CSS styler
- [Resend](https://resend.com/): zero- or low-cost email service used for password recovery
## Installation
For comprehensive installation instructions, see the [installation page](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/installation.html).
### uv
MacOS and Linux:
``` bash
wget -qO- https://astral.sh/uv/install.sh | sh
```
Windows:
``` bash
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```
See the [uv installation docs](https://docs.astral.sh/uv/getting-started/installation/) for more information.
### Python
Install Python 3.12 or higher from either the official [downloads page](https://www.python.org/downloads/) or using uv:
``` bash
# Installs the latest version
uv python install
```
### Docker and Docker Compose
Install Docker Desktop and Coker Compose for your operating system by following the [instructions in the documentation](https://docs.docker.com/compose/install/).
### PostgreSQL headers
For Ubuntu/Debian:
``` bash
sudo apt update && sudo apt install -y python3-dev libpq-dev libwebp-dev
```
For macOS:
``` bash
brew install postgresql
```
For Windows:
- No installation required
### Python dependencies
From the root directory, run:
``` bash
uv venv
uv sync
```
This will create an in-project virtual environment and install all dependencies.
### Set environment variables
Copy `.env.example` to `.env` with `cp .env.example .env`.
Generate a 256 bit secret key with `openssl rand -base64 32` and paste it into the .env file.
Set your desired database name, username, and password in the .env file.
To use password recovery, register a [Resend](https://resend.com/) account, verify a domain, get an API key, and paste the API key into the .env file.
### Start development database
To start the development database, run the following command in your terminal from the root directory:
``` bash
docker compose up -d
```
### Run the development server
Make sure the development database is running and tables and default permissions/roles are created first.
``` bash
uv run python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
Navigate to http://localhost:8000/
### Lint types with mypy
``` bash
uv run mypy .
```
## Developing with LLMs
``` {python}
#| echo: false
#| include: false
import re
from pathlib import Path
def extract_file_paths(quarto_yml_path):
"""
Extract href paths from _quarto.yml file.
Returns a list of .qmd file paths.
"""
with open(quarto_yml_path, 'r', encoding='utf-8') as f:
content = f.read()
# Find all href entries that point to .qmd files
pattern = r'^\s*-\s*href:\s*(.*?\.qmd)\s*$'
matches = re.findall(pattern, content, re.MULTILINE)
return matches
def process_qmd_content(file_path):
"""
Process a .qmd file by converting YAML frontmatter to markdown heading.
Returns the processed content as a string.
"""
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Replace YAML frontmatter with markdown heading
pattern = r'^---\s*\ntitle:\s*"([^"]+)"\s*\n---'
processed_content = re.sub(pattern, r'# \1', content)
return processed_content
# Get the current working directory
base_dir = Path.cwd()
quarto_yml_path = base_dir / '_quarto.yml'
# Extract file paths from _quarto.yml
qmd_files = extract_file_paths(quarto_yml_path)
# Process each .qmd file and collect contents
processed_contents = []
for qmd_file in qmd_files:
file_path = base_dir / qmd_file
if file_path.exists():
processed_content = process_qmd_content(file_path)
processed_contents.append(processed_content)
# Concatenate all contents with double newline separator
final_content = '\n\n'.join(processed_contents)
# Ensure the output directory exists
output_dir = base_dir / 'docs' / 'static'
output_dir.mkdir(parents=True, exist_ok=True)
# Write the concatenated content to the output file
output_path = output_dir / 'documentation.txt'
with open(output_path, 'w', encoding='utf-8') as f:
f.write(final_content)
```
In line with the [llms.txt standard](https://llmstxt.org/), we have provided a Markdown-formatted prompt—designed to help LLM agents understand how to work with this template—as a text file: [llms.txt](docs/static/llms.txt).
One use case for this file, if using the Cursor IDE, is to rename it to `.cursorrules` and place it in your project directory (see the [Cursor docs](https://docs.cursor.com/context/rules-for-ai) on this for more information). Alternatively, you could use it as a custom system prompt in the web interface for ChatGPT, Claude, or the LLM of your choice.
We have also exposed the full Markdown-formatted project documentation as a [single text file](docs/static/documentation.txt) for easy downloading and embedding for RAG workflows.
## Contributing
Your contributions are welcome! See the [issues page](https://github.com/promptly-technologies-llc/fastapi-jinja2-postgres-webapp/issues) for ideas. Fork the repository, create a new branch, make your changes, and submit a pull request.
## License
This project is created and maintained by [Promptly Technologies, LLC](https://promptlytechnologies.com/) and licensed under the MIT License. See the LICENSE file for more details.