Software Development Lifecycle (SDLC)
The Software Development Lifecycle is the process of planning, developing, testing, and deploying software applications. It ensures that software is built in a structured and efficient manner while maintaining quality.
1. Source Control (Git)
Source control is a system that tracks changes to the codebase, allowing multiple developers to collaborate without overwriting each other’s work. Git is the most widely used version control system.
Why use source control?
- Keeps track of every change in the code.
- Allows multiple developers to work on the same project without conflicts.
- Provides a history of code changes (useful for debugging and rollbacks).
- Supports collaboration through repositories like GitHub, GitLab, and Bitbucket.
# Common Git Commands:
git init # Initialize a Git repository
git clone <repo_url> # Clone an existing repository
git status # Check the status of changes
git add . # Stage changes
git commit -m "Commit message" # Save changes locally
git push # Push changes to a remote repository
git pull # Fetch and merge changes from the remote repository
2. Forking & Branching
Forking
Forking is when you create an independent copy of a repository. This is useful when contributing to open-source projects or making personal modifications.
Example Use Case:
- You fork a repository from GitHub, make changes in your copy, and then submit a pull request to the original repository.
Branching
Branching allows developers to create a separate version of the codebase to work on new features or fixes without affecting the main (production) code.
Types of Branches in Git:
- Main (Master) Branch: The stable, production-ready branch.
- Feature Branch: A separate branch for developing new features.
- Bug Fix Branch: Created to address a specific bug.
- Release Branch: A stable branch prepared for deployment.
# Common Git Branching Commands:
git branch feature-xyz # Create a new branch
git checkout feature-xyz # Switch to a branch
git checkout -b new-feature # Create and switch to a new branch
git merge feature-xyz # Merge a branch into the main branch
git branch -d feature-xyz # Delete a branch
3. Testing & Verification
Testing ensures that code changes work correctly before being merged into the main branch or deployed.
Types of Testing:
- Unit Testing: Tests individual functions or components.
- Integration Testing: Ensures different parts of the application work together.
- End-to-End Testing: Simulates user behavior to test the entire application.
- Automated Testing: Runs pre-written test cases automatically.
// Example of Unit Testing in JavaScript (Using Jest):
function add(a, b) {
return a + b;
}
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
- Continuous Integration (CI): Tools like GitHub Actions, Jenkins, and Travis CI automatically test code when changes are pushed.
4. Pull Requests & Merging
A pull request (PR) is a request to merge changes from one branch into another (usually into the main branch). This allows other developers to review the code before it gets added to the main project.
- Pull Request Workflow:
- Create a new branch and make changes.
- Push the changes to a remote repository.
- Open a pull request (PR).
- Reviewers provide feedback or approve the PR.
- If approved, the PR is merged into the main branch.
- Merging Strategies:
- Merge Commit (git merge): Keeps all commit history.
- Rebase (git rebase): Applies changes on top of the main branch for a cleaner history.
- Squash and Merge: Combines multiple commits into one before merging.
5. Deployment
Deployment is the process of making the software available for users.
- Types of Deployment:
- Development Environment: Used for internal testing.
- Staging Environment: A production-like environment for final testing.
- Production Environment: The live application used by real users.
- Common Deployment Methods:
- Manual Deployment: Uploading files to a server.
- Automated Deployment (CI/CD Pipelines): Uses tools like GitHub Actions, Jenkins, or Docker to automate deployment.
- Containerization (Docker, Kubernetes): Packages applications into containers for easy deployment.