Coding Standards - Vinuyans/Mega_Chug_Lords-SOEN341_Project_F24 GitHub Wiki

General Guidelines

Version Control

Pull Requests: Always create a PR and request at least one review and approval before merging.

Frontend (React)

File Structure Organize components in a modular fashion:

src/
├── components/
│   ├── Header/
│   │   └── Header.jsx
├── pages/
│   ├── HomePage.jsx
│   ├── LoginPage.jsx
└── App.jsx

Use PascalCase for component files (Header.jsx).

Hooks:

  • Use useState and useEffect instead of class components.
  • Extract reusable logic into custom hooks (useAuth, useFetch).

State Management:

Use Context API or Redux for shared state.

Express/Node

Naming Conventions

  • Files: Use camelCase for filenames (authMiddleware.js).
  • Variables: Use descriptive names in camelCase (userName, errorHandler).
  • Constants: Use UPPERCASE for constants (JWT_SECRET).

Error Handling

  • Use try-catch blocks in all asynchronous functions.
  • Always return meaningful error messages.

Environment Variables

Store sensitive information like database URIs and API keys in a .env file. Use dotenv to load these variables.

Database (MongoDB)

Schema Design

  • Use Mongoose for schema validation.
  • Follow the naming convention:
    • Collection Names: Use lowercase (e.g., user, orders).
    • Fields: Use snake_case for property names (e.g., first_name, order_date).

Tools and Automation

  • ESLint: Linting separate rules for frontend and backend.
  • Husky: Run pre-commit hooks to ensure testing when committing.
  • Jest: For unit testing backend code.