GithubHelp home page GithubHelp logo

kevincubas / spacetime-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 1.05 MB

Backend application - Time capsule to collect memorable moments from your journey, developed during NLW Spacetime

TypeScript 100.00%
crud fastify fastify-cors fastify-jwt node oauth prisma sqlite typescript axios

spacetime-server's Introduction

NLW - Spacetime SERVER

Back-end Time capsule designed to help you collect your most memorable moments. This README document provides an overview of the features, used technologies, and functionalities of the application, as well as instructions on how to set it up and use it effectively.

You may find the frontend application in the following repo: FrontendApp

Technologies Used:

Features:

  • Authentication: The application retrieves the access token and user information from GitHub and creates a user in the database if they are not already registered. A JWT (JSON Web Token) is generated and returned to the frontend for subsequent API requests.

  • GET memories: This action retrieves all the memories created by the user. The backend fetches the memories associated with the user ID from the database and returns them as a list.

  • GET memory details(get by id):The backend fetches the memory from the database based on the provided memoryId. If the memory is public, it can be accessed by other users as well. The details of the memory, including its description, media, visibility, and creation timestamp, are returned to the frontend.

  • Create(POST) new memory: The user provides the necessary details such as description, media (image or video), and visibility (public or personal). Associates the memory with the user, and saves it in the database.

  • Edit(PUT) Memory: verifies that the memory belongs to the authenticated user, and updates the corresponding record in the database.

  • Delete(DELETE) Memory: verifies that the memory belongs to the authenticated user and deletes the corresponding record from the database. This action is irreversible, and once a memory is deleted, it cannot be recovered.

Routes

  • /auth: Handles authentication with GitHub, retrieves access tokens, and creates users in the database.
  • /memories: CRUD operations for memories with JWT verification.
  • /uploads: Handles media local uploads, validates the format and file size, and return the URL to the front.

Prisma Schema

The databe of the application is the SQLite. It consists of two models:

  • User: Represents a user in the system and stores their GitHub information.
  • Memory: Represents a memory created by a user, including the associated user ID, cover URL, content, visibility status, and creation timestamp.

Installation and Setup:

Requirements

  • Node: 17 or latest version
  • NPM: 9 or latest version (NPM is included with Node)
  • GIT

GITHUB OAuth token AND .env set up

  1. Go to the GitHub Developer Settings page: https://github.com/settings/developers.

  2. Click on "New OAuth App" to create a new OAuth App.

  3. Fill in the following information for your OAuth App:

  • Application Name: Choose a name for your application.
  • Homepage URL: http://localhost:3000. - change port if necessary.
  • Authorization callback URL: Enter the callback URL where GitHub will redirect users after authentication. For local development, we are using http://localhost:3000/api/auth/callback in the frontend
  1. Click on "Register Application" to create the OAuth App.

After creating the OAuth App, you will see the "Client ID" and "Client Secret" on the OAuth App page. These credentials will be used to authenticate your application with GitHub.

  1. In your project, create a .env file in the root directory if it doesn't already exist.

  2. Set the DATABASE_URL environment variable

DATABASE_URL="file:./dev.db"
  1. Set the GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET environment variables, replacing <CLIENT_ID> and <client_secret> with your actual credentials obtained from the GitHub OAuth App page:
GITHUB_CLIENT_ID=<client_id>
GITHUB_CLIENT_SECRET=<client_secret>

Remember to keep your GitHub Client ID and Client Secret secure and never expose them publicly.

Steps to install and run:

  1. Clone the repository
  git clone https://github.com/kevinCubas/spacetime-server.git
  1. Change into the project directory:
cd spacetime-server
  1. Install dependencies using npm:
  npm install
  1. Run the application locally: port 3333
  npm run dev

Contributing

To contribute to this project, please follow these guidelines:

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit them using Conventional Commits
  4. Push to the branch: git push origin feature/your-feature-name
  5. Submit a pull request

Contributors:

KevinCubas

spacetime-server's People

Contributors

kevincubas avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

franciscodara

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.