Skip to content

Commit c0035a3

Browse files
authored
Merge pull request #21 from whythawk/organising-documentation
Documentation re-organisation
2 parents 6c77945 + bc6cf02 commit c0035a3

7 files changed

+436
-172
lines changed

README.md

+19-152
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,47 @@
44

55
Accelerate your next web development project with this FastAPI/Nuxt.js base project generator.
66

7-
This project is a comprehensively updated fork of [Sebastián Ramírez's](https://github.com/tiangolo) [Full Stack FastAPI and PostgreSQL Base Project Generator](https://github.com/tiangolo/full-stack-fastapi-postgresql). FastAPI is updated to version 0.88 (November 2022), SQLAlchemy to version 2.0 (January 2023), and the frontend to Nuxt 3.2 (February 2023).
7+
This project is for developers looking to build and maintain full-feature progressive web applications using Python on the backend / Typescript on the frontend, and want the complex-but-routine aspects of auth 'n auth, and component and deployment configuration, taken care of, including interactive API documentation.
88

9-
Generate a backend and frontend stack using Python, including interactive API documentation.
9+
This is a comprehensively updated fork of [Sebastián Ramírez's](https://github.com/tiangolo) [Full Stack FastAPI and PostgreSQL Base Project Generator](https://github.com/tiangolo/full-stack-fastapi-postgresql). FastAPI is updated to version 0.88 (November 2022), SQLAlchemy to version 2.0 (January 2023), and the frontend to Nuxt 3.2 (February 2023).
1010

1111
- [Screenshots](#screenshots)
1212
- [Key features](#key-features)
1313
- [How to use it](#how-to-use-it)
14-
- [Generate passwords](#generate-passwords)
15-
- [Input variables](#input-variables)
16-
- [Local development](#local-development)
17-
- [Starting Jupyter Lab](#starting-jupyter-lab)
18-
- [How to deploy](#how-to-deploy)
19-
- [Authentication with magic and TOTP](#authentication-with-magic-and-totp)
14+
- [Getting started](getting-started.md)
15+
- [Development and installation](#development-and-installation)
16+
- [Deployment for production](#deployment-for-production)
17+
- [Authentication and magic tokens](#authentication-and-magic-tokens)
2018
- [More details](#more-details)
2119
- [Release notes](#release-notes)
2220
- [License](#license)
23-
21+
2422
## Screenshots
2523

2624
### App landing page
2725

28-
[![Landing page](img/landing.png)](https://github.com/whythawk/full-stack-fastapi-postgresql)
26+
![Landing page](img/landing.png)
2927

3028
### Dashboard Login
3129

32-
[![Magic-link login](img/login.png)](https://github.com/whythawk/full-stack-fastapi-postgresql)
30+
![Magic-link login](img/login.png)
3331

3432
### Dashboard User Management
3533

36-
[![Moderator user management](img/dashboard.png)](https://github.com/whythawk/full-stack-fastapi-postgresql)
34+
![Moderator user management](img/dashboard.png)
3735

3836
### Interactive API documentation
3937

40-
[![Interactive API docs](img/redoc.png)](https://github.com/whythawk/full-stack-fastapi-postgresql)
38+
![Interactive API docs](img/redoc.png)
4139

4240
### Enabling two-factor security (TOTP)
4341

44-
[![Enabling TOTP](img/totp.png)](https://github.com/whythawk/full-stack-fastapi-postgresql)
45-
42+
![Enabling TOTP](img/totp.png)
4643

4744
## Key features
4845

46+
This FastAPI, PostgreSQL, Neo4j & Nuxt 3 repo will generate a complete web application stack as a foundation for your project development.
47+
4948
- **Docker Compose** integration and optimization for local development.
5049
- **Authentication** user management schemas, models, crud and apis already built, with OAuth2 JWT token support & default hashing. Offers _magic link_ authentication, with password fallback, with cookie management, including `access` and `refresh` tokens.
5150
- [**FastAPI**](https://github.com/tiangolo/fastapi) backend with [Inboard](https://inboard.bws.bio/) one-repo Docker images:
@@ -72,142 +71,10 @@ Generate a backend and frontend stack using Python, including interactive API do
7271

7372
## How to use it
7473

75-
Go to the directory where you want to create your project and run:
76-
77-
```bash
78-
pip install cookiecutter
79-
cookiecutter https://github.com/whythawk/full-stack-fastapi-postgresql
80-
```
81-
82-
### Generate passwords
83-
84-
You will be asked to provide passwords and secret keys for several components. Open another terminal and run:
85-
86-
```bash
87-
openssl rand -hex 32
88-
# Outputs something like: 99d3b1f01aa639e4a76f4fc281fc834747a543720ba4c8a8648ba755aef9be7f
89-
```
90-
91-
Copy the contents and use that as password / secret key. And run that again to generate another secure key.
92-
93-
94-
### Input variables
95-
96-
The generator (cookiecutter) will ask you for some data, you might want to have at hand before generating the project.
97-
98-
The input variables, with their default values (some auto generated) are:
99-
100-
- `project_name`: The name of the project
101-
- `project_slug`: The development friendly name of the project. By default, based on the project name
102-
- `domain_main`: The domain in where to deploy the project for production (from the branch `production`), used by the load balancer, backend, etc. By default, based on the project slug.
103-
- `domain_staging`: The domain in where to deploy while staging (before production) (from the branch `master`). By default, based on the main domain.
104-
- `domain_base_api_url`: The domain url used by the frontend app for backend api calls. If deploying a localhost development environment, likely to be `http://localhost/api/v1`
105-
- `domain_base_ws_url`: The domain url used by the frontend app for backend websocket calls. If deploying a localhost development environment, likely to be `ws://localhost/api/v1`
106-
107-
- `docker_swarm_stack_name_main`: The name of the stack while deploying to Docker in Swarm mode for production. By default, based on the domain.
108-
- `docker_swarm_stack_name_staging`: The name of the stack while deploying to Docker in Swarm mode for staging. By default, based on the domain.
109-
110-
- `secret_key`: Backend server secret key. Use the method above to generate it.
111-
- `totp_secret_key`: Two-factor security (TOTP) server secret key.
112-
- `first_superuser`: The first superuser generated, with it you will be able to create more users, etc. By default, based on the domain.
113-
- `first_superuser_password`: First superuser password. Use the method above to generate it.
114-
- `backend_cors_origins`: Origins (domains, more or less) that are enabled for CORS (Cross Origin Resource Sharing). This allows a frontend in one domain (e.g. `https://dashboard.example.com`) to communicate with this backend, that could be living in another domain (e.g. `https://api.example.com`). It can also be used to allow your local frontend (with a custom `hosts` domain mapping, as described in the project's `README.md`) that could be living in `http://dev.example.com:8080` to communicate with the backend at `https://stag.example.com`. Notice the `http` vs `https` and the `dev.` prefix for local development vs the "staging" `stag.` prefix. By default, it includes origins for production, staging and development, with ports commonly used during local development by several popular frontend frameworks (Vue with `:8080`, React, Angular).
115-
- `smtp_tls`: Transport Sockets Layer (or Secure Sockets Layer) boolean setting. By default `True`.
116-
- `smtp_port`: Port to use to send emails via SMTP. By default `587`.
117-
- `smtp_host`: Host to use to send emails, it would be given by your email provider, like Mailgun, Sparkpost, etc.
118-
- `smtp_user`: The user to use in the SMTP connection. The value will be given by your email provider.
119-
- `smtp_password`: The password to be used in the SMTP connection. The value will be given by the email provider.
120-
- `smtp_emails_from_email`: The email account to use as the sender in the notification emails, it could be something like `[email protected]`.
121-
- `smtp_emails_from_name`: The email account name to use as the sender in the notification emails, it could be something like `Symona Adaro`.
122-
- `smtp_emails_to_email`: The email account to use as the recipient for `contact us` emails, it could be something like `[email protected]`.
123-
124-
- `postgres_password`: Postgres database password. Use the method above to generate it. (You could easily modify it to use MySQL, MariaDB, etc).
125-
- `pgadmin_default_user`: PGAdmin default user, to log-in to the PGAdmin interface.
126-
- `pgadmin_default_user_password`: PGAdmin default user password. Generate it with the method above.
127-
128-
- `neo4j_password`: Neo4j database password. Use the method above to generate it.
129-
130-
- `traefik_constraint_tag`: The tag to be used by the internal Traefik load balancer (for example, to divide requests between backend and frontend) for production. Used to separate this stack from any other stack you might have. This should identify each stack in each environment (production, staging, etc).
131-
- `traefik_constraint_tag_staging`: The Traefik tag to be used while on staging.
132-
- `traefik_public_constraint_tag`: The tag that should be used by stack services that should communicate with the public.
133-
134-
- `flower_auth`: Basic HTTP authentication for flower, in the form`user:password`. By default: "`admin:changethis`".
135-
136-
- `sentry_dsn`: Key URL (DSN) of Sentry, for live error reporting. You can use the open source version or a free account. E.g.: `https://1234abcd:[email protected]/30`.
137-
138-
- `docker_image_prefix`: Prefix to use for Docker image names. If you are using GitLab Docker registry it would be based on your code repository. E.g.: `git.example.com/development-team/my-awesome-project/`.
139-
- `docker_image_backend`: Docker image name for the backend. By default, it will be based on your Docker image prefix, e.g.: `git.example.com/development-team/my-awesome-project/backend`. And depending on your environment, a different tag will be appended ( `prod`, `stag`, `branch` ). So, the final image names used will be like: `git.example.com/development-team/my-awesome-project/backend:prod`.
140-
- `docker_image_celeryworker`: Docker image for the celery worker. By default, based on your Docker image prefix.
141-
- `docker_image_frontend`: Docker image for the frontend. By default, based on your Docker image prefix.
142-
143-
### Local development
144-
145-
Once the Cookiecutter script has completed, you will have a folder populated with the base project and all input variables customised.
146-
147-
Change into the project folder and run the `docker-compose` script to build the project containers:
148-
149-
```bash
150-
docker-compose build --no-cache
151-
```
152-
153-
And start them:
154-
155-
```bash
156-
docker-compose up -d
157-
```
158-
159-
**NOTE:** If you install new Node packages, you will need to rebuild the `frontend`. I also find that `frontend` behaves inconsistently in development mode, and may not refresh on changes. In particular, `nuxt/content` is very unpredictable in dev mode running in the container. You may have more success running the `frontend` outside of the container to take advantage of live refresh.
160-
161-
Change into the `/frontend` folder, and:
162-
163-
```bash
164-
yarn install
165-
yarn dev
166-
```
167-
168-
Be careful about the version of `Node.js` you're using. As of today (December 2022), the latest Node version supported by Nuxt is 16.18.1.
169-
170-
You can then view the frontend at `http://localhost:3000` and the backend api endpoints at `http://localhost/redoc`.
171-
172-
FastAPI `backend` updates will refresh automatically, but the `celeryworker` container must be restarted before changes take effect.
173-
174-
### Starting Jupyter Lab
175-
176-
If you like to do algorithmic development and testing in Jupyter Notebooks, then launch the `backend` terminal and start Jupyter as follows:
177-
178-
```bash
179-
docker-compose exec backend bash
180-
```
181-
182-
From the terminal:
183-
184-
```bash
185-
$JUPYTER
186-
```
187-
188-
Copy the link generated into your browser and start.
189-
190-
**NOTE:** Notebooks developed in the container are not saved outside, so remember to copy them for persistence. You can do that from inside Jupyter (download), or:
191-
192-
```bash
193-
docker cp <containerId>:/file/path/within/container /host/path/target
194-
```
195-
196-
## How to deploy
197-
198-
This stack can be adjusted and used with several deployment options that are compatible with Docker Compose, but it is designed to be used in a cluster controlled with pure Docker in Swarm Mode with a Traefik main load balancer proxy handling automatic HTTPS certificates, using the ideas from <a href="https://dockerswarm.rocks" target="_blank">DockerSwarm.rocks</a>.
199-
200-
Please refer to <a href="https://dockerswarm.rocks" target="_blank">DockerSwarm.rocks</a> to see how to deploy such a cluster in 20 minutes.
201-
202-
## Authentication with magic and TOTP
203-
204-
> Any custodial changes to user-controlled information must be treated as requiring full authentication. Do **not** assume that a logged-in user is the authorised account holder.
205-
206-
Most web applications permit account recovery through requesting a password reset via email. This has process has been hardened using dual JWT tokens, and is offered as a primary authentication method, with password fallback.
207-
208-
Time-based One-Time Password (TOTP) authentication extends the login process to include a challenge-response component where the user needs to enter a time-based token after their preferred login method.
209-
210-
For development, you may prefer to use login and password.
74+
- [Getting started](getting-started.md)
75+
- [Development and installation](development-guide.md)
76+
- [Deployment for production](deployment-guide.md)
77+
- [Authentication and magic tokens](authentication-guide.md)
21178

21279
## More details
21380

@@ -220,7 +87,7 @@ See notes and [releases](https://github.com/whythawk/full-stack-fastapi-postgres
22087
### 0.7.3
22188
- @nuxt/content 2.2.1 -> 2.4.3
22289
- Fixed: `@nuxt/content` default api, `/api/_content`, conflicts with the `backend` api url preventing content pages loading.
223-
- Documentation: Complete deployment guide in `DEPLOYMENT-README.md`
90+
- Documentation: Complete deployment guide in `DEPLOYMENT-README.md` (this has now been moved to `/docs`)
22491

22592
### 0.7.2
22693
- Fixed: URLs for recreating project in generated `README.md`. PR [#15](https://github.com/whythawk/full-stack-fastapi-postgresql/pull/15) by @FranzForstmayr

0 commit comments

Comments
 (0)