Introduction to SDLC and CI/CD: A Complete Guide with Coding Examples

Milad Fahmy
5 min readOct 4, 2024

--

Generated By AI

A fast-paced software development landscape, efficient development, and deployment practices are essential to meet the ever-growing demands of the tech world. This guide will walk you through two key concepts in modern software development: Software Development Life Cycle (SDLC) and Continuous Integration/Continuous Delivery (CI/CD).

We’ll explore each topic in detail, provide real-world coding examples, and illustrate how these concepts streamline the development processes. Whether you’re new to these ideas or looking for a deeper understanding, this article will make sure you walk away with a solid grasp.

Understanding the Software Development Life Cycle (SDLC)

What is SDLC?

The Software Development Life Cycle (SDLC) is a process used by software developers to design, develop, test, and deploy high-quality software. It is a set of well-defined steps that provide a structured approach to software creation. Following an SDLC helps ensure software is built efficiently and meets the needs of users.

Key Phases of SDLC:

Let’s break down each phase of SDLC using a practical scenario where a team is building a simple Task Management Application.

1. Planning

In the planning phase, the team outlines the project’s objectives, scope, resources, and timeline. It answers the questions: What are we building? Who is the user? What technologies will we use?*

Example:

  • Objective: Build a simple web app to allow users to add, edit, and track their daily tasks.
  • Technology Stack: MERN stack (MongoDB, Express, React, Node.js).

2. Requirement Analysis

In this phase, the team gathers and documents the specific functional requirements. It defines exactly what the software should do.

Example Requirements:

  • The user should be able to create a new task.
  • The user should be able to mark a task as completed.
  • The user should be able to edit or delete a task.

These requirements can be documented in a Software Requirement Specification (SRS) document.

3. Design

The design phase involves creating the system architecture, database schema, and user interface (UI). This is where the overall structure of the software is outlined.

Example:

  • Database Design: MongoDB collection for tasks with fields like title, description, status, and due_date.
{
"title": "Finish article",
"description": "Complete the SDLC and CI/CD article",
"status": "in-progress",
"due_date": "2024-10-05"
}
  • UI Design: A simple React-based interface with forms for task creation and a list view to display tasks.

4. Implementation (Coding)

The actual development of the software happens here. Developers write the code for the application.

Example Code (Task Creation in Node.js/Express):

const express = require('express');
const app = express();
const mongoose = require('mongoose');

app.use(express.json());

// MongoDB Schema
const taskSchema = new mongoose.Schema({
title: String,
description: String,
status: String,
due_date: Date,
});

const Task = mongoose.model('Task', taskSchema);

// API endpoint to create a new task
app.post('/tasks', async (req, res) => {
const { title, description, status, due_date } = req.body;
const newTask = new Task({ title, description, status, due_date });
await newTask.save();
res.status(201).send('Task Created');
});

mongoose.connect('mongodb://localhost/taskdb', { useNewUrlParser: true })
.then(() => console.log('MongoDB connected'))
.catch((err) => console.error('MongoDB connection failed', err));

app.listen(3000, () => console.log('Server running on port 3000'));

5. Testing

Testing ensures the software works as intended. Unit testing, integration testing, and system testing are all done to catch bugs early.

Example Unit Test with Jest (Testing Task Creation):

const request = require('supertest');
const app = require('../app'); // Your express app

describe('POST /tasks', () => {
it('should create a new task', async () => {
const res = await request(app)
.post('/tasks')
.send({
title: 'Test task',
description: 'Testing the task creation API',
status: 'pending',
due_date: '2024-10-10'
});

expect(res.statusCode).toEqual(201);
expect(res.text).toEqual('Task Created');
});
});

6. Deployment

After testing, the application is deployed to a live environment (such as AWS, Heroku, or another cloud provider). This makes it accessible to end users.

7. Maintenance

Once the application is live, it requires ongoing maintenance to fix bugs, add new features, and handle security issues.

What is CI/CD?

Generated By AI

CI/CD stands for Continuous Integration (CI) and Continuous Delivery (CD) (or Continuous Deployment). It automates the integration, testing, and deployment of code, making it faster and less error-prone to release new software.

Continuous Integration (CI):

CI ensures that code changes from multiple developers are automatically tested and merged into a shared repository regularly (e.g., several times a day). This helps catch bugs early and improves collaboration.

Example CI Workflow:

  1. Developer A commits code to the repository.
  2. The CI pipeline automatically triggers:
    - Code is pulled from the repository.
    - Automated tests are run.
    - If tests pass, the code is merged into the main branch.

Example of a Simple CI Pipeline (GitHub Actions):

name: CI Pipeline

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test

Continuous Delivery (CD):

CD automates the process of preparing the code for release. After successful CI, the code is automatically deployed to staging environments for further testing. In Continuous Deployment, it is automatically pushed to production if all tests pass.

Example CD Workflow:

  1. After CI passes, the code is deployed to a staging environment.
  2. If approved, the code is promoted to the production environment.

Example of a CD Pipeline (Jenkins):

pipeline {
agent any

stages {
stage('Build') {
steps {
echo 'Building...'
sh 'npm install'
}
}
stage('Test') {
steps {
echo 'Testing...'
sh 'npm test'
}
}
stage('Deploy') {
steps {
echo 'Deploying to Staging...'
sh 'npm run deploy:staging'
}
}
}
}

In the example above, once the testing phase is complete, Jenkins automatically deploys the application to a staging environment for further evaluation.

Illustrating SDLC and CI/CD with Diagrams

SDLC Flow Diagram:

Below is an illustration of the entire SDLC process:

This flowchart illustrates how each phase of the SDLC is interconnected.

CI/CD Pipeline Diagram:

This diagram shows a typical CI/CD pipeline.

How CI/CD Enhances SDLC

  • Speed: With CI/CD, software is integrated and delivered continuously, shortening the development cycle.
  • Automation: Automating testing, integration, and deployment reduces manual errors.
  • Quality: Continuous testing ensures bugs are caught early, improving overall software quality.
  • Collaboration: CI/CD promotes better collaboration between development, testing, and operations teams.

Conclusion

In this article, we explored the Software Development Life Cycle (SDLC) and the CI/CD pipeline, essential concepts for modern software development. SDLC helps guide the development process, ensuring software is built systematically. CI/CD, on the other hand, automates the integration and delivery of code, making the development process faster, more efficient, and more reliable.

By incorporating CI/CD into SDLC, teams can create a seamless workflow that enhances the speed and quality of software delivery, making both developers and users more satisfied with the end result.

Now, you’re equipped with a solid understanding of these critical concepts and their real-world applications. Ready to take the plunge and implement them in your projects? Let’s get coding!

--

--

Milad Fahmy
Milad Fahmy

Written by Milad Fahmy

I’m a JS Champion, I wrote about software engineering. I’m currently developing various open-source projects (like: https://encrypt-rsa.js.org)

No responses yet