Skip to content

Comprehensive backend development journey from scratch with Node.js, Express, and MongoDB. Covers core concepts, APIs, authentication, and database integration to build scalable server-side applications.

Notifications You must be signed in to change notification settings

devsiffy/Backend-Development-from-Scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–₯️ Backend Mastery: From Zero to Backend Hero πŸ”₯

NOTE:- The "must_change.env" must require some changes;
     > remove the word "must_change.env" and change it into ".env" only
     > replace values with your own credentials inside .env file

πŸ“… Day 01

"The journey of a thousand miles begins with one step."

  1. Project Initialization

    • package.json setup
    • Install Express & dotenv
  2. Configuration

    • Create .env file (PORT)
    • Build server (index.js)
  3. Routing & Server

    • Define GET routes (/, /login, /signup)
    • Start server

πŸ“… Day 02

"Code is like humor. When you have to explain it, it’s bad."

  1. API Fundamentals

    • What is an API
    • Role in frontend-backend communication
  2. Working with APIs in React

    • Fetch vs Axios comparison
    • Axios GET request with then() & catch()
    • Best practices (useEffect, useState, error handling)
  3. Handling CORS Issues

    • What is CORS
    • Proxy setup in Vite
    • Backend solutions (cors package, headers)

πŸ“… Day 03

"Structure your data before you build β€” clean models lead to clean code."

  1. Data Modeling Basics

    • Object modeling purpose
    • Benefits of early planning
  2. Introduction to Mongoose

    • What is Mongoose
    • Schemas and models
  3. Project Structure & Naming Conventions

    • models/ folder setup
    • File naming patterns
  4. Schema Definition Essentials

    • Field types and rules
    • Common validations (required, unique, min, etc.)
    • Timestamps for created/updated tracking
    • Model Relationships: Using ref for associations

πŸ“… Day 04

"Learning to write programs stretches your mind, and helps you think better."

  1. Data Modeling Practice

    • E-Commerce Store Schema Design
    • Hospital Management System Schema Design
  2. Exploring Mongoose Concepts

    • Review: models/ecommerce/
    • Review: models/hospital_management/

πŸ“… Day 05

"A well-structured project is the foundation of professional software development."

  1. UI/UX Design & DB Planning Phase

    • Design all screens using tools like Figma
    • Collect data points for DB
    • Create data modeling diagram (with tools like Eraser.io)
  2. Project Initialization & Structuring

    • Initialize package.json with npm init
    • Setup common folders: src, public, controllers, routes, etc.
    • Create essential files: .env, .gitignore, README.md, etc.
  3. Development Tools Setup

    • Install nodemon for auto-restart
    • Install prettier for consistent formatting
  4. Files Configuration

    • Use online generator to create .gitignore for Node.js
    • Add .prettierrc and .prettierignore files
    • Update package.json for modules and scripts

πŸ“… Day 06

"Build software the way real teams do – step by step, piece by piece."

  1. MongoDB Atlas

    • Create account, project, cluster
    • Save URI in .env
  2. DB Connection

    • Two connection approaches: Direct connect in index.js (less modular) Use src/db/connection.js
    • Best Practices: Use async/await + try/catch
  3. Import Rules

    • Load dotenv at top of entry file
    • Add .js extension to imports
    • Keep secrets in .env
    • Keep index.js clean

πŸ“… Day 07

"Building real-world back-end architecture step by step."

  1. Express App Setup (app.js)

    • Middlewares: cors, cookieParser, express.json, etc.
  2. Server Initialization (index.js)

    • DB connection, server start, and error handling
  3. Utility Modules (utils/)

    • asyncHandler.js – async error wrapper
    • ApiError.js – custom error class
    • ApiResponse.js – consistent success responses

πŸ“… Day 08

