Skip to content

Commit 3355835

Browse files
authored
Merge pull request #1 from mongodb-labs/README-fixes
Small Fixes
2 parents 34883fb + 7acc2d6 commit 3355835

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

.github/FUNDING.yml

-1
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The tests are broken and it would be great if someone could take that on. Other
9595

9696
See notes:
9797

98-
## 0.1.0
98+
## CalVer 2023.11.10
9999

100100
- Replaced Next/Vue.js frontend framework with entirely React/Redux
101101
- Replaced Backend native connection of PostgreSQL/SQLAlchemy with MongoDB Motor/Beanie ODM

docs/development-guide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Go to the directory where you want to create your project and run:
2222

2323
```bash
2424
pip install cookiecutter
25-
cookiecutter https://github.com/whythawk/full-stack-fastapi-postgresql
25+
cookiecutter https://github.com/mongodb-labs/full-stack-fastapi-mongodb.git
2626
```
2727

2828
## Generate passwords
@@ -38,7 +38,7 @@ Copy the contents and use that as password / secret key. And run that again to g
3838

3939
## Input variables
4040

41-
The generator (Cookiecutter) will ask you for data on a long list of fields which will be used to populate variables across the project, customising it for you out the box. You might want to have these on hand before generating the project.
41+
The generator (Cookiecutter) will ask you for data on a long list of fields which will be used to populate variables across the project, customising it for you out the box. **You might want to have these on hand before generating the project.**
4242

4343
The input variables, with their default values (some auto generated) are:
4444

@@ -53,7 +53,7 @@ The input variables, with their default values (some auto generated) are:
5353
- `secret_key`: Backend server secret key. Use the method above to generate it.
5454
- `first_superuser`: The first superuser generated, with it you will be able to create more users, etc. By default, based on the domain.
5555
- `first_superuser_password`: First superuser password. Use the method above to generate it.
56-
- `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).
56+
- `backend_cors_origins`: Origins (domains, more or less) that are enabled for CORS ([Cross Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)). This informs a frontend browser in one domain (e.g. `https://dashboard.example.com`) it can trust 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).
5757
- `smtp_port`: Port to use to send emails via SMTP. By default `587`.
5858
- `smtp_host`: Host to use to send emails, it would be given by your email provider, like Mailgun, Sparkpost, etc.
5959
- `smtp_user`: The user to use in the SMTP connection. The value will be given by your email provider.

docs/getting-started.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This FastAPI, React, MongoDB repo will generate a complete web application stack
4545

4646
## Who is it for?
4747

48-
This project is a rock-solid foundation on which to build complex web applications which need parallel processing, scheduled event management, and a range of relational and graph database support. The base deployment requires about 2Gb of memory to run.
48+
This project is a rock-solid foundation on which to build complex web applications which need parallel processing, scheduled event management, leveraging a NoSQL Datastore (MongoDB). The base deployment requires about 2Gb of memory to run.
4949

5050
This is **not** a light-weight system to deploy a blog or simple content-management-system.
5151

@@ -83,9 +83,9 @@ Running Cookiecutter to customise the deployment with your settings, and then bu
8383

8484
### Setting up a Mongo Connection
8585

86-
A Mongo connection can be set up one of two ways: At the cookiecutter generation step, provide the `mongodb_uri`, and `mongo_database` to inform the generator on how to connect to an Atlas cloud instance. Additionally, in the generated file, you can manually set the .env.MONGO_DATABASE_URI and it will connect to the Atlas cluster made locally.
86+
A Mongo connection can be set up one of two ways: At the cookiecutter generation step, provide the `mongodb_uri`, and `mongo_database` to inform the generator on how to connect to an Atlas cloud instance. Additionally, in the generated file, you can manually leave the `.env.MONGO_DATABASE_URI` as `mongodb` and it will automatically connect to the running mongodb docker instance.
8787

