Free Bootstrap Admin & Dashboard Template Built for AI-Assisted Development
# Architecture Documentation
## Project Purpose
CoreUI Free Bootstrap Admin Template is a professional admin dashboard template built on Bootstrap 5 and CoreUI components. It provides a ready-to-use foundation for building admin panels, dashboards, and web applications with a clean, modern interface.
**Key Characteristics:**
- Server-side templating approach (Pug β HTML)
- Bootstrap 5 + CoreUI component library
- Vanilla JavaScript (no framework dependencies)
- Multi-page application (MPA) architecture
- Static file generation with build-time compilation
## High-Level Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Source Files β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Pug β β Sass β β JS β β
β βTemplates β β Styles β β Modules β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ β
β β β β β
βββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Build Pipeline β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Pug β βPostCSS + β β syncdir β β
β βCompiler β β Sass β β(copy JS) β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ β
β β β β β
βββββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Distribution Files β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β HTML β β CSS β β JS β β
β β Files β β (minified)β β(bundled) β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β (served via browser-sync or web server) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## Technology Stack
### Frontend
- **HTML Generation**: Pug 3.0.3 (template engine)
- **CSS Framework**: Bootstrap 5.3.x
- **Component Library**: CoreUI 5.x (@coreui/coreui)
- **Icons**: CoreUI Icons (@coreui/icons)
- **JavaScript**: Vanilla ES6+ (no framework)
- **Charts**: Chart.js 4.x
- **Scrollbars**: SimpleBar 6.x
### Build Tools
- **Package Manager**: npm
- **CSS Processing**: Sass 1.102.x β PostCSS β Autoprefixer
- **JS**: plain ES2015+, copied as-is via `sync-directory` (no transpilation - the declared browser targets already support the syntax used, see [Browser Support](#browser-support))
- **Task Runner**: npm scripts with npm-run-all
- **File Watching**: Nodemon
- **Live Server**: Browser-sync 3.0.4
### Code Quality
- **Linting**: ESLint 9.x (flat config) with XO + Unicorn
- **Style Linting**: Stylelint 16.x with Bootstrap config
- **Formatting**: Prettier 3.9.x
- **Editor Config**: .editorconfig for consistency
## Directory Structure
```
coreui-free-bootstrap-admin-template/
β
βββ src/ # Source files (edit these)
β βββ pug/ # Pug templates (HTML source)
β β βββ _layout/ # Base layout templates
β β β βββ default.pug # Main layout with sidebar/header
β β β βββ pages.pug # Standalone pages layout (auth, errors)
β β βββ _partials/ # Reusable components
β β β βββ banner.pug # Top announcement banner
β β β βββ head.pug # HTML <head> section
β β β βββ header.pug # Top navigation bar
β β β βββ sidebar.pug # Left sidebar wrapper
β β β βββ sidebar-nav.pug # Sidebar navigation items (data-driven)
β β β βββ footer.pug # Page footer
β β β βββ scripts.pug # Common script includes
β β β βββ docs-icons.pug # Icon documentation helpers
β β βββ _mixins/ # Pug helper mixins
β β β βββ breadcrumb.pug # Breadcrumb generator
β β β βββ callout.pug # Alert/callout boxes
β β β βββ callout-custom.pug # Custom callout variant
β β β βββ docs-components.pug # Docs component helpers
β β β βββ example.pug # Code example displays
β β β βββ inline-svg.pug # Inline SVG helper
β β βββ views/ # Page templates
β β βββ index.pug # Main dashboard page
β β βββ blank.pug # Blank page template
β β βββ charts.pug # Charts page
β β βββ widgets.pug # Widgets page
β β βββ authentication/ # Auth pages (login, register, etc.)
β β βββ components/ # UI components (buttons, modals, etc.)
β β βββ error-pages/ # Error pages (404, 500)
β β βββ forms/ # Form components
β β βββ icons/ # Icon libraries
β β
β βββ scss/ # Sass stylesheets
β β βββ style.scss # Main stylesheet entry
β β βββ style-rtl.scss # RTL (right-to-left) styles
β β βββ examples.scss # Demo/example page styles
β β
β βββ js/ # JavaScript modules
β β βββ main.js # Main entry point
β β βββ charts.js # Chart.js configurations
β β βββ color-modes.js # Dark/light theme switcher
β β βββ config.js # App configuration / shared settings
β β βββ tooltips.js # Tooltip initialization
β β βββ popovers.js # Popover initialization
β β βββ toasts.js # Toast notification initialization
β β βββ widgets.js # Widgets page charts
β β
β βββ assets/ # Static assets
β β βββ brand/ # Logo files
β β βββ favicon/ # Favicon files
β β βββ img/ # Images
β β
β βββ views/ # Compiled HTML (auto-generated)
β βββ *.html # Do NOT edit these manually
β
βββ dist/ # Production build output
β βββ css/ # Minified CSS
β βββ js/ # Synced JS (copied as-is, no transform)
β βββ assets/ # Copied assets
β βββ vendors/ # Third-party libraries
β βββ *.html # Production HTML files
β
βββ build/ # Build scripts
β βββ pug.mjs # Pug compilation script
β βββ postcss.config.mjs # PostCSS configuration
β βββ vendors.mjs # Vendor file bundling
β βββ format-html.mjs # HTML formatting/prettifying
β
βββ node_modules/ # npm dependencies (ignored)
β
βββ Configuration files
βββ package.json # Dependencies and scripts
βββ .editorconfig # Editor settings
βββ eslint.config.mjs # ESLint flat config
βββ .prettierrc.json # Prettier formatting
βββ .stylelintrc # Stylelint rules
βββ .browserslistrc # Target browsers
βββ .cursorrules # AI context (Cursor IDE)
```
## Build Pipeline Details
### Development Mode (`npm start`)
1. **Clean**: Remove old compiled files
2. **Compile Pug**: `src/pug/**/*.pug` β `src/views/*.html`
3. **Compile Sass**: `src/scss/*.scss` β `dist/css/*.css` (expanded, autoprefixed)
4. **Sync JS**: `src/js/*.js` β `dist/js/*.js` (copied as-is via `sync-directory`, no transform)
5. **Copy Assets**: `src/assets/**/*` β `dist/assets/`
6. **Build Vendors**: Bundle third-party libraries
7. **Watch Files**: Monitor changes and recompile
8. **Browser-sync**: Live reload server on http://localhost:3000
### Production Build (`npm run build`)
1. **All development steps**
2. **Minify CSS**: Compress stylesheets with clean-css-cli
3. **JS**: No separate minify step - shipped as synced source
4. **Optimize Assets**: Copy optimized files
5. **Generate zip**: Create distribution package
### File Watching
```
npm run watch # Watch all file types
npm run watch-pug # Watch Pug templates only
npm run watch-css # Watch Sass files only
npm run watch-js # Watch JavaScript files only
```
Each watch task uses **nodemon** to monitor file changes and trigger appropriate compilation.
## Data Flow
### Page Rendering Flow
```
1. Browser Request
ββ> /index.html
2. Server Response
ββ> Serve dist/index.html (static file)
3. HTML Loads Resources
ββ> dist/css/style.css (Bootstrap + CoreUI + custom styles)
ββ> dist/js/main.js (app initialization)
ββ> dist/vendors/*.js (Chart.js, SimpleBar, etc.)
4. JavaScript Execution
ββ> Initialize CoreUI components
ββ> Set up event listeners
ββ> Configure charts (if on dashboard)
ββ> Enable tooltips/popovers
5. User Interaction
ββ> JavaScript handles UI updates (no page reload)
```
### Theme Switching Flow
```
1. User clicks theme toggle button
ββ> color-modes.js listens for click
2. ColorModeStorageManager updates preference
ββ> Save to localStorage
ββ> Update [data-coreui-theme] attribute
3. CSS custom properties respond
ββ> Variables change (--cui-primary-bg, --cui-text-color, etc.)
4. ColorSchemeChange event fires
ββ> Charts re-render with new theme colors
```
### Chart Rendering Flow
```
1. charts.js module loads
ββ> import Chart from 'chart.js/auto'
2. DOM ready
ββ> Find chart canvas elements
3. Fetch data (or use inline data)
ββ> Random data generator for demo
4. Create Chart.js instance
ββ> Configure chart type (line, bar, pie, etc.)
ββ> Apply theme colors from CSS variables
ββ> Set responsive options
5. Theme changes
ββ> Re-initialize charts with new colors
```
## Component Organization
### Pug Template Hierarchy
```
default.pug (main layout β dashboard/component pages)
ββ> sidebar.pug (side navigation)
β ββ> sidebar-nav.pug (data-driven nav items)
ββ> header.pug (top navigation bar)
β ββ> block breadcrumb
ββ> block canonical / block styles
ββ> block view
β ββ> index.pug / components/*.pug / etc. (page content)
ββ> footer.pug (page footer)
ββ> scripts.pug (common script includes)
ββ> block scripts / block js
pages.pug (standalone layout β auth & error pages)
ββ> block styles
ββ> block view
ββ> authentication/*.pug / error-pages/*.pug
```
**Block System:**
- `block view`: Main page content area (both layouts)
- `block canonical`: `<link rel="canonical">` override (`default.pug` only)
- `block breadcrumb`: Breadcrumb trail, declared inside `header.pug` (`default.pug` only)
- `block scripts` / `block js`: Page-specific script includes, declared inside `scripts.pug`
- Each view extends a layout and overrides only the blocks it needs
### CSS Architecture
```
style.scss
ββ> Import Bootstrap 5
ββ> Import CoreUI components
ββ> Import custom variables
ββ> Import custom component styles
Theme System:
[data-coreui-theme="light"] # Light mode (default)
[data-coreui-theme="dark"] # Dark mode
[data-coreui-theme="auto"] # System preference
```
**CSS Custom Properties:**
- `--cui-primary`, `--cui-secondary`, etc. (colors)
- `--cui-bg`, `--cui-text-color` (backgrounds/text)
- `--cui-border-color`, `--cui-shadow` (UI elements)
### JavaScript Module Pattern
Each JS file in `src/js/` is an ES6 module:
```javascript
// Import dependencies
import { Something } from '@coreui/coreui'
// Define functionality
const doSomething = () => { /* ... */ }
// Initialize on DOM ready
document.addEventListener('DOMContentLoaded', () => {
doSomething()
})
// Export if needed (most files use side effects only)
```
## Key Dependencies
### Runtime Dependencies
| Package | Purpose | Used In |
|---------|---------|---------|
| `@coreui/coreui` | UI component library | All pages |
| `@coreui/icons` | Icon library | Icon pages |
| `chart.js` | Charts and graphs | Dashboard |
| `simplebar` | Custom scrollbars | Sidebar |
| `@coreui/utils` | Utility functions | Theme switching |
### Build Dependencies
| Package | Purpose |
|---------|---------|
| `sass` | CSS preprocessing |
| `sync-directory` | Copy `src/js`, `src/assets`, `src/views` into `dist/` |
| `pug` | HTML templating |
| `postcss` | CSS post-processing |
| `autoprefixer` | Vendor prefix automation |
| `browser-sync` | Development server |
| `eslint` | JavaScript linting |
| `stylelint` | CSS linting |
## Browser Support
Defined in `.browserslistrc`:
```
>= 0.5%
last 2 major versions
not dead
Chrome >= 60
Firefox >= 60
Firefox ESR
iOS >= 12
Safari >= 12
not Explorer <= 11
```
Modern browsers with native ES2015+ support - this is also why `src/js` ships untranspiled (see [Build Tools](#build-tools)).
## Deployment
### Static Hosting (Recommended)
1. Run `npm run build`
2. Deploy `dist/` folder to:
- Netlify
- Vercel
- GitHub Pages
- AWS S3 + CloudFront
- Any static file server
### Traditional Web Server
1. Run `npm run build`
2. Copy `dist/` contents to web root
3. Configure server to serve `index.html` as default
4. Set proper MIME types for CSS/JS files
### Docker (Optional)
```dockerfile
FROM nginx:alpine
COPY dist/ /usr/share/nginx/html/
EXPOSE 80
```
## Performance Considerations
### CSS Optimization
- Sass compilation removes unused styles
- PostCSS autoprefixer adds only necessary prefixes
- Minification in production build
- CSS is render-blocking (loaded in `<head>`)
### JavaScript Optimization
- No transpilation or minification step - files are copied as-is (see [Build Tools](#build-tools))
- Files loaded as separate scripts (no bundler)
- Deferred script loading where possible
### Asset Optimization
- SVG icons (scalable, small file size)
- Favicon in multiple formats for compatibility
- Images in `src/assets/` should be optimized before adding
## Security Considerations
### Content Security Policy (CSP)
Template includes inline scripts and styles. For strict CSP:
1. Extract inline scripts to external files
2. Use nonces or hashes for required inline scripts
3. Update CSP headers accordingly
### XSS Prevention
- Pug automatically escapes HTML by default
- Use `!= html` only for trusted content
- Sanitize user input on server-side (if adding backend)
### Dependency Management
- Regularly update npm dependencies
- Run `npm audit` to check for vulnerabilities
- Pin major versions in `package.json`
## Extensibility
### Adding New Pages
1. Create `src/pug/views/my-page.pug`
2. Extend layout: `extends ../_layout/default.pug`
3. Override the `view` block (see [Block System](#pug-template-hierarchy)):
```pug
block view
.container-lg.px-4
h1 My Page Title
p Page content here
```
4. Add an entry to `src/pug/_partials/sidebar-nav.pug` so the page is reachable from the sidebar
5. Run `npm run pug` (or `npm start`) to compile
6. Access at `/my-page.html`
### Adding New Components
1. Check CoreUI docs: https://coreui.io/bootstrap/docs/
2. Copy component markup to Pug file
3. Convert HTML to Pug syntax (use html2pug.com if needed)
4. Import required JavaScript:
```javascript
import { Modal } from '@coreui/coreui'
```
5. Initialize component in page-specific JS
### Adding New Styles
1. Edit `src/scss/style.scss` or create new partial
2. Use Sass modules syntax to import CoreUI:
```scss
@use "@coreui/coreui/scss/coreui" as * with (
$enable-deprecation-messages: false
);
```
For CoreUI Pro projects:
```scss
@use "@coreui/coreui-pro/scss/coreui" as * with (
$enable-deprecation-messages: false
);
```
3. Use CSS custom properties for theme compatibility
4. Run `npm run css` to compile
### Integrating Backend APIs
This template is frontend-only. To add backend:
1. **Fetch API** for AJAX requests:
```javascript
fetch('/api/endpoint')
.then(response => response.json())
.then(data => updateUI(data))
```
2. **Authentication**: Implement token-based auth
- Store JWT in localStorage/sessionStorage
- Add Authorization header to requests
- Redirect to login on 401 responses
3. **State Management**: For complex apps, consider:
- Vanilla JS with custom events
- Lightweight state library (Zustand, Nano Stores)
- Full framework migration (React, Vue, etc.)
## Common Issues and Solutions
### Pug Compilation Errors
- **Error**: "Cannot find module"
- **Fix**: Check Pug include/extend paths (relative to file)
### Sass Compilation Errors
- **Error**: "Undefined variable"
- **Fix**: Import Bootstrap/CoreUI variables before using
### JavaScript Errors
- **Error**: "X is not defined"
- **Fix**: Add `/* global X */` comment or import module
### Live Reload Not Working
- **Error**: Browser-sync not updating
- **Fix**: Check if `watch` scripts are running, restart `npm start`
### Build Fails
- **Error**: npm scripts fail
- **Fix**: Delete `node_modules/` and `dist/`, run `npm install`, then `npm run build`
## Resources
- **CoreUI Bootstrap Docs**: https://coreui.io/bootstrap/docs/
- **Pug Documentation**: https://pugjs.org/
- **Chart.js Documentation**: https://www.chartjs.org/
- **Sass Documentation**: https://sass-lang.com/documentation/
## Changelog
See [releases](https://github.com/coreui/coreui-free-bootstrap-admin-template/releases) for version history and updates.