Topic 2 – 4 folders to understand angular project structure

image 2

Play Store Application link – Java to Angular in 19 Steps – App on Google Play

Note – According to nodeJs version installed in system, project structure might differ.
Github project link – https://github.com/kuldeep101990/angular-step2

In software development, project structure plays a crucial role in organizing code efficiently. If you’re a Java developer, think of Angular’s folder hierarchy as similar to the organization of a Java project, such as src/main/java, resources, and pom.xml. Let’s explore the default Angular project structure and draw parallels to what you already know.


Angular Project Structure Overview

When you create a new Angular project, the default folder structure looks like this:

project-name/  
β”œβ”€β”€ e2e/  
β”‚   β”œβ”€β”€ src/  
β”‚   └── protractor.conf.js  
β”œβ”€β”€ node_modules/  
β”œβ”€β”€ src/  
β”‚   β”œβ”€β”€ app/  
β”‚   β”œβ”€β”€ assets/  
β”‚   β”œβ”€β”€ environments/  
β”‚   β”œβ”€β”€ index.html  
β”‚   β”œβ”€β”€ main.ts  
β”‚   β”œβ”€β”€ polyfills.ts  
β”‚   β”œβ”€β”€ styles.scss  
β”‚   └── test.ts  
β”œβ”€β”€ .angular.json  
β”œβ”€β”€ package.json  
β”œβ”€β”€ tsconfig.app.json  
β”œβ”€β”€ tsconfig.json  
β”œβ”€β”€ tsconfig.spec.json  
└── tslint.json  

Here’s what these files and folders represent, along with Java-based comparisons:


1. e2e Folder (End-to-End Testing)

This folder is used for writing and running end-to-end tests with Protractor, Angular’s testing framework for simulating user interactions.

Java Comparison: Similar to using Selenium in Java for automating web application testing.


2. node_modules Folder (Dependencies)

This is where all project dependencies are installed.

Java Comparison: Equivalent to Maven Dependencies or Gradle Dependencies, where external JARs are stored.


3. src Folder (Source Code)

This folder contains your Angular application’s source code, similar to src/main/java in Java.

  • app Folder: Houses Angular components, like Java classes or Spring Beans.
  • assets Folder: Contains static files, equivalent to resources in Java.
  • environments Folder: For environment-specific configurations, akin to Spring profiles (application-dev.properties, etc.).
  • index.html: Acts as the entry point, similar to index.jsp or index.html.
  • main.ts: The app’s bootstrap file, like the main() method or @SpringBootApplication.

4. Configuration Files

  • .angular.json: Angular CLI settings, like pom.xml or build.gradle.
  • package.json: Manages project metadata and dependencies, similar to pom.xml.
  • tsconfig.json: TypeScript configuration, analogous to javac compiler options.

Major Version Differences

As Angular has evolved, its structure and capabilities have changed significantly. Here are some highlights of major differences across versions, which are important for Java developers transitioning to Angular:

  1. Angular 5:
    • Followed a rigid module-based architecture.
    • Every feature needed to be explicitly declared in a module (NgModule).
    • Java Comparison: Similar to earlier versions of Spring, where everything revolved around XML-based configurations.
  2. Angular 12+:
    • Introduced support for optional chaining (?.) in templates, improving readability.
    • Java Comparison: Comparable to the introduction of Optional in Java 8, simplifying null handling.
  3. Angular 15:
    • Made it possible to use a module-free structure with standalone components.
    • This means you can directly bootstrap components without declaring them in a module.
    • Java Comparison: Think of it like moving from tightly coupled Spring XML configurations to annotations like @ComponentScan and @Configuration, which allow for more flexibility.

Summary

Angular’s project structure aligns well with Java developers’ expectations:

  • node_modules is like Maven/Gradle dependencies.
  • app/ folder is like the src/main/java folder, housing core logic.
  • Environment files are akin to Spring profiles.
  • Configuration files like .angular.json and package.json serve roles similar to pom.xml or build.gradle.

With each major version, Angular has improved developer productivity, just like how Java evolved with features like annotations, lambdas, and the Streams API. Understanding these concepts will make your transition to Angular smoother and help you build robust web applications.

Leave a Reply

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