FR
User Authentication:-Login and registration must be secure
Repository Management:-Create,update and delete repositories
Branching and Merging:-Support for branching and merging
File Management:-Upload,updating and deleting repositories
Commit Tracking:-Record and managing commit done by the user
Pull Requests:-Users can submit pull requests to propose changes to repositories
Issue Tracking:-Users can create,assign and close issues related to repositories
Collaboration:-Support for multiple users collaborating on same repo.
Review and commenting on code changes.
Should support high number of concurrent users
NFR
1.Highly available
2.Highly scalable
3.Eventual Consistent system
4.Low latency while merging branches /searching
5.Must be secure
API’s
1.Register User (POST /api/v1/users/register
)
request
{
"username": "johndoe",
"email": "johndoe@example.com",
"password": "password123"
}
response
{
"user_id": 1,
"message": "User registered successfully."
}
2.Login User (POST /api/v1/users/login
)
request
{
"email": "johndoe@example.com",
"password": "password123"
}
response
{
"token": "jwt-token",
"user_id": 1
}
3.Create Repository (POST /api/v1/repositories/create
)
request
{
"name": "example-repo",
"description": "Repository for example code."
}
response
{
"repository_id": 1,
"message": "Repository created successfully."
}
4 Get Repository (GET /api/v1/repositories/{repository_id}
)
response
{
"repository_id": 1,
"name": "example-repo",
"description": "Repository for example code.",
"owner_id": 1,
"created_at": "2024-10-22T10:00:00Z"
}
5.Update Repository (PUT /api/repositories/{repository_id}
)
request
{
"name": "updated-repo-name",
"description": "Updated description."
}
response
{
"repository_id": 1,
"message": "Repository updated successfully."
}
6.Delete Repository (DELETE /api/repositories/{repository_id}
)
response
{
"repository_id": 1,
"message": "Repository deleted successfully."
}
7.Create Branch (POST /api/repositories/{repository_id}/branches
)
request
{
"name": "feature-branch"
}
response
{
"branch_id": 1,
"message": "Branch created successfully."
}
8.Get Branches (GET /api/repositories/{repository_id}/branches
)
response
[
{
"branch_id": 1,
"name": "main"
},
{
"branch_id": 2,
"name": "feature-branch"
}
]
9.Create Commit (POST /api/branches/{branch_id}/commits
)
request
{
"user_id": 1,
"message": "Initial commit",
"file_changes": [
{
"file_path": "/src/main.cpp",
"content": "int main() { return 0; }"
}
]
}
response
{
"commit_id": 1,
"message": "Commit created successfully."
}
10.Get Commit History (GET /api/branches/{branch_id}/commits
)
[
{
"commit_id": 1,
"message": "Initial commit",
"timestamp": "2024-10-22T12:00:00Z"
},
{
"commit_id": 2,
"message": "Added main function",
"timestamp": "2024-10-23T08:15:00Z"
}
]
11.(POST /api/repositories/{repository_id}/pull-requests
)
request
{
"source_branch_id": 1,
"target_branch_id": 2,
"title": "Add feature X",
"description": "Implements feature X."
}
response
{
"pull_request_id": 1,
"message": "Pull request created successfully."
}
12.Get Pull Request Status (GET /api/pull-requests/{pull_request_id}
)
response
{
"pull_request_id": 1,
"status": "open",
"title": "Add feature X",
"description": "Implements feature X.",
"created_at": "2024-10-22T12:30:00Z"
}
13.Merge Pull Request (POST /api/pull-requests/{pull_request_id}/merge
)
{
"pull_request_id": 1,
"status": "merged",
"message": "Pull request merged successfully."
}
Schema Design
User table
CREATE TABLE User (
user_id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Repository Table
CREATE TABLE Repository (
repository_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
owner_id INT NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (owner_id) REFERENCES User(user_id)
);
Branch Table
CREATE TABLE Branch (
branch_id INT PRIMARY KEY AUTO_INCREMENT,
repository_id INT NOT NULL,
name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (repository_id) REFERENCES Repository(repository_id),
UNIQUE (repository_id, name)
);
Commit Table
CREATE TABLE Commit (
commit_id INT PRIMARY KEY AUTO_INCREMENT,
branch_id INT NOT NULL,
user_id INT NOT NULL,
message TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (branch_id) REFERENCES Branch(branch_id),
FOREIGN KEY (user_id) REFERENCES User(user_id)
);
File Table
CREATE TABLE File (
file_id INT PRIMARY KEY AUTO_INCREMENT,
branch_id INT NOT NULL,
file_path VARCHAR(255) NOT NULL,
content MEDIUMBLOB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (branch_id) REFERENCES Branch(branch_id),
UNIQUE (branch_id, file_path)
);
Pull Requests Table
CREATE TABLE PullRequest (
pull_request_id INT PRIMARY KEY AUTO_INCREMENT,
repository_id INT NOT NULL,
source_branch_id INT NOT NULL,
target_branch_id INT NOT NULL,
author_id INT NOT NULL,
title VARCHAR(255),
description TEXT,
status ENUM('open', 'closed', 'merged') DEFAULT 'open',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (repository_id) REFERENCES Repository(repository_id),
FOREIGN KEY (source_branch_id) REFERENCES Branch(branch_id),
FOREIGN KEY (target_branch_id) REFERENCES Branch(branch_id),
FOREIGN KEY (author_id) REFERENCES User(user_id)
);
Issues Table
CREATE TABLE Issue (
issue_id INT PRIMARY KEY AUTO_INCREMENT,
repository_id INT NOT NULL,
author_id INT NOT NULL,
assignee_id INT,
title VARCHAR(255),
description TEXT,
status ENUM('open', 'in_progress', 'closed') DEFAULT 'open',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (repository_id) REFERENCES Repository(repository_id),
FOREIGN KEY (author_id) REFERENCES User(user_id),
FOREIGN KEY (assignee_id) REFERENCES User(user_id)
);
Collaboration Table
CREATE TABLE Collaboration (
collaboration_id INT PRIMARY KEY AUTO_INCREMENT,
repository_id INT NOT NULL,
user_id INT NOT NULL,
role ENUM('admin', 'contributor', 'viewer') DEFAULT 'viewer',
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (repository_id) REFERENCES Repository(repository_id),
FOREIGN KEY (user_id) REFERENCES User(user_id),
UNIQUE (repository_id, user_id)
)
Review Table
CREATE TABLE Review (
review_id INT PRIMARY KEY AUTO_INCREMENT,
pull_request_id INT NOT NULL,
reviewer_id INT NOT NULL,
comment TEXT,
status ENUM('approved', 'rejected', 'commented') DEFAULT 'commented',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (pull_request_id) REFERENCES PullRequest(pull_request_id),
FOREIGN KEY (reviewer_id) REFERENCES User(user_id)
);
Comments Table
CREATE TABLE Comment (
comment_id INT PRIMARY KEY AUTO_INCREMENT,
issue_id INT,
pull_request_id INT,
author_id INT NOT NULL,
comment TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (issue_id) REFERENCES Issue(issue_id),
FOREIGN KEY (pull_request_id) REFERENCES PullRequest(pull_request_id),
FOREIGN KEY (author_id) REFERENCES User(user_id)
);