Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

GitHub Clone Backend

This project is a Node.js backend for a GitHub-inspired application. It contains an Express JSON API for users, repositories, and issues, a Socket.IO server, and a separate command-line workflow for creating and syncing local repository snapshots.

What's included

  • HTTP API: Express routes for account registration and login, user profiles, repositories, and issues.
  • Persistence: MongoDB. User handlers use the native MongoDB driver; repository and issue handlers use Mongoose.
  • Authentication primitives: Password hashing with bcryptjs and one-hour JWTs with jsonwebtoken.
  • Live connections: Socket.IO clients can join a room by user ID.
  • Snapshot CLI: init, add, commit, push, pull, and revert commands.
  • Object storage: The snapshot CLI uploads and downloads commit files with AWS S3.

Requirements

  • Node.js and npm
  • A MongoDB instance
  • AWS credentials available through the AWS SDK credential provider chain if using push or pull

Setup and run the API

  1. Install the dependencies:

    npm install
  2. Create a .env file in the project directory:

    PORT=3000
    MONGODB_URI=mongodb://127.0.0.1:27017/githubclone
    JWT_SECRET_KEY=replace-with-a-long-random-secret

    PORT is optional and defaults to 3000. MONGODB_URI is used by Mongoose and the native MongoDB client. The user handlers explicitly select the githubclone database, so use that database name in the URI to keep user, repository, and issue data together. JWT_SECRET_KEY is used to sign login and signup tokens.

  3. Start the server:

    npm start

    The server listens on http://localhost:3000 unless PORT is set. GET / returns Welcome!.

The package has no test or lint scripts configured.

REST API

All routes are mounted at the server root. Request bodies are JSON.

Users

Method Path Request fields Description
POST /signup username, email, password Create an account and return { token, userId }.
POST /login email, password Authenticate and return { token, userId }.
GET /allUsers None Return all user documents.
GET /userProfile/:id None Return a user document by MongoDB ID.
PUT /updateProfile/:id email, optionally password Update the account email and/or password.
DELETE /deleteProfile/:id None Delete the user document.

Passwords are hashed during signup and when a password is updated. Signup and login JWTs expire after one hour.

Repositories

Method Path Request fields Description
POST /repo/create name, owner ID; optionally description, visibility, content, issues Create a repository. The owner ID can be sent as owner, userId, or userID.
GET /repo/all None List repositories, populating their owner and issues.
GET /repo/:id None Get one repository by ID, populating its owner and issues.
GET /repo/name/:name None Find repositories with the given name.
GET /repo/user/:userID None List repositories owned by a user.
PUT /repo/update/:id content, description Append content and/or replace the description.
PATCH /repo/toggle/:id None Toggle the repository's visibility boolean.
DELETE /repo/delete/:id None Delete a repository.

Repository names are unique in the schema. content is stored as an array of strings; on creation, a single value is converted to a one-item array.

Issues

Method Path Request fields Description
POST /issue/create repositoryId, title, description Create an issue linked to a repository.
POST /issue/create/:id title, description Create an issue linked to the repository ID in :id.
GET /issue/all None List all issues.
GET /issue/:id None Get one issue by ID.
PUT /issue/update/:id title, description, status Update an issue. status is open or closed and defaults to open.
DELETE /issue/delete/:id None Delete an issue.

Snapshot CLI

The CLI stores local state in a .prashGit/ directory under the current working directory. Run the commands from the project directory you want to snapshot. Replace <backend-path> with the path to this backend's directory:

node <backend-path>/index.js init
node <backend-path>/index.js add README.md
node <backend-path>/index.js commit "Add project readme"
node <backend-path>/index.js push
node <backend-path>/index.js pull
node <backend-path>/index.js revert <commit-id>
  • init creates .prashGit/ and its commits/ directory.
  • add <file> copies the selected file into .prashGit/staging/.
  • commit <message> creates a UUID-named snapshot from the staged files and records the message and timestamp in commit.json.
  • Committing does not clear the staging directory; staged files remain available to subsequent commits.
  • push uploads files under local commits to S3.
  • pull downloads S3 objects under the commits/ prefix into .prashGit/.
  • revert <commit-id> copies files from a local commit snapshot into the parent directory of .prashGit/.

S3 configuration

The S3 client is currently configured in config/aws-config.js with region ap-southeast-2 and bucket ant-bucket-19. Configure AWS credentials using an AWS SDK-supported provider, and change those constants if your deployment uses a different region or bucket.

init writes the S3_BUCKET environment value to .prashGit/config.json, but the current push and pull implementations do not read that file; they use the bucket constant from config/aws-config.js.

Socket.IO

The HTTP server also hosts Socket.IO. After connecting, a client can emit joinRoom with a user ID to join the room named for that ID. The server currently allows cross-origin connections (*).

Security and operational notes

  • The API enables CORS for all origins.
  • JWTs are issued, but the included auth and authorization middleware are not mounted on the routes. API routes, including profile, repository, and issue operations, do not currently require a token.
  • GET /allUsers and GET /userProfile/:id return stored user documents, which include the password hash. Do not expose these endpoints publicly without restricting and filtering their responses.
  • Use a private, strong JWT_SECRET_KEY, configure production CORS and authentication/authorization, and review response fields before deploying.

Project layout

config/       AWS S3 configuration
controllers/  API handlers and snapshot CLI commands
middleware/   Auth and authorization middleware modules
models/       Mongoose user, repository, and issue schemas
routes/       Express route definitions
index.js      API server and CLI command entry point

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages