Skip to content

Ashendrakumar/admin_portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Secure Admin Portal

Enterprise-grade Angular 17+ Admin Dashboard β€” Production-ready authentication, CRUD operations, and modern UI/UX patterns.

Version Angular TypeScript License


πŸ“‹ Overview

Secure Admin Portal is a professional, production-ready Angular application demonstrating enterprise architecture patterns, security best practices, and modern UX/UI design principles.

Key Features

βœ… Enterprise Authentication β€” JWT-based login with secure token management
βœ… Protected Routes β€” AuthGuard prevents unauthorized access
βœ… Token Interceptor β€” Automatically attaches JWT to all API requests
βœ… CRUD Operations β€” Create, read, update, delete user records
βœ… Server-side Pagination β€” Efficient data handling for large datasets
βœ… Search & Filter β€” RxJS debounce, role/status filters
βœ… State Management β€” BehaviorSubject + Angular Signals
βœ… Reusable Components β€” Table, modal, toast, loader, search bar
βœ… Modern Design System β€” Custom CSS variables, responsive layout
βœ… OnPush Change Detection β€” Performance-optimized rendering


πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm 9+
  • Angular CLI 17+

Installation

  1. Clone or extract the project

    cd secure-admin-portal
  2. Install dependencies

    npm install
  3. Start the development server

    npm start
    # or
    ng serve
  4. Open in browser

    http://localhost:4200
    

Demo Credentials

Use these credentials to test the application:

Email:    eve.holt@reqres.in
Password: cityslicka

Note: The app uses reqres.in as a mock REST API for demonstration.


πŸ“ Project Structure

secure-admin-portal/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ core/                    # Singleton services, guards, interceptors
β”‚   β”‚   β”‚   β”œβ”€β”€ guards/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.guard.ts           # Route protection
β”‚   β”‚   β”‚   β”‚   └── no-auth.guard.ts        # Prevent authenticated users from login
β”‚   β”‚   β”‚   β”œβ”€β”€ interceptors/
β”‚   β”‚   β”‚   β”‚   └── auth.interceptor.ts     # JWT token attachment
β”‚   β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.service.ts         # Authentication API calls
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth-state.service.ts   # Global auth state
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ toast.service.ts        # Notifications
β”‚   β”‚   β”‚   β”‚   └── loader.service.ts       # Loading indicators
β”‚   β”‚   β”‚   └── models/
β”‚   β”‚   β”‚       └── index.ts                # Shared interfaces & types
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ shared/                 # Reusable components, pipes, directives
β”‚   β”‚   β”‚   └── components/
β”‚   β”‚   β”‚       β”œβ”€β”€ table/          # Dynamic data table
β”‚   β”‚   β”‚       β”œβ”€β”€ toast/          # Toast notifications
β”‚   β”‚   β”‚       β”œβ”€β”€ loader/         # Global & inline spinners
β”‚   β”‚   β”‚       β”œβ”€β”€ search-bar/     # Debounced search input
β”‚   β”‚   β”‚       β”œβ”€β”€ form-modal/     # Reusable form modal
β”‚   β”‚   β”‚       └── confirm-dialog/ # Delete confirmation
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ features/               # Feature modules (lazy-loaded)
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/               # Authentication module
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   └── login-page/      # Login page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”‚   └── auth.routes.ts
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   └── dashboard/          # Dashboard module
β”‚   β”‚   β”‚       β”œβ”€β”€ components/
β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ dashboard-home/      # Shell layout with sidebar
β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ dashboard-overview/  # Stats & welcome
β”‚   β”‚   β”‚       β”‚   └── user-list/           # CRUD interface
β”‚   β”‚   β”‚       β”œβ”€β”€ services/
β”‚   β”‚   β”‚       β”‚   └── dashboard.service.ts # API calls
β”‚   β”‚   β”‚       └── dashboard.routes.ts
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ app.component.ts        # Root component
β”‚   β”‚   β”œβ”€β”€ app.config.ts           # App configuration
β”‚   β”‚   └── app.routes.ts           # Main routing config
β”‚   β”‚
β”‚   β”œβ”€β”€ environments/
β”‚   β”‚   β”œβ”€β”€ environment.ts          # Development
β”‚   β”‚   └── environment.prod.ts     # Production
β”‚   β”‚
β”‚   β”œβ”€β”€ styles.scss                 # Global styles & design system
β”‚   β”œβ”€β”€ index.html                  # HTML template
β”‚   β”œβ”€β”€ main.ts                     # Bootstrap
β”‚   └── favicon.ico
β”‚
β”œβ”€β”€ angular.json                    # Angular CLI config
β”œβ”€β”€ tsconfig.json                   # TypeScript config
β”œβ”€β”€ package.json                    # Dependencies
β”œβ”€β”€ README.md                       # This file
└── .gitignore

