DEV Community

Tom Fong
Tom Fong

Posted on

4 2

Ionic Angular: Project Structure Suggestion

I would like to share how I manage Ionic Angular project generally.

By using ionic generate command, we can get what Angular features are available in an Ionic Angular project:

> page 
  component 
  service 
  module 
  class 
  directive 
  guard 
  class 
  directive 
  guard 
  pipe 
  interface 
  enum 
Enter fullscreen mode Exit fullscreen mode

I usually divide and group them according to their type (component, service, guard etc.) rather than use case. It can make the project structure cleaner and simplify the syntax of importing exported declarations or modules.

Here is an example of the structure I usually apply

src
├── app
    ├── components
        └── search
            ├── search.component.html
            ├── search.component.scss
            └── search.component.ts
    ├── directives
        ├── disable-click.directive.ts
        └── highlight.directive.ts
    ├── enums
        ├── colors.ts
        └── genders.ts
    ├── guards
        └── auth.guard.ts
    ├── modals
        └── student-info
            ├── student-info.module.ts
            ├── student-info.page.html
            ├── student-info.page.scss
            └── student-info.page.ts
    ├── models
        └── student.ts
    ├── pages
        └── home
            ├── home-routing.module.ts
            ├── home.module.ts
            ├── home.page.html
            ├── home.page.scss
            └── home.page.ts
        └── login
            ├── login-routing.module.ts
            ├── login.module.ts
            ├── login.page.html
            ├── login.page.scss
            └── login.page.ts
    ├── pipes
        └── date.pipe.ts
    ├── services
        ├── auth.service.ts
        └── env.service.ts
    ├── utils
        ├── animations.ts
        └── validators.ts
├── assets
├── environments
├── theme
├── global.scss
├── index.html
├── main.ts
├── polyfills.ts
├── test.ts
└── zone-flags.ts
Enter fullscreen mode Exit fullscreen mode

Key Points

components: This folder consists of all non-page components that is without module.

directives: This folder consists of all Angular directives.

enums: This folder consists of all enums.

guards: This folder consists of all Angular guards.

modals: This folder consists of all page components that is not used for routing but for Ionic modal.

models: This folder consists of all classes that is used to represent MVC's model or so-called DTO (Data Transfer Object).

pages: This folder consists of all page components that should be used for routing.

pipes: This folder consists of all Angular pipes.

services: This folder consists of all Angular injectable services.

utils: This folder consists of all helper classes or functions.

Example

I did not create an example project to demonstrate this structure, but you can take my Ionic app - Simple QR as a real-world reference.

Hope this can help you. Happy coding!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay