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.
- 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
bcryptjsand one-hour JWTs withjsonwebtoken. - Live connections: Socket.IO clients can join a room by user ID.
- Snapshot CLI:
init,add,commit,push,pull, andrevertcommands. - Object storage: The snapshot CLI uploads and downloads commit files with AWS S3.
- Node.js and npm
- A MongoDB instance
- AWS credentials available through the AWS SDK credential provider chain if using
pushorpull
-
Install the dependencies:
npm install
-
Create a
.envfile in the project directory:PORT=3000 MONGODB_URI=mongodb://127.0.0.1:27017/githubclone JWT_SECRET_KEY=replace-with-a-long-random-secret
PORTis optional and defaults to3000.MONGODB_URIis used by Mongoose and the native MongoDB client. The user handlers explicitly select thegithubclonedatabase, so use that database name in the URI to keep user, repository, and issue data together.JWT_SECRET_KEYis used to sign login and signup tokens. -
Start the server:
npm start
The server listens on
http://localhost:3000unlessPORTis set.GET /returnsWelcome!.
The package has no test or lint scripts configured.
All routes are mounted at the server root. Request bodies are JSON.
| 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.
| 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.
| 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. |
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>initcreates.prashGit/and itscommits/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 incommit.json.- Committing does not clear the staging directory; staged files remain available to subsequent commits.
pushuploads files under local commits to S3.pulldownloads S3 objects under thecommits/prefix into.prashGit/.revert <commit-id>copies files from a local commit snapshot into the parent directory of.prashGit/.
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.
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 (*).
- 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 /allUsersandGET /userProfile/:idreturn 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.
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