"Professional backend development through real-world modeling techniques."

  1. Model Structure & Setup

    • Created user.model.js and video.model.js using Mongoose
    • Used ObjectId references, timestamps, and schema validation

  2. User Model & Authentication

    • Defined user fields
    • Password hashing with bcrypt using Mongoose pre-save middleware
    • Custom methods for authentication:
      • Password verification (bcrypt)
      • JWT generation (jsonwebtoken) for access & refresh tokens
    • Stored secrets and token expiry settings in .env
  3. Video Model & Pagination

    • Defined video fields
    • Linked each video to its owner (User)
    • Added pagination support using mongoose-aggregate-paginate-v2

πŸ“… Day 09

"Code is the bridge between imagination and reality; every bug you fix is a step forward."

  1. Cloudinary Setup

    • Creating an account and adding credentials in .env
    • Installing npm package cloudinary and configure
    • Functions to upload files and handle errors
  2. Multer Setup

    • Installing npm package multer
    • Define multer as middleware
    • Multer uses for temporary file storage, and works with Cloudinary

πŸ“… Day 10

"The web speaks in protocols β€” learn their language to unlock endless possibilities."

  1. HTTP Basics

    • Overview
    • HTTP vs HTTPS
    • Client-Server Model
    • URL, URI, URN
  2. HTTP Headers

    • Purpose and importance
    • Types: Request, Response, Representation, Payload
    • Key headers: Authorization, Content-Type, CORS
  3. HTTP Methods

    • Main verbs: GET, POST, PUT, PATCH, DELETE
    • Others: HEAD, OPTIONS, TRACE
  4. HTTP Status Codes

    • Categories: 1xx to 5xx
    • Common codes: 200, 201, 400, 401, 403, 404, 500

πŸ“… Day 11

"Building like a pro β€” following real-world back-end development practices."

  1. Express Router & Route Management

    • Using Express Router
    • Exporting and importing router in app.js
    • Mounting routes with app.use()
  2. Controller Functions & JSON Responses

    • Writing controller functions
    • Sending JSON responses with status codes
    • Example: registerUser controller returning a success message
  3. Error Handling with asyncHandler

    • Wrapping controllers to handle async errors
    • Avoiding repetitive try-catch blocks
    • Passing errors to Express using next(error)
  4. API Testing with Postman

    • Creating collections and requests
    • Testing POST routes like /register
    • Verifying JSON response and status codes

πŸ“… Day 12

"Building like real professionals, one step at a time."

  1. User Registration Workflow

    • Input validation and duplication checks
    • Image handling and upload (avatar, cover)
    • User creation and sensitive data filtering
    • Structured API response to frontend
  2. File Management

    • Local file handling with Multer
    • Cloudinary integration for media uploads
  3. Error Handling & API Response

    • Centralized error responses using ApiError
    • Consistent success responses via ApiResponse

πŸ“… Day 13

"Building like real devs β€” one step at a time."

  1. User Registration API

    • Testing /api/v1/users/register using POSTMAN
    • Required form-data fields: fullName, email, username, password, avatar, coverImage
    • Backend tasks: validation, duplication checks, Cloudinary upload, DB save, response handling
  2. Cloudinary Bug Fixes

    • Bug in cloudinary.js due to delayed dotenv.config()
    • Environment variables not loading (CLOUDINARY_CLOUD_NAME, etc.)
    • Fixes applied in:
      • src/index.js (moved dotenv.config() above imports)
      • package.json (nodemon -r dotenv/config ...)
  3. Local File Cleanup After Upload

    • Deleting uploaded files from public/temp after Cloudinary upload
    • Using fs.unlinkSync() in both success and error cases
  4. Professional Use of POSTMAN

    • Organizing with Collections (e.g., MediaTube) and Folders (e.g., user)
    • Creating and using Environment Variables (server = base URL)
    • Replacing hardcoded URLs with {{server}} variable in requests

πŸ“… Day 14

"Building a real-world back-end system using professional development practices."

  1. Authentication Flow

    • /login Route
    • /logout Route
    • loginUser Controller
    • logoutUser Controller
  2. Token Management

    • Access & Refresh Token Generator
    • Sending Tokens as Secure Cookies
    • Removing Tokens via Cookies on Logout
  3. Security Middleware

    • verifyJWT Middleware for Protected Routes
    • Token Validation via Cookies or Headers

