Giter Site home page Giter Site logo

roywakumelojr / prismatopia Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bloomtech-labs/prismatopia

0.0 1.0 0.0 831 KB

A backend API stack combining a bunch of trendy components (circa 2020): Apollo Server, Prisma, Oauth, JWT, Postgres, Docker, Typescript and more!

Shell 0.02% TypeScript 96.34% Dockerfile 0.49% Makefile 3.15%

prismatopia's Introduction

Prismatopia

NOTE: THIS IS A WORK IN PROGRESS, CHANGING RAPIDLY, NOT STABLE, USE AT YOUR OWN RISK UNTIL THIS SENTENCE IS REMOVED FROM THE README!

An API stack combining a bunch of trendy components (circa 2020): Apollo Server, Prisma, OAuth, OpenID Connect, JWT, Postgres, Docker, Typescript, AWS and more!

How to use this repository

Prismatopia is a reference implementation, meaning you can clone it, configure, run it and play with it. But if you want to use it for your own purposes, you need to heavily modify it. You make a copy of this repository and that copy becomes the backend for your application. You'll end up customizing your copy of this repository with your resolvers, schemas and other stuff. This repository is simply an empty vessel for you to fork or otherwise copy as the starting point for your API stack.

The Stack

This API is built as a very specific stack of technologies. This is about as opinionated a stack as it gets. There no options, other than configuring the existing stack components or swapping them out in your own copy. Enjoy!

Here are the technologies in this stack...

  • AWS
    • Handles networking (ALB, VPC, etc.) and container management (ECS)
  • Apollo Server 2
    • Provides a GraphQL server for resolvers, which is where business logic lives
  • Prisma
    • Provides an ORM to translate from Graphql to Postgres, Apollo resolvers mainly call a Prisma Client to access data
  • Postgres
    • Provides persistent storage for data, this is managed by AWS RDS in production but is run in a container during local development
  • Github
    • Provides a place to hold the source code and Docker images

Directories

The various components of this stack are organized into folders to help keep everything neat and tidy.

Root

.env You don't see this because you'll need to create it and load it up with your specific configurations. To get Prismatopia running for reference, you should create a .env file in the root directory that looks like this:

APPLICATION_NAME=donuts
ENVIRONMENT_NAME=stage

OAUTH_TOKEN_ENDPOINT=https://<your okta domain>.okta.com/oauth2/default
OAUTH_CLIENT_ID=<your okta client id>

PRISMA_MANAGEMENT_API_SECRET=<a big long gnarly secret string used to access the prisma management api>

PRISMA_ENDPOINT=http://localhost:7000/

PRISMA_SECRET=<another big long gnarly secret string used to access your application's prisma api>

sourceme.sh A simple little script that will load the environment variables in .env into your shell environment. You need to source this for it to work: source ./sourceme.sh

docker-compose.yml A Docker Compose file that brings Prismatopia up locally for you to play with and develop against. Use it by running docker-compose up

.gitignore Very important to ensuing that you don't accidentally commit .env into your repository!

Makefile Oh how do we love the Makefile! So handy! Anything you need to do with Prismatopia can be done from the make file...

The Layers

Running locally

  1. Create an .env file in the root directory as described above
  2. Run Prismatopia: docker-compose up

Prisma should be running now, you should see some output:

...
apollo_1    | Running at address :: on port 8000
...
prisma_1    | Server running on :7000
...

You should also be able to hit Prisma in the browser:

Though when you hit Apollo, you should get an authorization error:

Sweet! Now, you need to deploy something to Prisma, which starts out empty.

  1. Load the environment variables into your shell: source ./sourceme.sh
  2. Deploy the Prisma schema: make prisma-deploy
  3. Generate a token: make prisma-token

You've now deployed and seeded the Prisma/Postgres layer. You can refresh your browser and use the generated token in GraphQL Playground and Prisma Admin. You should see data and you should be able to run some queried and mutations.

Getting into Apollo will be a bit trickier, since you need a valid JWT from an OAuth identity provider. In this case, we're using Okta, so you'll need to get a JWT from Okta.

  1. Setup an application in Okta that uses the Client Credentials flow
  2. Add the credentials to your .env file:
TEST_OAUTH_CLIENT_ID=<the client id>
TEST_OAUTH_CLIENT_SECRET=<the client secret>
  1. Run make apollo-token-gen which will generate a token that can be sent to Apollo
  2. Download and run GraphQL Playground as an Electron app, since Apollo doesn't expose it in Prismatopia
  3. Use the access token from Okta to authorize with Apollo through the GraphQL Playground

Running in AWS

  1. Create the .env file
  2. Source the .env file: source ./sourceme.sh
  3. Edit the cloudformation/params.json file to your liking
  4. Deploy to AWS: make cf-aws-deploy-all
  5. Generate a token: make prisma-token
  6. Play: https://prisma.<your domain>

prismatopia's People

Contributors

armandoroman1016 avatar berniedurfee avatar carloc24 avatar elkhoudh avatar tinomen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.