πŸ” Authentication Flow

Login Process

1. User enters email & password
   ↓
2. LoginComponent sends POST /api/login
   ↓
3. Backend returns JWT token
   ↓
4. AuthService fetches user profile (GET /api/users/2)
   ↓
5. AuthStateService stores token + user data in localStorage
   ↓
6. User redirected to dashboard

Protected Routes

All dashboard routes are protected by AuthGuard:

// If not authenticated β†’ redirected to /auth/login
// returnUrl query param preserves intended destination

Token Persistence

  • Stored in: localStorage (key: sap_auth_token)
  • Synced on: App initialization (AuthStateService)
  • Cleared on: Logout or 401 response

πŸ”— HTTP Interceptor

The authInterceptor automatically:

βœ“ Attaches JWT token to every request
βœ“ Handles 401 (session expired)
βœ“ Handles 403 (forbidden)
βœ“ Handles network errors
βœ“ Shows appropriate toast messages

Example

// No manual header setup needed:
this.http.get('/api/users').subscribe(...);
// Becomes: GET /api/users Authorization: Bearer <token>

πŸ“Š CRUD Operations (User Management)

Create User

dashboardService.createUser({
  first_name: 'John',
  last_name: 'Doe',
  email: 'john@company.com',
  job: 'Software Engineer',
  role: 'editor',
  department: 'Engineering'
})

Read Users (Paginated)

dashboardService.getUsers({
  page: 1,
  per_page: 6,
  search: 'john'
})

Update User

dashboardService.updateUser(userId, {
  first_name: 'Jane',
  job: 'Senior Engineer'
})

Delete User

dashboardService.deleteUser(userId)

🎯 State Management

BehaviorSubject Pattern (RxJS)

// AuthStateService uses BehaviorSubject for backward compatibility
authState.currentUser$.subscribe(user => {
  console.log('Current user:', user);
});

authState.isAuthenticated$.subscribe(isAuth => {
  console.log('Is authenticated:', isAuth);
});

Angular Signals (Modern API)

// Signals for reactive updates without subscriptions
const user = authState.user(); // null | AuthUser
const isAuth = authState.isAuthenticated(); // boolean

🎨 UI Components

Toast Notifications

toastService.success('Success', 'Operation completed');
toastService.error('Error', 'Something went wrong');
toastService.warning('Warning', 'Please review');
toastService.info('Info', 'Additional information');

Global Loader

loaderService.show('Processing...');
// ... async operation
loaderService.hide();

// Force hide (in case of multiple requests)
loaderService.forceHide();

Reusable Table

<app-common-table
  [columns]="tableColumns"
  [data]="userData"
  [isLoading]="isLoading()"
  [pagination]="paginationConfig"
  [sort]="sortConfig"
  (sortChange)="onSort($event)"
  (pageChange)="onPageChange($event)"
>
  <!-- Custom cell templates optional -->
</app-common-table>

Search Bar with Debounce

<app-search-input
  placeholder="Search users..."
  [debounce]="350"
  (search)="onSearch($event)"
/>

// Emits after 350ms of inactivity

⚑ Performance Optimizations

Change Detection Strategy

All components use ChangeDetectionStrategy.OnPush:

@Component({
  selector: 'app-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
})

This disables automatic change detection and requires manual triggers, significantly improving rendering performance.

