Skip to content

Ionic 8 + Angular 17 Boilerplate πŸš€ – A production-ready starter kit for building cross-platform apps (Android, iOS, Web/PWA) with JWT authentication, secure storage, API layer, and modular theme customization.

Notifications You must be signed in to change notification settings

krguptaa/ionic-angular-boilerplate

Repository files navigation

Ionic 8 + Angular Boilerplate

A comprehensive, production-ready Ionic 8 + Angular boilerplate with authentication, theming, platform-specific features, and modern development practices.

Ionic Angular TypeScript Capacitor

✨ Features

πŸ” Authentication & Security

  • JWT-based authentication with refresh tokens
  • Secure storage for sensitive data
  • Route guards with role-based access control
  • Automatic token refresh and session management
  • Password reset and account recovery

🎨 Theming & UI

  • Comprehensive theme system with light/dark/auto modes
  • Responsive design with breakpoints
  • Reusable UI components (buttons, inputs, modals, alerts, toasts)
  • Customizable color schemes and typography
  • Platform-specific styling

πŸ“± Platform Support

  • Web/PWA: Full PWA support with service worker and offline capabilities
  • Android: Native Android app with full device integration
  • iOS: Native iOS app with platform-specific features
  • Cross-platform camera, location, and push notification support

πŸ”§ Core Services

  • API Service: Generic HTTP client with interceptors and error handling
  • State Management: Angular Signals-based reactive state management
  • Platform Service: Device detection and platform-specific features
  • Network Monitoring: Real-time connectivity status and offline support

πŸ“¦ Additional Features

  • Form validation utilities
  • Date/time formatting helpers
  • File upload and management
  • Push notifications with background handling
  • Biometric authentication support
  • Haptic feedback and device vibration
  • Clipboard and sharing capabilities

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Ionic CLI: npm install -g @ionic/cli
  • Angular CLI: npm install -g @angular/cli

Installation

  1. Clone the repository:

    git clone https://github.com/krguptaa/ionic-angular-boilerplate.git
    cd ionic-angular-boilerplate
  2. Install dependencies:

    npm install
  3. Set up environment variables:

    cp src/environments/environment.ts src/environments/environment.prod.ts
    # Edit environment files with your API endpoints
  4. Run the development server:

    npm start

πŸ“‹ Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ auth/                    # Authentication module
β”‚   β”‚   β”œβ”€β”€ login/              # Login page
β”‚   β”‚   β”œβ”€β”€ register/           # Registration page
β”‚   β”‚   └── auth-routing.module.ts
β”‚   β”œβ”€β”€ guards/                 # Route guards
β”‚   β”‚   └── auth.guard.ts       # Authentication guard
β”‚   β”œβ”€β”€ home/                   # Home page
β”‚   β”œβ”€β”€ interceptors/           # HTTP interceptors
β”‚   β”‚   └── auth.interceptor.ts # JWT token interceptor
β”‚   β”œβ”€β”€ models/                 # TypeScript interfaces
β”‚   β”œβ”€β”€ services/               # Application services
β”‚   β”‚   β”œβ”€β”€ api.service.ts      # Generic API service
β”‚   β”‚   β”œβ”€β”€ auth.service.ts     # Authentication service
β”‚   β”‚   β”œβ”€β”€ camera.service.ts   # Camera functionality
β”‚   β”‚   β”œβ”€β”€ location.service.ts # Geolocation service
β”‚   β”‚   β”œβ”€β”€ platform.service.ts # Platform utilities
β”‚   β”‚   β”œβ”€β”€ push-notifications.service.ts # Push notifications
β”‚   β”‚   └── state/              # State management
β”‚   β”‚       β”œβ”€β”€ base-state.service.ts
β”‚   β”‚       β”œβ”€β”€ user-state.service.ts
β”‚   β”‚       β”œβ”€β”€ app-state.service.ts
β”‚   β”‚       └── network-state.service.ts
β”‚   β”œβ”€β”€ shared/                 # Shared components and modules
β”‚   β”‚   β”œβ”€β”€ components/         # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ alert/          # Alert component
β”‚   β”‚   β”‚   β”œβ”€β”€ toast/          # Toast notifications
β”‚   β”‚   β”‚   β”œβ”€β”€ card/           # Card component
β”‚   β”‚   β”‚   β”œβ”€β”€ badge/          # Badge component
β”‚   β”‚   β”‚   β”œβ”€β”€ custom-button/  # Enhanced button
β”‚   β”‚   β”‚   β”œβ”€β”€ custom-input/   # Enhanced input
β”‚   β”‚   β”‚   β”œβ”€β”€ custom-modal/   # Enhanced modal
β”‚   β”‚   β”‚   └── loading-spinner/ # Loading spinner
β”‚   β”‚   └── shared.module.ts    # Shared module
β”‚   β”œβ”€β”€ utilities/              # Utility classes
β”‚   β”‚   β”œβ”€β”€ date.utils.ts       # Date formatting
β”‚   β”‚   β”œβ”€β”€ validation.utils.ts # Form validation
β”‚   β”‚   β”œβ”€β”€ platform.utils.ts   # Platform detection
β”‚   β”‚   └── index.ts            # Utility exports
β”‚   β”œβ”€β”€ constants/              # Application constants
β”‚   β”œβ”€β”€ theme/                  # Theme configuration
β”‚   β”‚   └── variables.scss      # SCSS variables
β”‚   └── environments/           # Environment configurations
β”œβ”€β”€ assets/                     # Static assets
β”œβ”€β”€ android/                    # Android platform files
β”œβ”€β”€ ios/                        # iOS platform files
└── resources/                  # Icon and splash screen sources

