Angular Development Standards and Best Practices Table of Contents Project Structure Naming Conventions Branching Strategy Pull Requests Repository Format Unit Testing Visual Testing with Storybook and Chromatic Code Reviews Security Best Practices Version Control Practices Documentation
-
Project Structure Use Angular CLI: Always generate components, services, and modules using Angular CLI to maintain consistency in the project structure. Folder Organization: Group feature modules together. Use a structure like this:
-
Naming Conventions Files and Directories: Use the kebab-case format. Example:
user-profile.component.ts
,auth.service.ts
. Components: Name components in PascalCase. Example:UserProfileComponent
. Services: Suffix service classes with Service. Example:AuthService
. Modules: Name modules with the suffix Module. Example:UserProfileModule
. Enum and Interface Names: Use PascalCase and prefix with I for interfaces. Example:IUserProfile
,UserRole
. -
Branching Strategy Branch Naming: Use a clear naming convention for branches. Features: feature/description Bug fixes: bugfix/description Hotfixes: hotfix/description Main Branch: Keep a stable main or develop branch that always reflects the latest production-ready code.
-
Pull Requests PR Descriptions: Clearly describe the purpose of the pull request, including what issue it addresses and any relevant details. Link Issues: Reference issues or tasks related to the PR by including their IDs in the PR description. Review Process: Require at least one approval before merging. Encourage reviewers to leave meaningful comments.
-
Repository Format Consistent Structure: Ensure that repository follows the defined project structure. README.md: Keep the README updated with essential instructions on setting up and contributing to the project.
-
Unit Testing Framework: Use Jasmine and Karma for unit testing. Structure: Keep test files adjacent to the source files (e.g., user-profile.component.spec.ts). Test Coverage: Aim for at least 80% code coverage. Testing Best Practices: Write clear and descriptive test cases. Use beforeEach() to set up common test data. Mock services where applicable.
-
Visual Testing with Storybook and Chromatic Integrate Storybook: Use Storybook to develop and visualize UI components in isolation. Documentation: Document components within Storybook. Utilize Chromatic: Use Chromatic for visual regression testing, ensuring that changes do not unintentionally alter the appearance of components.
-
Code Reviews Conduct Regular Reviews: Establish a routine for daily or weekly code reviews. Review Checklist: Adherence to coding standards. Appropriateness of test coverage. Clarity and readability of code. Feedback Culture: Foster a culture of constructive feedback, focusing on improving code quality rather than criticizing individuals.
-
Security Best Practices Environment Variables: Store sensitive information such as API keys in environment variables, not in the source code. Input Validation: Always validate input data on both client and server sides to prevent XSS and SQL injection attacks. Dependency Management: Regularly update dependencies and monitor vulnerabilities using tools like npm audit.
-
Version Control Practices Commits: Write meaningful commit messages that explain what changes were made and why. Atomic Commits: Make small, committed changes that focus on one specific issue or feature to facilitate easier code reviews and traceability.
-
Documentation Inline Comments: Use inline comments where necessary to explain complex logic. Generated Documentation: Use tools like TypeDoc to generate project documentation from your TypeScript code. Architecture Decision Records (ADRs): Maintain records of architectural decisions to provide a historical context for technical choices. Final Note By following these standards and best practices, we will create a collaborative and efficient workflow, ensuring high-quality output and a strong development culture within our team.
This template ships with the main Angular and Storybook configuration files you'll need to get up and running fast.
-
Create the application.
Use degit to get this template.
# Clone the template npx degit chromaui/intro-storybook-angular-template taskbox
-
Install the dependencies.
Navigate into your new site’s directory and install the necessary dependencies.
# Navigate to the directory cd taskbox/ # Install the dependencies npm install
-
Open the source code and start editing!
Open the
taskbox
directory in your code editor of choice and building your first component! -
Browse your stories!
Run
npm run storybook
to see your component's stories athttp://localhost:6006
.
A quick look at the top-level files and directories included with this template.
.
├── .storybook
├── node_modules
├── src
├── .editorconfig
├── .gitignore
├── angular.json
├── LICENSE
├── package-lock.json
├── package.json
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.spec.json
├── tslint.json
└── README.md
-
.storybook
: This directory contains Storybook's configuration files. -
node_modules
: This directory contains all of the modules of code that your project depends on (npm packages). -
src
: This directory will contain all of the code related to what you will see on your application. -
.editorconfig
: This file contains the configurations for EditorConfig. -
.gitignore
: This file tells git which files it should not track or maintain during the development process of your project. -
angular.json
: This file contains all the configurations required for your Angular project. -
LICENSE
: The template is licensed under the MIT licence. -
package-lock.json
: This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. (Do not change it manually). -
package.json
: Standard manifest file for Node.js projects, which typically includes project specific metadata (such as the project's name, the author among other information). It's based on this file that npm will know which packages are necessary to the project. -
tsconfig.app.json
: This file contains auxiliary configurations for your Angular project. -
tsconfig.json
: This file contains configurations the required configurations for TypeScript. -
tsconfig.spec.json
: This is a TypeScript configuration file aimed for application testing.
If you encounter an issue with the template, we encourage you to open an issue in this template's repository.
- Read our introductory tutorial at Learn Storybook.
- Learn how to transform your component libraries into design systems in our Design Systems for Developers tutorial.
- See our official documentation at Storybook.