Skip to content

GitForge is an educational project that recreates Git's core functionality from the ground up to understand how version control systems work internally. It implements fundamental Git commands like init, add, commit, push, pull, and revert, while leveraging AWS S3 for remote storage instead of traditional Git servers.

Notifications You must be signed in to change notification settings

prathampmp23/GitForge-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitForge

GitForge Banner

A Git-Inspired Version Control System Built from Scratch

Features β€’ Tech Stack β€’ Installation β€’ Usage β€’ API Documentation


πŸ“– Overview

GitForge is an educational project that recreates Git's core functionality from the ground up to understand how version control systems work internally. It implements fundamental Git commands like init, add, commit, push, pull, and revert, while leveraging AWS S3 for remote storage instead of traditional Git servers.

This project combines a CLI tool for local version control operations with a full-stack web application for repository management, user authentication, and collaboration features.

🎯 Project Goals

  • Learn Git Internals: Understand how Git tracks changes, creates commits, and manages file snapshots
  • Cloud Storage Integration: Use AWS S3 as a remote repository storage solution
  • Full-Stack Development: Build a complete ecosystem with CLI tools and web interface
  • Real-World Application: Implement authentication, authorization, and collaboration features

✨ Features

πŸ› οΈ CLI Version Control

  • init - Initialize a new GitForge repository (.gitForge directory)
  • add <file> - Stage files for commit (move to staging area)
  • commit <message> - Create a snapshot with unique commit ID (UUID)
  • push - Upload commits to AWS S3 bucket
  • pull - Download commits from AWS S3 bucket
  • revert <commitID> - Revert repository to a specific commit

🌐 Web Application

  • User Management

    • User registration and authentication (JWT-based)
    • User profiles with activity heatmaps
    • Password encryption with bcrypt
  • Repository Management

    • Create and manage repositories
    • Public/private visibility settings
    • Star repositories
    • Repository content browsing
  • Issue Tracking

    • Create and manage issues
    • Link issues to repositories
    • Issue collaboration
  • Real-time Features

    • WebSocket integration with Socket.IO
    • Live updates and notifications

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Node.js JavaScript runtime environment
Express Web application framework
MongoDB NoSQL database for user/repo data
Mongoose MongoDB object modeling
AWS S3 Cloud storage for commits
Socket.IO Real-time bidirectional communication
JWT Authentication & authorization
Yargs CLI command parsing
UUID Unique commit ID generation

Frontend

Technology Purpose
React UI library
Vite Build tool & dev server
React Router Client-side routing
TailwindCSS Utility-first CSS framework
Axios HTTP client
Primer React GitHub's design system

πŸ“‚ Project Structure

GitForge/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── aws-config.js          # AWS S3 configuration
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ init.js                # Initialize repository
β”‚   β”‚   β”œβ”€β”€ add.js                 # Stage files
β”‚   β”‚   β”œβ”€β”€ commit.js              # Create commits
β”‚   β”‚   β”œβ”€β”€ push.js                # Upload to S3
β”‚   β”‚   β”œβ”€β”€ pull.js                # Download from S3
β”‚   β”‚   β”œβ”€β”€ revert.js              # Revert to commit
β”‚   β”‚   β”œβ”€β”€ userController.js      # User operations
β”‚   β”‚   β”œβ”€β”€ repoController.js      # Repository operations
β”‚   β”‚   └── issueController.js     # Issue operations
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ authMiddleware.js      # JWT authentication
β”‚   β”‚   └── authorizeMiddleware.js # Authorization checks
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ userModel.js           # User schema
β”‚   β”‚   β”œβ”€β”€ repoModel.js           # Repository schema
β”‚   β”‚   └── issueModel.js          # Issue schema
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ user.router.js         # User endpoints
β”‚   β”‚   β”œβ”€β”€ repo.router.js         # Repository endpoints
β”‚   β”‚   └── issue.router.js        # Issue endpoints
β”‚   β”œβ”€β”€ index.js                   # Entry point & CLI
β”‚   └── package.json
β”‚
└── frontend/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ auth/              # Login & Signup
    β”‚   β”‚   β”œβ”€β”€ dashboard/         # Main dashboard
    β”‚   β”‚   β”œβ”€β”€ repo/              # Repository components
    β”‚   β”‚   β”œβ”€β”€ user/              # User profile & heatmap
    β”‚   β”‚   └── issue/             # Issue components
    β”‚   β”œβ”€β”€ authContext.jsx        # Auth state management
    β”‚   β”œβ”€β”€ ProjectRoutes.jsx      # Route configuration
    β”‚   └── App.jsx
    └── package.json