πŸ“… Day 15

"Simulating a real-world back-end development process used in professional software companies."

  1. Authentication Route Testing

    • Testing /login and /logout using POSTMAN
    • Expected request structure and responses
    • Cookie handling for tokens
  2. Login Controller Debugging

    • Common login issues (missing fields, invalid credentials, etc.)
    • Proper use of async/await and error handling
    • Security tips: avoid exposing sensitive data
  3. Token-Based Authentication

    • Access Token: purpose, lifespan, and usage
    • Refresh Token: role in session management and renewal
    • Key differences between access and refresh tokens
    • How both tokens work together in maintaining user sessions
  4. Refresh Token Implementation

    • /refresh-token route functionality
    • Validating refresh tokens and issuing new tokens
    • Security practices: HttpOnly cookies, database checks
    • Frontend behavior on token expiration

πŸ“… Day 16

"Building a scalable backend by following real-world development practices."

  1. Subscription Model

    • Mongoose schema for user-to-user subscriptions
    • Fields: subscriber, channel (both linked to User model)
    • Includes timestamps for creation and updates
  2. User Account Management

    • Password Management: Change current password with verification

    • Profile Information: Get current logged-in user details Update full name and email (excluding password)

    • Media Uploads: Update user avatar (profile picture) Update cover image (banner)


πŸ“… Day 17

"Note:- You can see the 'day 17.png' image for visual understanding"

  1. Designing the Subscription Model

    • Purpose of the Subscription Model
    • Why not use arrays in the User schema
    • One subscription per document structure
    • Advantages of this Approach
  2. Querying Subscriptions

    • Counting a channel’s subscribers
    • Listing channels a user has subscribed to

πŸ“… Day 18

"Building real-world features using professional backend practices."

  1. MongoDB Aggregation Pipeline

    • What is Aggregation Pipeline
    • Why and when to use it
    • Benefits for complex data querying
  2. Aggregation Stages

    • $match – Filter documents
    • $lookup – Join collections
    • $addFields – Add or modify fields
    • $project – Select specific fields
    • $sort, $limit, $group, $unwind
  3. Common Operators

    • $in – Check if value exists in array
    • $cond – If-then-else logic
    • $size, $eq, $and, $or

πŸ“… Day 19

"Building real-world back-end features, step by step, like a pro."

  1. Watch History Feature

    • Defining getWatchHistory controller
    • MongoDB Aggregation Pipeline usage
    • Step-by-step data retrieval and joining
  2. User Routes & Structure

    • Defining routes for controllers
    • Public Routes: /register, /login
    • Protected Routes: /logout, /history, /update-account, etc.
  3. Route Protection & Middleware

    • JWT authentication using verifyJWT
    • File upload handling with upload middleware

πŸ“… Day 20

"Expanding the backend with essential user and content models."

  1. Created More Models

    • Comment Model - content, video, owner

    • Like Model - video | comment | tweet, likedBy

    • Playlist Model - name, description, videos, owner

    • Tweet Model - content, owner


πŸ“… Day 21

Simple structure, clear steps, professional workflow.

  1. User Routes Tested

    • Tested all user routes using Postman
    • Fixed small bugs
    • Now user routes are working perfectly
  2. Routes & Controllers Setup

    • All routes defined in app.js
    • Created routes in src/routes/ for:
      • tweet, video, comment, like, playlist, subscription, dashboard
    • Created controllers in src/controllers/ with:
      • Empty methods
      • // TASK: comments showing what logic to add later
  3. What Do Next

    • Add real logic inside controller methods
    • Test each route using Postman
    • Make sure everything works correctly

About

Comprehensive backend development journey from scratch with Node.js, Express, and MongoDB. Covers core concepts, APIs, authentication, and database integration to build scalable server-side applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages