Skip to content

Commit 4bd7688

Browse files
Quarto multi-page website
1 parent 0de1c67 commit 4bd7688

29 files changed

+455
-3672
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.devcontainer
22
__pycache__
33
*.pyc
4-
.env
4+
.env
5+
/.quarto/
6+
_docs/
7+
.pytest_cache/
8+
.mypy_cache/

.nojekyll

Whitespace-only changes.

README.md

Lines changed: 40 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,55 @@
1-
# README
1+
# FastAPI, Jinja2, PostgreSQL Webapp Template
22

3+
![Screenshot of homepage](docs/static/Screenshot.png)
34

4-
## FastAPI, Jinja2, PostgreSQL Webapp
5+
## Documentation
56

6-
![Screenshot of homepage](static/Screenshot.png)
7+
This README provides a high-level overview. See the **[full documentation website](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/)** for more detailed information on installation, features, architecture, conventions and code style, customization, and deployment to cloud platforms.
78

8-
This project is still under development.
9+
## Features
910

10-
### Architecture
11+
*FastAPI, Jinja2, PostgreSQL Webapp Template* combines three of the most lightweight and performant open-source web development frameworks in existence into a customizable webapp template with:
1112

12-
This application uses a Post-Redirect-Get (PRG) pattern. The user
13-
submits a form, which sends a POST request to a FastAPI endpoint on the
14-
server. The database is updated, and the user is redirected to a GET
15-
endpoint, which fetches the updated data and re-renders the Jinja2 page
16-
template with the new data.
13+
- Pure Python backend
14+
- Low-Javascript frontend
15+
- Powerful, easy-to-manage database layer
1716

18-
![Webapp Flow](static/webapp_flow.png)
17+
The template also includes full-featured secure auth with:
1918

20-
The advantage of the PRG pattern is that it is very straightforward to
21-
implement and keeps most of the rendering logic on the server side. The
22-
disadvantage is that it requires an extra round trip to the database to
23-
fetch the updated data, and re-rendering the entire page template may be
24-
less efficient than a partial page update on the client side.
19+
- Token-based authentication
20+
- Password recovery flow
21+
- Role-based access control system
2522

26-
### Authentication Flow
23+
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.
2724

28-
This application implements a comprehensive authentication system with
29-
security best practices. The diagrams below show the main authentication
30-
flows and security measures.
25+
## Tech stack
3126

