Setting Up Your Codebase: The Blueprint

1. Repository Types: What Kind of Project Are We Building?

  • Monorepo: Imagine a giant toolbox that holds all your different tools and projects. This is perfect when you have multiple related applications (like a website, a mobile app, and a backend service) that share common parts.
  • Backend Repository: This is where the “brains” of your application live. It handles all the data, logic, and services that run behind the scenes.
  • Frontend Repository: This is the “face” of your application—what users see and interact with, whether it’s a website or a mobile app.

2. Your Standard Development Environment (.vscode Folder)

  • settings.json: This file is like a rulebook for your code editor. It makes sure everyone formats code the same way (e.g., uses spaces instead of tabs, automatically formats when you save).
  • extensions.json: This lists recommended VS Code extensions, like tools for making your code look pretty (Prettier), checking for errors (ESLint), or understanding your code’s history (GitLens).
  • launch.json (optional): If you need special settings to “debug” or troubleshoot your code, they go here.
  • tasks.json (optional): For automating common actions like building your project or running tests.
  • Everyone gets the same coding experience, no matter their computer.
  • New team members can jump in easily without struggling with setup.
  • You avoid annoying “pull request” comments just about formatting issues.

Keeping Your Code Clean and Stable

3. Atomic Commits & Automated Checks

  • It must build successfully (like confirming your brick is solid).
  • It must pass linting (checking for style and potential errors).
  • All unit tests must pass (small automated checks to ensure your code works as expected).
  • Locally: Tools like Husky and lint-staged check your code before you even save it, giving you immediate feedback.
  • During Development: Automated “Continuous Integration/Continuous Deployment” (CI/CD) systems run these checks again before your changes can be added to the main project.

How We Work Together: Branching and Collaboration

4. Branching Strategy: Trunk-Based Development

  • main: This branch always represents the code that’s currently live and working perfectly for users.
  • stage: This is where all the new changes are gathered and tested together before being released to main. It’s like a rehearsal stage.
  • feature/*: For building brand new features.
  • bugfix/*: For fixing small issues.
  • hotfix/*: For urgent fixes that need to go live immediately to solve critical problems.

5. Branch Protection Rules

  • Pull Request Required: You can’t just push code directly; it needs to go through a review process.
  • CI/CD Checks Required: All those automated tests and checks must pass.
  • 1–2 Approving Reviewers: At least one (and preferably two) other team members must approve your changes.
  • Commit Signing Recommended: This helps verify who made what change.
  • Force Pushes Disabled: You can’t rewrite history on these branches.
  • Branch Deletion Disabled: These important branches can’t be accidentally deleted.

6. Standard Development Workflow: A Step-by-Step Guide

  • You grab the latest version of the stage branch.
  • Then, you create a new, dedicated branch for your task (e.g., feature/add-login-button).
  • As you code, you make small, focused changes and save them with clear messages (e.g., “feat: add user session handling”).
  • You push these changes to your feature branch.
  • A clear title following “Conventional Commits” rules (like feat: add user session handling).
  • A detailed explanation of what you did and why.
  • Screenshots or GIFs if you changed anything visual.
  • Links to any related issues (e.g., “Fixes #123”).
  • Assigned reviewers to check your work.
  • When merging a feature or bugfix branch, we typically “Squash & Merge,” which combines all your small commits into one clean commit for easier history.
  • When promoting changes from stage to main for a release, we use a “Standard Merge” to keep the full commit history.

Code Style and Quality: The Look and Feel

7. Code Formatting Standards: Tabs vs. Spaces

This is a universal rule:

  • All code must use spaces, not tabs, for indentation.
  • Standard indentation is 2 spaces.
  • Prettier: An automated code formatter.
  • ESLint: A tool that finds and fixes style issues and potential errors.
  • .vscode: Your editor’s settings.
  • CI/CD: Automated checks during development.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *