VibeKoding / Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat / Principles of Frontend Project ArchitecturePrinciples of Frontend Project Architecture
VK

Principles of Frontend Project ArchitecturePrinciples of Frontend Project Architecture

๐Ÿ“š Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat ๐ŸŒ Dual Bahasa (ID / EN) โšก VibeKoding Native

Ensiklopedia VibeKoding: Principles of Frontend Project Architecture.Ensiklopedia VibeKoding: Principles of Frontend Project Architecture.

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

How do you choose the right architecture for projects of different sizes, from simple HTML pages to complex enterprise applications? It's like asking: from a studio apartment to a large shopping mall, how do you design different spatial layouts based on needs? Good architecture should evolve with the project, rather than being over-engineered from the start.How do you choose the right architecture for projects of different sizes, from simple HTML pages to complex enterprise applications? It's like asking: from a studio apartment to a large shopping mall, how do you design different spatial layouts based on needs? Good architecture should evolve with the project, rather than being over-engineered from the start.

------

1. Architecture Evolution: From Simple to Complex1. Architecture Evolution: From Simple to Complex

1.1 Three Complexity Levels Overview1.1 Three Complexity Levels Overview

Frontend project architecture should match project complexity. We classify projects into three levels based on technical complexity and user scale:Frontend project architecture should match project complexity. We classify projects into three levels based on technical complexity and user scale:

LevelTech StackUser ScaleTypical ScenariosCore Focus
BeginnerHTML/CSS/JSIndividual/small teamPersonal blogs, landing pages, simple toolsQuick launch, simple maintenance
IntermediateVue/React + build toolsSmall-to-medium businessManagement systems, e-commerce frontends, SaaSComponent reuse, state management
EnterpriseFramework + micro-frontend/SSRLarge applicationsLarge platforms, complex business systemsPerformance optimization, team collaboration, scalability
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

Don't over-engineer! Many projects start with simple HTML and gradually introduce frameworks and tools as needs grow. - Personal projects โ†’ Beginner level - Startup MVP โ†’ Beginner or intermediate level - Enterprise management systems โ†’ Intermediate level - Large internet platforms โ†’ Enterprise levelDon't over-engineer! Many projects start with simple HTML and gradually introduce frameworks and tools as needs grow. - Personal projects โ†’ Beginner level - Startup MVP โ†’ Beginner or intermediate level - Enterprise management systems โ†’ Intermediate level - Large internet platforms โ†’ Enterprise level

------

2. Beginner Level: HTML/CSS/JS Projects2. Beginner Level: HTML/CSS/JS Projects

2.1 Suitable Scenarios2.1 Suitable Scenarios

2.2 Recommended Directory Structure2.2 Recommended Directory Structure

CODE
my-simple-project/ โ”œโ”€โ”€ index.html # Homepage โ”œโ”€โ”€ about.html # About page (if needed) โ”œโ”€โ”€ css/ โ”‚ โ”œโ”€โ”€ reset.css # Reset styles โ”‚ โ”œโ”€โ”€ variables.css # CSS variables (colors, fonts, etc.) โ”‚ โ”œโ”€โ”€ components.css # Component styles (buttons, cards, etc.) โ”‚ โ””โ”€โ”€ main.css # Main stylesheet โ”œโ”€โ”€ js/ โ”‚ โ”œโ”€โ”€ utils.js # Utility functions โ”‚ โ”œโ”€โ”€ api.js # Simple API calls โ”‚ โ””โ”€โ”€ main.js # Main logic โ”œโ”€โ”€ assets/ โ”‚ โ”œโ”€โ”€ images/ # Image assets โ”‚ โ””โ”€โ”€ fonts/ # Font files โ””โ”€โ”€ README.md # Project documentation

2.3 Code Organization Principles2.3 Code Organization Principles

HTML: Semantic tags, clear structureHTML: Semantic tags, clear structure

html
<!-- index.html --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Personal Blog</title> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/variables.css"> <link rel="stylesheet" href="css/components.css"> <link rel="stylesheet" href="css/main.css"> </head> <body> <header class="site-header"> <nav class="main-nav"> <a href="index.html">Home</a> <a href="about.html">About</a> </nav> </header> <main class="content"> <article class="blog-post"> <h1>Article Title</h1> <p>Article content...</p> </article> </main> <footer class="site-footer"> <p>&copy; 2024 My Blog</p> </footer> <script src="js/utils.js"></script> <script src="js/main.js"></script> </body> </html>

CSS: Use CSS variables to manage themesCSS: Use CSS variables to manage themes

css
/* variables.css */ :root { --primary-color: #3498db; --text-color: #333; --bg-color: #fff; --spacing-sm: 8px; --spacing-md: 16px; --spacing-lg: 24px; --font-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } /* components.css - Reusable component styles */ .btn { padding: var(--spacing-sm) var(--spacing-md); border: none; border-radius: 4px; background: var(--primary-color); color: white; cursor: pointer; } .card { padding: var(--spacing-md); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

JavaScript: Modular organization (using ES6 modules or simple splitting)JavaScript: Modular organization (using ES6 modules or simple splitting)

javascript
// utils.js const utils = { // Simplified DOM operations $(selector) { return document.querySelector(selector); }, // Simple debounce debounce(fn, delay) { let timer; return function(...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; }, // Local storage wrapper storage: { get(key) { return JSON.parse(localStorage.getItem(key) || 'null'); }, set(key, value) { localStorage.setItem(key, JSON.stringify(value)); } } }; // main.js document.addEventListener('DOMContentLoaded', () => { // Page initialization logic initNavigation(); loadBlogPosts(); });

2.4 Best Practices2.4 Best Practices

โœ… Do:โœ… Do:

โŒ Avoid:โŒ Avoid:

------

3. Intermediate Level: Vue/React Framework Projects3. Intermediate Level: Vue/React Framework Projects

3.1 Suitable Scenarios3.1 Suitable Scenarios

3.2 Vue Project Recommended Structure3.2 Vue Project Recommended Structure

CODE
my-vue-project/ โ”œโ”€โ”€ public/ # Static assets โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ””โ”€โ”€ favicon.ico โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ assets/ # Styles, images, fonts โ”‚ โ”‚ โ”œโ”€โ”€ styles/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ variables.scss โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ mixins.scss โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ global.scss โ”‚ โ”‚ โ””โ”€โ”€ images/ โ”‚ โ”œโ”€โ”€ components/ # Shared components โ”‚ โ”‚ โ”œโ”€โ”€ common/ # Global shared (Button, Modal, etc.) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Button/ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ index.vue โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Button.scss โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Modal/ โ”‚ โ”‚ โ””โ”€โ”€ business/ # Business components (UserCard, etc.) โ”‚ โ”œโ”€โ”€ views/ # Page components โ”‚ โ”‚ โ”œโ”€โ”€ Home/ โ”‚ โ”‚ โ”œโ”€โ”€ User/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ List.vue โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Detail.vue โ”‚ โ”‚ โ””โ”€โ”€ Product/ โ”‚ โ”œโ”€โ”€ router/ # Route configuration โ”‚ โ”‚ โ””โ”€โ”€ index.js โ”‚ โ”œโ”€โ”€ stores/ # Pinia/Vuex state management โ”‚ โ”‚ โ”œโ”€โ”€ user.js โ”‚ โ”‚ โ””โ”€โ”€ app.js โ”‚ โ”œโ”€โ”€ services/ # API services โ”‚ โ”‚ โ”œโ”€โ”€ request.js # axios wrapper โ”‚ โ”‚ โ”œโ”€โ”€ user.js โ”‚ โ”‚ โ””โ”€โ”€ product.js โ”‚ โ”œโ”€โ”€ utils/ # Utility functions โ”‚ โ”‚ โ”œโ”€โ”€ format.js โ”‚ โ”‚ โ”œโ”€โ”€ validate.js โ”‚ โ”‚ โ””โ”€โ”€ storage.js โ”‚ โ”œโ”€โ”€ composables/ # Composable functions โ”‚ โ”‚ โ”œโ”€โ”€ useAuth.js โ”‚ โ”‚ โ””โ”€โ”€ useLoading.js โ”‚ โ”œโ”€โ”€ constants/ # Constant definitions โ”‚ โ”‚ โ””โ”€โ”€ index.js โ”‚ โ”œโ”€โ”€ App.vue โ”‚ โ””โ”€โ”€ main.js โ”œโ”€โ”€ tests/ # Test files โ”œโ”€โ”€ .env # Environment variables โ”œโ”€โ”€ vite.config.js โ”œโ”€โ”€ package.json โ””โ”€โ”€ README.md

3.3 React Project Recommended Structure3.3 React Project Recommended Structure

CODE
my-react-project/ โ”œโ”€โ”€ public/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ assets/ โ”‚ โ”œโ”€โ”€ components/ โ”‚ โ”‚ โ”œโ”€โ”€ common/ # Shared components โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Button/ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ index.jsx โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Button.module.css โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Modal/ โ”‚ โ”‚ โ””โ”€โ”€ business/ # Business components โ”‚ โ”œโ”€โ”€ pages/ # Page components โ”‚ โ”‚ โ”œโ”€โ”€ Home/ โ”‚ โ”‚ โ”œโ”€โ”€ User/ โ”‚ โ”‚ โ””โ”€โ”€ Product/ โ”‚ โ”œโ”€โ”€ hooks/ # Custom Hooks โ”‚ โ”‚ โ”œโ”€โ”€ useAuth.js โ”‚ โ”‚ โ””โ”€โ”€ useFetch.js โ”‚ โ”œโ”€โ”€ services/ # API services โ”‚ โ”‚ โ”œโ”€โ”€ api.js โ”‚ โ”‚ โ””โ”€โ”€ userService.js โ”‚ โ”œโ”€โ”€ store/ # Redux/Zustand state management โ”‚ โ”‚ โ”œโ”€โ”€ slices/ โ”‚ โ”‚ โ””โ”€โ”€ index.js โ”‚ โ”œโ”€โ”€ utils/ โ”‚ โ”œโ”€โ”€ constants/ โ”‚ โ”œโ”€โ”€ App.jsx โ”‚ โ””โ”€โ”€ main.jsx โ”œโ”€โ”€ tests/ โ””โ”€โ”€ package.json

3.4 Key Concepts Explained3.4 Key Concepts Explained

Component Design PrinciplesComponent Design Principles

Single Responsibility: One component does one thingSingle Responsibility: One component does one thing

vue
<!-- โŒ Bad example: Component does too much --> <template> <div> <form @submit="handleSubmit"> <!-- Form content --> </form> <table> <!-- Data table --> </table> <div class="charts"> <!-- Charts --> </div> </div> </template> <!-- โœ… Good example: Split into independent components --> <template> <div> <UserForm @submit="fetchData" /> <UserTable :data="users" /> <UserStats :data="users" /> </div> </template>

State Management StrategyState Management Strategy

State TypeStorage LocationExample
Global statePinia/ReduxUser info, login status, theme settings
Page statePage componentList query conditions, pagination info
Component stateComponent internalForm inputs, modal show/hide
Server stateTanStack Query/SWRServer data, caching

Directory Organization Approach SelectionDirectory Organization Approach Selection

Approach 1: Organize by type (suitable for small projects)Approach 1: Organize by type (suitable for small projects)

CODE
src/ โ”œโ”€โ”€ components/ # All components โ”œโ”€โ”€ views/ # All pages โ”œโ”€โ”€ stores/ # All state โ””โ”€โ”€ services/ # All services

Approach 2: Organize by feature (suitable for medium-to-large projects)Approach 2: Organize by feature (suitable for medium-to-large projects)

CODE
src/ โ”œโ”€โ”€ features/ โ”‚ โ”œโ”€โ”€ auth/ # All code for authentication feature โ”‚ โ”œโ”€โ”€ user/ # All code for user feature โ”‚ โ””โ”€โ”€ product/ # All code for product feature โ”œโ”€โ”€ shared/ # Shared resources โ””โ”€โ”€ App.vue
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

- Project pages < 10 โ†’ Organize by type - Project pages > 20 โ†’ Organize by feature - Team > 5 people โ†’ Organize by feature for parallel development- Project pages < 10 โ†’ Organize by type - Project pages > 20 โ†’ Organize by feature - Team > 5 people โ†’ Organize by feature for parallel development

------

4. Enterprise Level: Large Application Architecture4. Enterprise Level: Large Application Architecture

4.1 Suitable Scenarios4.1 Suitable Scenarios

4.2 Micro-Frontend Architecture4.2 Micro-Frontend Architecture

When a project grows to a certain size and a single codebase becomes difficult to maintain, micro-frontend architecture can be considered.When a project grows to a certain size and a single codebase becomes difficult to maintain, micro-frontend architecture can be considered.

CODE
Large E-Commerce Platform/ โ”œโ”€โ”€ Base Application (Main Framework) โ”‚ โ”œโ”€โ”€ Top Navigation โ”‚ โ”œโ”€โ”€ Side Menu โ”‚ โ”œโ”€โ”€ User Center Entry โ”‚ โ””โ”€โ”€ Sub-application Container โ”œโ”€โ”€ Product Sub-application (Independently deployed) โ”‚ โ”œโ”€โ”€ Product List โ”‚ โ”œโ”€โ”€ Product Details โ”‚ โ””โ”€โ”€ Product Management โ”œโ”€โ”€ Order Sub-application (Independently deployed) โ”‚ โ”œโ”€โ”€ Shopping Cart โ”‚ โ”œโ”€โ”€ Order List โ”‚ โ””โ”€โ”€ Payment Flow โ”œโ”€โ”€ User Sub-application (Independently deployed) โ”‚ โ”œโ”€โ”€ Personal Center โ”‚ โ”œโ”€โ”€ Shipping Addresses โ”‚ โ””โ”€โ”€ Coupons โ””โ”€โ”€ Marketing Sub-application (Independently deployed) โ”œโ”€โ”€ Campaign Pages โ”œโ”€โ”€ Coupon Distribution โ””โ”€โ”€ Points Mall

Advantages of micro-frontends:Advantages of micro-frontends:

4.3 Enterprise-Level Directory Structure4.3 Enterprise-Level Directory Structure

CODE
enterprise-project/ โ”œโ”€โ”€ apps/ # Micro-frontend sub-applications โ”‚ โ”œโ”€โ”€ main/ # Base application โ”‚ โ”œโ”€โ”€ product/ โ”‚ โ”œโ”€โ”€ order/ โ”‚ โ””โ”€โ”€ user/ โ”œโ”€โ”€ packages/ # Shared packages (Monorepo) โ”‚ โ”œโ”€โ”€ ui-components/ # Shared component library โ”‚ โ”œโ”€โ”€ utils/ # Utility functions โ”‚ โ”œโ”€โ”€ constants/ # Constant definitions โ”‚ โ””โ”€โ”€ types/ # TypeScript types โ”œโ”€โ”€ shared/ # Shared configuration โ”‚ โ”œโ”€โ”€ eslint-config/ โ”‚ โ”œโ”€โ”€ ts-config/ โ”‚ โ””โ”€โ”€ vite-config/ โ”œโ”€โ”€ docs/ # Project documentation โ”œโ”€โ”€ scripts/ # Build scripts โ””โ”€โ”€ package.json

4.4 Performance Optimization Architecture4.4 Performance Optimization Architecture

Large applications need to focus on performance optimization:Large applications need to focus on performance optimization:

CODE
Performance Optimization Strategy/ โ”œโ”€โ”€ Build-time Optimization โ”‚ โ”œโ”€โ”€ Code Splitting โ”‚ โ”œโ”€โ”€ Route Lazy Loading โ”‚ โ”œโ”€โ”€ Tree Shaking โ”‚ โ””โ”€โ”€ Asset Compression โ”œโ”€โ”€ Runtime Optimization โ”‚ โ”œโ”€โ”€ Virtual Scrolling (long lists) โ”‚ โ”œโ”€โ”€ Image Lazy Loading โ”‚ โ”œโ”€โ”€ On-demand Component Rendering โ”‚ โ””โ”€โ”€ Caching Strategy โ””โ”€โ”€ Network Optimization โ”œโ”€โ”€ CDN Acceleration โ”œโ”€โ”€ HTTP Caching โ”œโ”€โ”€ Resource Preloading โ””โ”€โ”€ Service Worker

4.5 SSR/SSG Architecture4.5 SSR/SSG Architecture

For scenarios requiring SEO or fast first-screen performance:For scenarios requiring SEO or fast first-screen performance:

ApproachSuitable ScenariosRepresentative Frameworks
SSRNeeds SEO, fast first-screen renderingNext.js, Nuxt.js
SSGStatic content, infrequent updatesAstro, VitePress
HybridPart static, part dynamicNext.js (ISR)

------

5. Architecture Selection by User Scale5. Architecture Selection by User Scale

5.1 Individual/Small Team (Daily Active < 1,000)5.1 Individual/Small Team (Daily Active < 1,000)

Characteristics: Fast iteration, limited resources, rapidly changing requirementsCharacteristics: Fast iteration, limited resources, rapidly changing requirements

Recommended Architecture:Recommended Architecture:

Directory Structure: Simple organization by typeDirectory Structure: Simple organization by type

5.2 Medium Enterprise (Daily Active 1k-100k)5.2 Medium Enterprise (Daily Active 1k-100k)

Characteristics: Complex business, team collaboration, stability requiredCharacteristics: Complex business, team collaboration, stability required

Recommended Architecture:Recommended Architecture:

Directory Structure: Organize by feature, establish standardsDirectory Structure: Organize by feature, establish standards

5.3 Large Platform (Daily Active > 100k)5.3 Large Platform (Daily Active > 100k)

Characteristics: High concurrency, multi-team collaboration, long-term maintenanceCharacteristics: High concurrency, multi-team collaboration, long-term maintenance

Recommended Architecture:Recommended Architecture:

Directory Structure: Monorepo + micro-frontendDirectory Structure: Monorepo + micro-frontend

------

6. Architecture Evolution Roadmap6. Architecture Evolution Roadmap

6.1 Evolution Example: From Blog to Platform6.1 Evolution Example: From Blog to Platform

CODE
Stage 1: Personal Blog (HTML/CSS/JS) โ†“ Need: Backend management needed Stage 2: Add Admin Panel (Vue/React + simple structure) โ†“ Need: User system, comments feature Stage 3: Feature Modularization (organize by feature) โ†“ Need: Multi-team collaboration, independent deployment Stage 4: Micro-frontend Architecture (Monorepo)

6.2 Criteria for Upgrade Your Architecture6.2 Criteria for Upgrade Your Architecture

SignalDescriptionSuggestion
Build time > 5 minutesProject too largeCode splitting, micro-frontend
Frequent merge conflictsCollaboration difficultiesOrganize by feature, module splitting
Fix one thing, break anotherSevere couplingRefactor, strengthen testing
First screen load > 3 secondsPerformance issuesLazy loading, SSR, optimization
Slow onboarding for new membersDisorganized structureDocumentation, standards, refactoring

------

7. Summary7. Summary

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

There is no silver bullet for architecture โ€” what fits is best. - Small projects: Don't over-engineer, HTML/CSS/JS is sufficient - Medium projects: Establish standards, componentization, modularization - Large projects: Consider micro-frontends, performance optimization, team collaboration Remember these points: 1. Progressive evolution: Start simple, grow with needs 2. Unified conventions: Keep naming, structure, and code style consistent 3. Documentation first: Record architecture decisions for knowledge transfer 4. Regular refactoring: Pay off technical debt in a timely manner Ultimate goal: Make code like an organized space โ€” regardless of size, running efficiently.There is no silver bullet for architecture โ€” what fits is best. - Small projects: Don't over-engineer, HTML/CSS/JS is sufficient - Medium projects: Establish standards, componentization, modularization - Large projects: Consider micro-frontends, performance optimization, team collaboration Remember these points: 1. Progressive evolution: Start simple, grow with needs 2. Unified conventions: Keep naming, structure, and code style consistent 3. Documentation first: Record architecture decisions for knowledge transfer 4. Regular refactoring: Pay off technical debt in a timely manner Ultimate goal: Make code like an organized space โ€” regardless of size, running efficiently.

------

Reference ResourcesReference Resources