πŸš€ Installation

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or Atlas)
  • AWS Account with S3 bucket access
  • Git (for cloning the repository)

1️⃣ Clone the Repository

git clone https://github.com/prathampmp23/GitForge-Backend
cd GitForge

2️⃣ Backend Setup

cd backend
npm install

Create a .env file in the backend directory:

PORT=3000
MONGODB_URI=mongodb://localhost:27017/gitforge
JWT_SECRET=your_jwt_secret_key_here

# AWS Configuration
AWS_REGION=your-aws-region
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
S3_BUCKET=your-s3-bucket-name

3️⃣ Frontend Setup

cd ../frontend
npm install

Create a .env file in the frontend directory (if needed):

VITE_API_URL=http://localhost:3000

4️⃣ AWS S3 Setup

  1. Create an S3 bucket in your AWS account
  2. Configure IAM user with S3 access permissions
  3. Update the .env file with your credentials

πŸ’» Usage

Running the Web Application

Start Backend Server:

cd backend
npm start

Server will run on http://localhost:3000

Start Frontend Dev Server:

cd frontend
npm run dev

Frontend will run on http://localhost:5173

Using the CLI Tool

Navigate to any directory where you want to use GitForge:

Initialize a Repository:

node backend/index.js init

Add Files to Staging:

node backend/index.js add myfile.txt

Commit Changes:

node backend/index.js commit "Initial commit"

Push to S3:

node backend/index.js push

Pull from S3:

node backend/index.js pull

Revert to a Commit:

node backend/index.js revert <commit-id>

πŸ” How It Works

Internal Architecture

1. Repository Initialization

When you run init, GitForge creates a .gitForge directory with:

.gitForge/
β”œβ”€β”€ config.json       # Configuration (S3 bucket name)
β”œβ”€β”€ commits/          # Stores all commits locally
└── staging/          # Temporary area for files to be committed

2. Adding Files

The add command copies files from your working directory to the .gitForge/staging area.

3. Creating Commits

The commit command:

  • Generates a unique UUID for the commit
  • Creates a new directory under .gitForge/commits/<uuid>/
  • Copies all files from staging to the commit directory
  • Saves metadata in commit.json (message, timestamp)

4. Push to Cloud

The push command:

  • Reads all commit directories
  • Uploads each file to S3 with the structure: commits/<commit-id>/<filename>
  • Uses AWS SDK for file transfer

5. Pull from Cloud

Downloads commits from S3 back to local .gitForge/commits directory.

6. Revert Operation

Restores your working directory to the state of a specific commit.


πŸ“‘ API Documentation

Authentication Endpoints

POST /auth/register    - Register new user
POST /auth/login       - Login user (returns JWT token)
GET  /auth/profile     - Get current user profile

Repository Endpoints

POST   /repos          - Create new repository
GET    /repos          - Get all repositories
GET    /repos/:id      - Get repository by ID
PUT    /repos/:id      - Update repository
DELETE /repos/:id      - Delete repository
POST   /repos/:id/star - Star/unstar a repository

Issue Endpoints

POST   /repos/:repoId/issues     - Create issue
GET    /repos/:repoId/issues     - Get all issues
GET    /issues/:id                - Get issue by ID
PUT    /issues/:id                - Update issue
DELETE /issues/:id                - Delete issue

πŸŽ“ Learning Outcomes

By building GitForge, you'll understand:

  • βœ… Version Control Internals: How Git tracks file changes using snapshots
  • βœ… File System Operations: Reading, writing, and managing directories in Node.js
  • βœ… Cloud Storage: Integrating AWS S3 for persistent storage
  • βœ… CLI Development: Building command-line tools with Yargs
  • βœ… Full-Stack Architecture: Connecting frontend, backend, and cloud services
  • βœ… Authentication: Implementing JWT-based auth with bcrypt
  • βœ… Real-time Communication: Using WebSockets with Socket.IO
  • βœ… Database Design: Modeling relationships with MongoDB and Mongoose

🀝 Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is open source and available under the ISC License.


πŸ™ Acknowledgments

  • Inspired by the internal workings of Git
  • Built as an educational project to understand version control systems
  • Thanks to the open-source community for the amazing tools and libraries

πŸ“§ Contact

Project Maintainer: Pratham Potdar


Made with ❀️ to understand Git better

⭐ Star this repo if you found it helpful!

About

GitForge is an educational project that recreates Git's core functionality from the ground up to understand how version control systems work internally. It implements fundamental Git commands like init, add, commit, push, pull, and revert, while leveraging AWS S3 for remote storage instead of traditional Git servers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published