TrackBy in ngFor

<app-table
  [data]="users"
  trackByKey="id"  // Uses ID for DOM reconciliation
/>

Lazy Loading

Feature modules are lazy-loaded:

// app.routes.ts
{
  path: 'auth',
  loadChildren: () => import('./features/auth/auth.routes')
}

RxJS Debounce

Search input is debounced to reduce API calls:

// SearchBarComponent
searchControl.valueChanges
  .pipe(
    debounceTime(350),
    distinctUntilChanged()
  )
  .subscribe(value => this.search.emit(value));

πŸ›‘οΈ Security Features

Feature Implementation
JWT Authentication Bearer token in Authorization header
Secure Token Storage localStorage with key namespacing
Route Guards AuthGuard prevents unauthorized access
Session Management 401 triggers automatic logout
XSRF Protection Built-in Angular XSRF configuration
Input Validation Reactive Forms with Validators
Error Handling Centralized error responses

🎬 Build & Deployment

Development Build

npm start
# Starts dev server on http://localhost:4200

Production Build

npm run build:prod
# Creates optimized build in dist/secure-admin-portal/

Build Output

dist/secure-admin-portal/
β”œβ”€β”€ index.html
β”œβ”€β”€ styles.css (bundled & minified)
β”œβ”€β”€ main.js (bundled & optimized)
β”œβ”€β”€ polyfills.js
└── ...

Deployment

Deploy the dist/ folder to:

  • Static Hosting: Firebase, Vercel, Netlify, GitHub Pages
  • Server: Express, Node.js, AWS S3, Azure Static Web Apps
  • Docker: Build Docker image with Angular dist as static assets

πŸ”§ Environment Configuration

Development (environment.ts)

export const environment = {
  production: false,
  apiUrl: 'https://reqres.in/api',
  tokenKey: 'sap_auth_token',
};

Production (environment.prod.ts)

export const environment = {
  production: true,
  apiUrl: 'https://api.production-server.com/api',
  tokenKey: 'sap_auth_token',
};

Using Environment

import { environment } from '@environments/environment';

constructor(private http: HttpClient) {
  const apiUrl = environment.apiUrl;
  const isProduction = environment.production;
}

πŸ“± Responsive Design

The application is fully responsive:

  • Desktop (1024px+) β€” Full sidebar, multi-column layouts
  • Tablet (768px-1023px) β€” Collapsible sidebar, adjusted grids
  • Mobile (< 768px) β€” Drawer sidebar, single-column layouts

CSS utilities: .hide-mobile, .hide-desktop, .hide-tablet


πŸ§ͺ Testing (Optional)

Unit Tests

npm test

E2E Tests

npm run e2e

Testing setup can be added using Jasmine/Karma or Cypress


πŸ“¦ Dependencies

Package Purpose
@angular/common Common directives, pipes
@angular/forms Reactive Forms
@angular/router Routing & navigation
@angular/platform-browser DOM API
rxjs Reactive programming
typescript Language support

πŸŽ“ Learning Resources


🀝 Contributing

This is a portfolio/demo project. Contributions are welcome!

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

πŸ“„ License

This project is licensed under the MIT License β€” see LICENSE file for details.


πŸ™‹ Support

For issues, questions, or suggestions:

  1. GitHub Issues β€” Report bugs or feature requests
  2. Discussions β€” Ask questions and share ideas
  3. Email β€” Contact via project documentation

🎯 Future Enhancements

  • Role-based access control (RBAC)
  • Advanced analytics dashboard
  • Real-time notifications via WebSocket
  • Audit logging & activity tracking
  • Bulk operations (import/export users)
  • Two-factor authentication (2FA)
  • Dark/light theme toggle
  • Internationalization (i18n)
  • End-to-end testing suite
  • Storybook component library

πŸ“ž Contact & Credits

Built with Angular 17+, TypeScript, and modern web standards.

An enterprise-ready template for admin dashboards, CRM systems, and management applications.


Last Updated: May 2026
Version: 1.0.0
Status: Production-Ready βœ…

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors