My personal fullstack template for 2024. Constructed in May, 2024.
- DB - Postgres hosted on Render
- Backend - Python Flask API hosted on Render
- Frontend - NextJS with Typescript hosted on Vercel
- CSS Framework - Tailwind
- Middleware - NextJS
- Auth - NextAuth with Google Provider
- Clone repo
$ git clone
- Do the backend first - Switch the terminal to backend directory with
$ cd api
- Install requirements
$ pip3 install -r requirements.txt
- Fill out the environment variables:
- Clone the example environment file
$ cp -a example.env .env
- Add a postgres URL for the
DB_CONNECTION_URL
variable. I used render and they easily provide an external url, the docs can be found here. - Add a secret value for the
SECRET
variable that we will use for the backend/frontend handshake. You can create a secure secret in the terminal with$ openssl rand -base64 32
- Clone the example environment file
- Run first migration to backfill database with
$ python3 scripts/init_db.py
- Start Flask server
python3 -m flask --debug run
- Server will be running on http://localhost:5000/
- Install requirements
- Next we'll do the frontend - Open a second terminal tab in the same directory and switch to the backend with
$ cd web-app
- Fill out the environment variables:
- Clone the example environment file
$ cp -a example.env .env
- For the
SECRET
variable, use the same secret from the .env file in the/api/
directory - We'll need to supply a auth provider using NextAuth. I used Google. Documentation can be found here on how to set that up.
- Clone the example environment file
- We need install all libraries using
$ npm i
- Run
$ pnpm dev
to start development server - Server will be running on http://localhost:3000/
- Fill out the environment variables:
Deploying will take place in two parts. First, we will set up the database and deploy the backend using Render. Second, we will deploy the frontend using Vercel.
- You'll need this repo in your own github account. You can either clone it or fork it to create your own repo in your own github account. Do this now.
- You'll need to bring your own PostgreSQL database with a url connection. If you don't have that already, consider the below steps to create this in Render:
- Navigate to Render, make an account, and navigate to your dashboard. Click the New button and select PostgreSQL.
- You'll be prompted to enter a name (doesn't matter, but if you're stuck on it, try
my-unqiue-database
). The other parameters are optional. - Once the database has been created, you'll see the internal URL. We'll need this later.
- We'll be creating the backend in render. Log into your account, navigate to your dashboard, and click the New button. Select New Web service and point this to your newly cloned github repo.
- You'll be promoted for name and some other fields. Be sure to change root directory to
/api/
and select python 3 as your runtime. You'll also need to change the run command to be$ gunicorn app:app
. - There are 3 environment variables you'll need to provide. See the descriptions below:
DB_CONNECTION_URL=**Postgres required connection url. If you're using Render, provide the Internal Database URL which you can find in the render database UI
SECRET_HASH=**Your own secret hash. This will be used also in Vercel.
DEPLOY_MODE=Prod. self explanatory
- Click 'Create Web Service' button at the bottom.
- Once it is deployed, you'll see your production url at the top. Try it our by navigating your browser to
<your-url>
and you should see a Hello World Message!
- Next we'll do the frontend with Vercel. Navigate to Vercel, make an account, and navigate to your dashboard.
- Find the 'Add New Project' Button and select your associated github repo from the list.
- Select
Next.JS
for the Framework Present, and change the root direct to/web-app/
- There are 3 environment variables you'll need to provide. See the descriptions below:
SECRET=**Your own secret hash. This is the same hashed secret used in Render land.
GOOGLE_CLIENT_ID=* I used Google as my Oauth Provider. See details below.
GOOGLE_CLIENT_SECRET=** Another detail from Oauth. See details below.
I used Google as my OAuth provider. Next Auth has a ton of providers, I used Google. You should follow the documentation on NextAuth if you decide to go down this route. But you'll be unable to complete this step until you've actually launched your site and have a hosted URL.
- Click Deploy and visit your site on the provided URL. You should see the basic elements and a Log in button.
- Provide the host URL and other details to your OAuth provider. Go back to vercel and add the client_id and client_secret from Google to your environment variables.
- Test login, query the backend, and you're ready to go!