|
| 1 | +# Enterprise Angular 21 SSR Reference Architecture |
| 2 | + |
| 3 | +> **A production-ready, highly optimized Angular architecture designed for scale, performance, and maintainability.** |
| 4 | +
|
| 5 | +This repository serves as a masterclass in modern Angular development. Engineered from the ground up by a Senior Angular Architect, it demonstrates how to architect a state-of-the-art (SOTA) frontend application using the absolute latest features of Angular 21. It is explicitly designed to serve as a technical reference for enterprise teams and prospective clients. |
| 6 | + |
| 7 | +## 🚀 Why This Architecture is "Senior-Level" |
| 8 | + |
| 9 | +Unlike typical frontend portfolios, this project treats the UI as a comprehensive, production-critical system: |
| 10 | + |
| 11 | +- **Enterprise Feature-Driven Design:** The codebase strictly adheres to the `Core` / `Shared` / `Feature` / `Layout` module pattern. This eliminates circular dependencies, enforces a clean separation of concerns, and ensures the codebase remains maintainable as it scales. |
| 12 | +- **Aggressive Performance Optimization:** Utilizes intelligent asset preloading, HTTP `Link` headers, intersection observers for lazy loading, and advanced `@defer` blocks. The result is a near-instant First Contentful Paint (FCP) and exceptional Core Web Vitals. |
| 13 | +- **Node.js Express SSR & SSG Mastery:** Bypasses basic routing with a custom Express `server.ts` that handles dynamic `Accept-Language` locale detection, aggressive static asset caching (`Cache-Control`), security headers, and prerendering (SSG) for unparalleled SEO performance. |
| 14 | +- **Production-Grade DevOps & Automation:** Features an automated GitHub Actions CI/CD pipeline, strict TypeScript compilation enforcement, and Husky git hooks. |
| 15 | +- **Modern UI/UX Standards:** Built with PrimeNG 21 (Aura theme) and PrimeFlex, demonstrating deep expertise in integrating complex, enterprise-grade UI libraries cleanly into a modern Angular context. |
| 16 | +- **PWA & Offline Resilience:** Fully configured Service Worker with custom background update broadcasting (`sw-update-broadcast.service.ts`) for seamless, zero-downtime client updates. |
| 17 | +- **Decoupled Data Architecture:** Implements a strict Service Layer pattern for all HTTP interactions. Components are kept "lean" and unaware of API implementation details, while `InquiryService` handles data mutation, error catching, and state persistence via RxJS Observables. |
| 18 | + |
| 19 | + |
| 20 | +### System Architecture Flow |
| 21 | + |
| 22 | +```mermaid |
| 23 | +graph TD |
| 24 | + Client[Client Browser] -->|HTTP Request| Express[Node.js Express Server] |
| 25 | + Express -->|Static Asset?| Static[Serve /browser files] |
| 26 | + Express -->|Dynamic Route?| Locale[Detect Locale via Headers/URL] |
| 27 | + Locale --> AngularEngine[Angular Node App Engine] |
| 28 | + AngularEngine -->|Prerendered?| SSG[Serve SSG HTML] |
| 29 | + AngularEngine -->|Dynamic?| SSR[Render Angular Component] |
| 30 | + SSR --> Express |
| 31 | + SSG --> Express |
| 32 | + Express -->|Response| Client |
| 33 | +``` |
| 34 | + |
| 35 | +### Data Interaction Flow (Reactive Pattern) |
| 36 | + |
| 37 | +```mermaid |
| 38 | +graph LR |
| 39 | + View[Component Template] -->|User Action| Comp[Angular Component] |
| 40 | + Comp -->|Form Data| Service[InquiryService / Core] |
| 41 | + Service -->|HTTP POST| API[Backend API / Cloudflare] |
| 42 | + API -->|Response| Service |
| 43 | + Service -->|Observable| Comp |
| 44 | + Comp -->|Update UI| View |
| 45 | +``` |
| 46 | + |
| 47 | +### Component Structure |
| 48 | + |
| 49 | +```mermaid |
| 50 | +graph TD |
| 51 | + App[AppRoot Component] --> Layout |
| 52 | + App --> RouterOutlet |
| 53 | + |
| 54 | + Layout --> Header[Header Component] |
| 55 | + Layout --> Footer[Footer Component] |
| 56 | + |
| 57 | + RouterOutlet --> Features |
| 58 | + |
| 59 | + Features --> Home[Home Module] |
| 60 | + Features --> About[About Module] |
| 61 | + Features --> Legal[Legal Module] |
| 62 | + Features --> Prep[Prep Module] |
| 63 | + |
| 64 | + Home --> SharedComponents |
| 65 | + About --> SharedComponents |
| 66 | + Legal --> SharedComponents |
| 67 | + |
| 68 | + subgraph Shared |
| 69 | + SharedComponents[Buttons, Breadcrumbs, Schedulers] |
| 70 | + end |
| 71 | + |
| 72 | + subgraph Core |
| 73 | + Services[SEO, SW Updates, Inquiry Handling, Layout Adjusters] |
| 74 | + end |
| 75 | + |
| 76 | + Features -.->|Injects| Core |
| 77 | +``` |
| 78 | + |
| 79 | +## Project Structure |
| 80 | + |
| 81 | +``` |
| 82 | +src/ |
| 83 | +├── app/ |
| 84 | +│ ├── core/ # Singleton services (SEO, Updates, Inquiry, Adjustments) |
| 85 | +│ ├── features/ # Feature modules (Home, About, Legal, etc.) |
| 86 | +│ ├── layout/ # Global structural components (Header, Footer) |
| 87 | +│ └── shared/ # Reusable UI components and utilities |
| 88 | +├── assets/ # Static assets, fonts, icons |
| 89 | +├── environments/ # Environment-specific configuration |
| 90 | +└── locale/ # i18n translation files |
| 91 | +``` |
| 92 | + |
| 93 | +## Getting Started |
| 94 | + |
| 95 | +### Prerequisites |
| 96 | + |
| 97 | +- Node.js (v24 or higher recommended) |
| 98 | +- Angular CLI |
| 99 | + |
| 100 | +### Installation |
| 101 | + |
| 102 | +1. Clone the repository: |
| 103 | + ```bash |
| 104 | + git clone <your-repo-url> |
| 105 | + cd personal-website-opensource |
| 106 | + ``` |
| 107 | + |
| 108 | +2. Install dependencies: |
| 109 | + ```bash |
| 110 | + npm install |
| 111 | + ``` |
| 112 | + |
| 113 | +3. Configure Environment Variables: |
| 114 | + Update `src/environments/environment.ts` with your specific API and Worker URLs if you are connecting to a backend. |
| 115 | + |
| 116 | +### Development Server |
| 117 | + |
| 118 | +Run `npm run start` (or `ng serve`) for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. |
| 119 | + |
| 120 | +### Build |
| 121 | + |
| 122 | +Run `npm run build:prod` to build the project for production. The build artifacts will be stored in the `dist/` directory. This utilizes Angular's static output mode for prerendering. |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +This project is open-sourced under the MIT License. |
0 commit comments