πŸ—οΈ Architecture

State Management

The application uses Angular Signals for reactive state management:

// User state example
export class UserStateService extends BaseStateService<UserState> {
  public readonly isLoggedIn = computed(() => this.state().isAuthenticated);
  public readonly currentUser = computed(() => this.state().currentUser);

  setUser(user: User, token: string) {
    this.updateState({
      currentUser: user,
      isAuthenticated: true,
      session: { token, refreshToken: null, expiresAt: null }
    });
  }
}

Service Layer

Clean separation of concerns with dedicated services:

// API Service with error handling
@Injectable({ providedIn: 'root' })
export class ApiService {
  get<T>(endpoint: string, options?: ApiOptions): Observable<T> {
    return this.request<T>('GET', endpoint, null, options);
  }

  post<T>(endpoint: string, data: any, options?: ApiOptions): Observable<T> {
    return this.request<T>('POST', endpoint, data, options);
  }
}

Component Architecture

Reusable, platform-aware components:

@Component({
  selector: 'app-custom-button',
  template: `
    <ion-button [class.loading]="loading" (click)="onClick($event)">
      <ion-spinner *ngIf="loading"></ion-spinner>
      <ng-content></ng-content>
    </ion-button>
  `
})
export class CustomButtonComponent {
  @Input() loading = false;
  @Output() buttonClick = new EventEmitter<Event>();
}

πŸ“± Platform-Specific Setup

Android Setup

  1. Add Android platform:

    npx cap add android
  2. Configure permissions in android/app/src/main/AndroidManifest.xml

  3. Build and run:

    npx cap run android

iOS Setup

  1. Add iOS platform:

    npx cap add ios
  2. Configure permissions in ios/App/App/Info.plist

  3. Build and run:

    npx cap run ios

PWA Setup

  1. Build for production:

    npm run build
  2. Serve with HTTPS for full PWA functionality

  3. Register service worker (automatically configured)

🎨 Theming

Theme Configuration

The application supports multiple theme modes:

// Light theme (default)
:root {
  --theme-bg-primary: #ffffff;
  --theme-text-primary: #000000;
  --theme-primary: #3880ff;
}

// Dark theme
[data-theme="dark"] {
  --theme-bg-primary: #1e1e1e;
  --theme-text-primary: #ffffff;
  --theme-primary: #4c8dff;
}

Theme Service

@Injectable({ providedIn: 'root' })
export class ThemeService {
  setTheme(theme: 'light' | 'dark' | 'auto') {
    // Implementation
  }

  toggleTheme() {
    // Implementation
  }
}

πŸ” Authentication Flow

Login Process

// Login component
async onLogin(credentials: LoginRequest) {
  try {
    const response = await this.authService.login(credentials).toPromise();
    this.userState.setUser(response.user, response.accessToken);
    this.router.navigate(['/home']);
  } catch (error) {
    this.toastService.showError('Login failed');
  }
}

Route Protection

// Route guard
canActivate(route: ActivatedRouteSnapshot): boolean {
  if (!this.authService.isLoggedIn()) {
    this.router.navigate(['/auth/login']);
    return false;
  }
  return true;
}

πŸ“‘ API Integration

Base API Configuration

// API Service
export const APP_CONSTANTS = {
  API_BASE_URL: 'https://api.example.com',
  TIMEOUTS: {
    HTTP_REQUEST: 30000,
    CACHE_EXPIRY: 3600000
  }
};

HTTP Interceptor

// Auth Interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  // Add JWT token to requests
  const token = await this.authService.getAccessToken();
  if (token) {
    request = request.clone({
      setHeaders: { Authorization: `Bearer ${token}` }
    });
  }
  return next.handle(request);
}

πŸ§ͺ Testing

Unit Tests

npm run test

E2E Tests

npm run e2e

Linting

npm run lint

πŸ“¦ Build & Deployment

Development

npm start          # Development server
npm run watch      # Watch mode

Production Build

npm run build      # Web build
npx cap build      # Native builds

Deployment

# Web deployment
npm run build --prod
# Deploy to hosting service

# Android deployment
npx cap build android
# Sign and upload to Play Store

# iOS deployment
npx cap build ios
# Archive and upload to App Store

πŸ”§ Configuration

Environment Variables

// src/environments/environment.ts
export const environment = {
  production: false,
  apiUrl: 'https://api-dev.example.com',
  enableDebug: true,
  firebaseConfig: { /* ... */ }
};

Capacitor Configuration

// capacitor.config.ts
const config: CapacitorConfig = {
  appId: 'com.yourcompany.boilerplate',
  appName: 'Ionic Boilerplate',
  webDir: 'www',
  plugins: {
    Camera: { allowEditing: true },
    Geolocation: { enableHighAccuracy: true },
    PushNotifications: { presentationOptions: ["badge", "sound", "alert"] }
  }
};

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Ionic Framework team
  • Angular team
  • Capacitor team
  • All contributors and the open-source community

πŸ“ž Support

For support, email webworldgk@gmail.com (Kamlesh Gupta).


Happy coding! πŸš€

Built with ❀️ using Ionic 8 + Angular

About

Ionic 8 + Angular 17 Boilerplate πŸš€ – A production-ready starter kit for building cross-platform apps (Android, iOS, Web/PWA) with JWT authentication, secure storage, API layer, and modular theme customization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published