Giter Site home page Giter Site logo

unsplash-prisma's Introduction

Unsplash Gallery

An application to view and favourite images from Unsplash using Prisma.io

How to run

Add environment configuration

backend/prisma/.env

DATABASE_URL="postgresql://postgres:example@localhost:5432/postgres?schema=public"

backend/.env

DOWNLOAD_DIR=./src/downloads
UNSPLASH_ACCESS_KEY={Add key here}

frontend/.env

REACT_APP_API_BASE_URL=http://localhost:8000

Start the services

To provision the postgres db:

$ docker-compose up --build

Apply prisma schema to the database

$ cd backend && npx prisma migrate up --experimental

Start the server

$ npm run dev

Start the client

In a new terminal run the following command to start the client:

$ cd ../frontend && npm install && npm run start

Architecture

Backend

  • Postgres
  • Express.js
  • Typescript
  • Prisma

Frontend

  • React (create-react-app)
  • Typescript
  • Material UI

Design decisions

I chose to use Prisma as an "ORM" layer to ease interactions with the database and speed up API development. I find the schema is a nice way to map to a mental model. CRA on the frontend felt like the best choice because I wasn't looking to build a static site (Gatsby) or one that needed to be Server side rendered (Next.js). A GraphQL API was something I was interested in implementing but I felt it really wasn't necessary for an application of this size so I opted to not use it. If I had, using something like Nexus (framework) or type-graphql could have been appropriate libraries to use.

The frontend contains no state management libraries due to the limited requirements. I felt something like Redux was a too heavy and even the Context API was unnecessary since all the interactions were saved in the database and there wasn't really session state that needed to be shared between screens. That decision did lead to a ux bug though when favouriting an image on the Search page. The results on the page will not update so opening the modal a 2nd time will not have the updated list selection. One way to resolve this would be to refresh the photos cached locally, this would result in another call to the Unsplash api but I felt this was undesirable. Finding a shared transform of the results from Unsplash and the favourites returned from the database that could be used by both the Search and Favourites page would have been a nicer solution.

Future improvements include:

  • Tests
  • Authentication/authorization (or at least local storage)
  • Animations
  • Share lists with friends
  • Lazy loading
  • Error handling
  • Unlimited scroll/pagination

unsplash-prisma's People

Watchers

James Cloos avatar Jordon McKoy 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.