88-
Additionally, developers could configure a local mongo instance, but it would either have to be spun up in docker, or generated separately and also allow for non-localhost connections to be made.
88+
Whilst the local instance is available, it is best advised to create or [connect to a MongoDB Atlas Cluster](https://www.mongodb.com/docs/atlas/tutorial/connect-to-your-cluster/).
8989

9090
### Deploying for production
9191

@@ -105,7 +105,7 @@ After using this generator, your new project will contain an extensive `README.m
105105

106106
## Release Notes
107107

108-
### 0.1.0
108+
### 2023.11.10
109109
- Experimental release of FARM-stack generator app
110110

111111
## License

{{cookiecutter.project_slug}}/README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ If your Docker is not running in `localhost` (the URLs above wouldn't work) chec
4444
**The backend and celery containers will fail to load if a proper Mongo URI is not configured**.
4545

4646
Please ensure that either
47-
- `MONGO_(HOST|USER|PASSWORD|DATABASE)` were properly set in the initial MongoDB setup phase
48-
- `MONGO_DATABASE_URI` has been set in `{{ cookiecutter.project_slug }}/.env`
47+
- `MONGO_DATABASE` is properly set in the initial Cookiecutter setup phase.
48+
- `MONGO_DATABASE_URI` has been set in `{{ cookiecutter.project_slug }}/.env`; leaving the initial value as `mongodb` will establish a connection to the docker instance of mongo created.
4949

5050
To learn more about how to generate a MongoDB URI please look at the docs on [Connecting to your MongoDB Atlas Clutser](https://www.mongodb.com/docs/atlas/tutorial/connect-to-your-cluster/)
5151

5252
### Setting Up MongoDB Locally
5353

54-
**Currently, the FARM-stack generator does not provide a running `mongod` within the docker container**
54+
The docker-compose file has a simple setup for a mongodb server to run in a docker container. It'll be exposed on port `27017` and reachable by setting the MONGO_DATABASE_URI to `mongodb`
5555

56-
If running a local instance of MongoDB outside of a docker container that you want your backend to communicate with, you will need to set up [port forwarding in your docker config](https://docs.docker.com/desktop/networking/#use-cases-and-workarounds). Since the intention of this generator is to work with scalable production environments very quickly, providing a local container of MongoDB was not part of the initial charter in its creation. **We do strongly advise you connect to an Atlas cluster**
56+
Since the intention of this generator is to work with scalable production environments very quickly, we provide a container of MongoDB, but **We do strongly advise you connect to an Atlas cluster**
5757

5858
To see how to use MongoDB with Docker, read through this article on [set-up steps](https://www.mongodb.com/compatibility/docker)
5959

@@ -635,6 +635,8 @@ Github Actions is configured assuming 2 environments following Github flow:
635635

636636
If you need to add more environments, for example, you could imagine using a client-approved `preprod` branch, you can just copy the configurations in `actions.yml` for `stag` and rename the corresponding variables. The Docker Compose file and environment variables are configured to support as many environments as you need, so that you only need to modify `actions.yml` (or whichever CI system configuration you are using).
637637

638+
Support for the deployment to the desired host domain has been commented out as the functionality has not been tested by the MongoDB team. Feel free to uncomment and follow instructions for deployment steps at your own discretion.
639+
638640
## Docker Compose files and env vars
639641

640642
There is a main `docker-compose.yml` file with all the configurations that apply to the whole stack, it is used automatically by `docker-compose`.
@@ -773,7 +775,7 @@ This project was generated using https://github.com/mongodb-labs/full-stack-fast
773775

774776
```bash
775777
pip install cookiecutter
776-
cookiecutter https://github.com/whythawk/full-stack-fastapi-mongodb
778+
cookiecutter https://github.com/mongodb-labs/full-stack-fastapi-mongodb.git
777779
```
778780

779781
You can check the variables used during generation in the file `cookiecutter-config-file.yml`.

{{cookiecutter.project_slug}}/backend/app/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ If your Docker is not running in `localhost` (the URLs above wouldn't work) chec
5555
**The backend and celery containers will fail to load if a proper Mongo URI is not configured**.
5656

5757
Please ensure that either
58-
- `MONGO_(HOST|USER|PASSWORD|DATABASE)` were properly set in the initial MongoDB setup phase
59-
- `MONGO_DATABASE_URI` has been set in `{{ cookiecutter.project_slug }}/.env`
58+
- `MONGO_DATABASE` is properly set in the initial Cookiecutter setup phase.
59+
- `MONGO_DATABASE_URI` has been set in `{{ cookiecutter.project_slug }}/.env`; leaving the initial value as `mongodb` will establish a connection to the docker instance of mongo created.
6060

6161
To learn more about how to generate a MongoDB URI please look at the docs on [Connecting to your MongoDB Atlas Clutser](https://www.mongodb.com/docs/atlas/tutorial/connect-to-your-cluster/)
6262

6363
### Setting Up MongoDB Locally
6464

65-
**Currently, the FARM-stack generator does not provide a running `mongod` within the docker container**
65+
The docker-compose file has a simple setup for a mongodb server to run in a docker container. It'll be exposed on port `27017` and reachable by setting the MONGO_DATABASE_URI to `mongodb`
6666

67-
If running a local instance of MongoDB outside of a docker container that you want your backend to communicate with, you will need to set up [port forwarding in your docker config](https://docs.docker.com/desktop/networking/#use-cases-and-workarounds). Since the intention of this generator is to work with scalable production environments very quickly, providing a local container of MongoDB was not part of the initial charter in its creation. **We do strongly advise you connect to an Atlas cluster**
67+
Since the intention of this generator is to work with scalable production environments very quickly, we provide a container of MongoDB, but **We do strongly advise you connect to an Atlas cluster**
6868

6969
To see how to use MongoDB with Docker, read through this article on [set-up steps](https://www.mongodb.com/compatibility/docker)
7070

71+
7172
### General workflow
7273

7374
By default, the dependencies are managed with [Hatch](https://hatch.pypa.io/latest/), go there and install it.
@@ -782,7 +783,7 @@ This project was generated using https://github.com/tiangolo/full-stack-fastapi-
782783

783784
```bash
784785
pip install cookiecutter
785-
cookiecutter https://github.com/tiangolo/full-stack-fastapi-postgresql
786+
cookiecutter https://github.com/mongodb-labs/full-stack-fastapi-mongodb.git
786787
```
787788

788789
You can check the variables used during generation in the file `cookiecutter-config-file.yml`.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.0"
1+
__version__ = "2023.11.10"

{{cookiecutter.project_slug}}/backend/app/app/db/session.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from app.core.config import settings
2+
from app.__version__ import __version__
23
from motor import motor_asyncio, core
4+
from pymongo.driver_info import DriverInfo
5+
6+
DRIVER_INFO=DriverInfo(name="full-stack-fastapi-mongodb", version=__version__)
37

48

59
class _MongoClientSingleton:
@@ -9,7 +13,8 @@ def __new__(cls):
913
if not hasattr(cls, "instance"):
1014
cls.instance = super(_MongoClientSingleton, cls).__new__(cls)
1115
cls.instance.mongo_client = motor_asyncio.AsyncIOMotorClient(
12-
settings.MONGO_DATABASE_URI
16+
settings.MONGO_DATABASE_URI,
17+
driver=DRIVER_INFO
1318
)
1419
return cls.instance
1520

{{cookiecutter.project_slug}}/backend/app/app/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ async def app_init(app: FastAPI):
2626
if settings.BACKEND_CORS_ORIGINS:
2727
app.add_middleware(
2828
CORSMiddleware,
29+
# Trailing slash causes CORS failures from these supported domains
2930
allow_origins=[str(origin).rstrip("/") for origin in settings.BACKEND_CORS_ORIGINS],
3031
allow_credentials=True,
3132
allow_methods=["*"],

{{cookiecutter.project_slug}}/frontend/app/content/about.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Copy the contents and use that as password / secret key. And run that again to g
6868

6969
### Input variables
7070

71-
The generator (cookiecutter) will ask you for some data, you might want to have at hand before generating the project.
71+
The generator (cookiecutter) will ask you for some data, **you might want to have at hand before generating the project.**
7272

7373
The input variables, with their default values (some auto generated) are:
7474

@@ -85,7 +85,7 @@ The input variables, with their default values (some auto generated) are:
8585
- `secret_key`: Backend server secret key. Use the method above to generate it.
8686
- `first_superuser`: The first superuser generated, with it you will be able to create more users, etc. By default, based on the domain.
8787
- `first_superuser_password`: First superuser password. Use the method above to generate it.
88-
- `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).
88+
- `backend_cors_origins`: Origins (domains, more or less) that are enabled for CORS ([Cross Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)). This informs a frontend browser in one domain (e.g. `https://dashboard.example.com`) it can trust 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).
8989
- `smtp_port`: Port to use to send emails via SMTP. By default `587`.
9090
- `smtp_host`: Host to use to send emails, it would be given by your email provider, like Mailgun, Sparkpost, etc.
9191
- `smtp_user`: The user to use in the SMTP connection. The value will be given by your email provider.

0 commit comments

Comments
 (0)