File & Folder Structure - Entry Points, Config Files
Importance of File & Folder Structure
Understanding file and folder structure is necessary to:
- Know where to write new code
- Know where configuration changes happen
- Understand code execution flow
This is required for every technology (Angular, React, Vue, etc.)
Without understanding architecture and structure, expertise is not possible
Types of Files in an Angular Project
Sensitive files
- Small changes can cause large impact
Less important files
- Rarely used
- Presence or absence usually does not affect the project
Entry Points in Angular
Angular has two entry points
- HTML entry point:
index.html - TypeScript entry point:
main.ts
package.json
- Most important file in the project
- Contains project metadata
- Project will not run if this file is deleted or renamed
- Includes:
- Project name
- Project version
- Scripts to run, build, and test the project
- Installed libraries
- Version field is used for release management
Dependencies
- dependencies
- Required for the application to run
- devDependencies
- Required only during development
- Example: TypeScript
- TypeScript is converted to JavaScript during build
- Browsers can read only JavaScript, not TypeScript
TypeScript Configuration Files
tsconfig.json
- Main TypeScript configuration file
- Applies to the entire project
- Defines:
- ECMAScript target version
- Strictness rules
- Error and warning settings
tsconfig.app.json
- TypeScript configuration for the
appfolder - Controls:
- Included files
- Excluded files
- Output location
tsconfig.spec.json
- Used for test cases
specrefers to testing- Contains TypeScript configuration for unit tests
Test Files
- Files containing
.specare related to unit testing - Used for developer-level testing
README.md
- Project documentation file
- Contains:
- Commands to run the project
- Commands to generate components
- Build instructions
- Can be updated with project documentation
package-lock.json
- Automatically generated file
- Should not be edited manually
- Stores exact dependency versions
- Ensures same versions for all developers
- Prevents version mismatch in team projects
angular.json
- Main Angular configuration file
- Contains:
- Project root
- Source root
- Entry files
- Assets location
- Styles configuration
- Build settings
- Beginners usually do not change this file
node_modules
- Contains all installed libraries
- Created based on:
- dependencies
- devDependencies
- Includes nested dependencies of installed packages
- Not pushed to Git
- Can be recreated using
npm install
public Folder
- Used for public assets such as:
- Favicon
- Images
- Extra CSS or JavaScript files
- Contains non-sensitive files
src Folder
- Contains all project source code
- All developer-written code exists inside this folder
app Folder
- Contains application components
- Example:
- App component
- Login component
- Profile component
- Components are created using Angular commands
index.html
- Main HTML file
- First file loaded in the browser
- Acts as the HTML entry point
main.ts
- Main TypeScript entry file
- Bootstraps the Angular application
- Loads the root component
styles.css
- Global CSS file
- Styles apply to all components in the project
App-Level Files
app.config.ts
- Application-level configuration file
- Contains Angular-specific configurations
app.component.ts
- Root component file
- Connects HTML and CSS with logic
app.routes.ts
- Defines application routes
- Used to register URLs such as:
- Home
- Login
- Profile
app.component.spec.ts
- Unit test file for App component
Git and Editor Files
.gitignore
- Specifies files and folders to ignore in Git
- Example:
node_modules
.vscode
- Editor-specific settings
- Does not affect project execution
.editorconfig
- Controls code formatting
- Does not affect application behavior
.angular
- Stores cache and build-related data
- Used for performance optimization