32-
#### Registration and Login Flow
27+
**Core frameworks:**
28+
- [FastAPI](https://fastapi.tiangolo.com/): scalable, high-performance, type-annotated Python web backend framework
29+
- [PostgreSQL](https://www.postgresql.org/): the world's most advanced open-source database engine
30+
- [Jinja2](https://jinja.palletsprojects.com/en/3.1.x/): frontend HTML templating engine
31+
- [SQLModel](https://sqlmodel.tiangolo.com/): easy-to-use Python ORM
3332

34-
![Registration and Login Flow](static/auth_flow.png)
33+
**Additional technologies:**
34+
- [Poetry](https://python-poetry.org/): Python dependency manager
35+
- [Pytest](https://docs.pytest.org/en/7.4.x/): testing framework
36+
- [Docker](https://www.docker.com/): development containerization
37+
- [Github Actions](https://docs.github.com/en/actions): CI/CD pipeline
38+
- [Quarto](https://quarto.org/docs/): simple documentation website renderer
39+
- [MyPy](https://mypy.readthedocs.io/en/stable/): static type checker for Python
40+
- [Bootstrap](https://getbootstrap.com/): HTML/CSS styler
41+
- [Resend](https://resend.com/): zero- or low-cost email service used for password recovery
3542

36-
#### Password Reset Flow
43+
## Quickstart
3744

38-
![Password Reset Flow](static/reset_flow.png)
45+
For comprehensive installation instructions, see the [documentation website](https://promptlytechnologies.com/fastapi-jinja2-postgres-webapp/docs/).
3946

40-
The authentication system implements multiple security measures:
41-
42-
1. **Token Security**:
43-
- JWT-based with separate access/refresh tokens
44-
- Strict expiry times (30 min access, 30 day refresh)
45-
- Token type validation
46-
- HTTP-only cookies
47-
- Secure flag enabled
48-
- SameSite=strict restriction
49-
2. **Password Security**:
50-
- Strong password requirements enforced
51-
- Bcrypt hashing with random salt
52-
- Password reset tokens are single-use
53-
- Reset tokens have expiration
54-
3. **Cookie Security**:
55-
- HTTP-only prevents JavaScript access
56-
- Secure flag ensures HTTPS only
57-
- Strict SameSite prevents CSRF
58-
4. **Error Handling**:
59-
- Validation errors properly handled
60-
- Security-related errors don’t leak information
61-
- Comprehensive error logging
62-
63-
### Install development dependencies in a VSCode Dev Container
64-
65-
If you use VSCode with Docker to develop in a container, the following
66-
VSCode Dev Container configuration will install all dependencies:
67-
68-
``` json
69-
{
70-
"name": "Python 3",
71-
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
72-
"postCreateCommand": "sudo apt update && sudo apt install -y python3-dev libpq-dev graphviz && pipx install poetry && poetry install && poetry shell",
73-
"features": {
74-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
75-
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {}
76-
}
77-
}
78-
```
79-
80-
Simply create a `.devcontainer` folder in the root of the project and
81-
add a `devcontainer.json` file in the folder with the above content.
82-
VSCode may prompt you to install the Dev Container extension if you
83-
haven’t already, and/or to open the project in a container. If not, you
84-
can manually select “Dev Containers: Reopen in Container” from View \>
85-
Command Palette.
86-
87-
### Install development dependencies manually
88-
89-
#### Python and Docker
47+
### Python and Docker
9048

9149
- [Python 3.12 or higher](https://www.python.org/downloads/)
9250
- [Docker and Docker Compose](https://docs.docker.com/get-docker/)
9351

94-
#### PostgreSQL headers
52+
### PostgreSQL headers
9553

9654
For Ubuntu/Debian:
9755

@@ -109,28 +67,7 @@ For Windows:
10967

11068
- No installation required
11169

112-
#### Quarto CLI and Graphviz
113-
114-
- [Quarto CLI](https://quarto.org/docs/get-started/)
115-
116-
For macOS:
117-
118-
``` bash
119-
brew install graphviz
120-
```
121-
122-
For Ubuntu/Debian:
123-
124-
``` bash
125-
sudo apt update && sudo apt install -y graphviz
126-
```
127-
128-
For Windows:
129-
130-
- Download and install from
131-
[Graphviz.org](https://graphviz.org/download/#windows)
132-
133-
#### Python dependencies
70+
### Python dependencies
13471

13572
1. Install Poetry
13673

@@ -150,22 +87,17 @@ poetry install
15087
poetry shell
15188
```
15289

153-
(Note: You will need to activate the shell every time you open a new
154-
terminal session. Alternatively, you can use the `poetry run` prefix
155-
before other commands to run them without activating the shell.)
90+
(Note: You will need to activate the shell every time you open a new terminal session. Alternatively, you can use the `poetry run` prefix before other commands to run them without activating the shell.)
15691

15792
### Set environment variables
15893

15994
Copy .env.example to .env with `cp .env.example .env`.
16095

161-
Generate a 256 bit secret key with `openssl rand -base64 32` and paste
162-
it into the .env file.
96+
Generate a 256 bit secret key with `openssl rand -base64 32` and paste it into the .env file.
16397

16498
Set your desired database name, username, and password in the .env file.
16599

166-
To use password recovery, register a [Resend](https://resend.com/)
167-
account, verify a domain, get an API key, and paste the API key into the
168-
.env file.
100+
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.
169101

170102
### Start development database
171103

@@ -175,8 +107,7 @@ docker compose up -d
175107

176108
### Run the development server
177109

178-
Make sure the development database is running and tables and default
179-
permissions/roles are created first.
110+
Make sure the development database is running and tables and default permissions/roles are created first.
180111

181112
``` bash
182113
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
@@ -190,22 +121,10 @@ Navigate to http://localhost:8000/
190121
mypy .
191122
```
192123

193-
### Render the README
194-
195-
When updating the documentation, remember to make changes in the
196-
README.qmd file, not the README.md file. Then run the following command
197-
to render the README.md file:
198-
199-
``` bash
200-
quarto render README.qmd
201-
```
202-
203124
### Contributing
204125

205-
Fork the repository, create a new branch, make your changes, and submit
206-
a pull request.
126+
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.
207127

208128
### License
209129

210-
This project is licensed under the MIT License. See the LICENSE file for
211-
more details.
130+
This project is licensed under the MIT License. See the LICENSE file for more details.

0 commit comments

Comments
 (0)