Data Flow
Donβt worry β itβs subtle and doesnβt affect the overall flow.
Core Component Relationships
The interconnections between core components are critical for understanding the system's architecture:
App.js as the Central Orchestrator
App.js serves as the central orchestration component in Aether CMS. It:
- Initializes all core systems in the proper sequence
- Connects the Routes and Hook System
- Sets up all API endpoints
- Creates middleware for security and authentication
- Manages error handling for the entire application
// From app.js
export async function setupApp(app, config) {
// Initialize core systems
hookSystem = new HookSystem()
fileStorage = new FileStorage(config.uploadsDir)
authManager = new AuthManager(config.dataDir)
// ...
// Set up API routes
setupContentApi(app, systems)
setupThemeApi(app, systems)
setupMediaApi(app, systems)
setupUserApi(app, systems)
setupStaticApi(app, systems)
}
Hook System Integration
The Hook System provides extension points throughout the application:
- It's initialized early in the bootstrap process
- Routes utilize hooks for request processing
- Content rendering passes through hooks for modification
- APIs apply hooks for filtering and transformation
- Static site generation uses hooks for content optimization
// Example of hook usage in content API
const filteredPosts = hookSystem.applyFilters("api_posts", posts, req)
Routes and Request Flow
Routes define how requests flow through the system:
- Client requests enter through the Routes component
- Routes use the Hook System for processing
- App.js connects Routes to the appropriate API endpoints
- APIs interact with the necessary Service Layer components
- Responses flow back through the same path# Aether CMS Data Flow Documentation
Overview
Aether CMS is built with a modular architecture that efficiently manages data flow between its various components. This document provides a comprehensive overview of how data moves through the system, from user input to storage and output generation. Understanding these data flows is crucial for developers who want to extend or customize Aether CMS functionality.
System Architecture
Aether CMS follows a layered architecture with clear separation of concerns:
1. Client Layer
The entry point for all interactions with the system. This includes:
- Admin Interface - Where content management occurs
- Frontend Theme - What visitors see when browsing the site
- Static Site Generator - Creates static HTML files for deployment
2. Core App Layer
The orchestration layer that initializes and coordinates all subsystems:
- App.js - The central component that initializes all subsystems and connects them
- Routes - Handles URL routing for both frontend and admin interfaces
- Hook System - Provides plugin-like extensibility for the CMS
The Core App Layer has an important internal flow:
- Hook System provides services to Routes
- Routes are integrated into App.js
- App.js connects to all API endpoints
3. API Layer
RESTful endpoints that handle specific types of requests:
- Content API - Manages posts, pages, and custom content
- Media API - Handles file uploads and media management
- Theme API - Controls theme selection and customization
- User API - Manages authentication and user permissions
- Static API - Facilitates static site generation
4. Service Layer
Specialized managers that implement the business logic:
- Content Manager - Handles content creation, storage, and retrieval
- Theme Manager - Manages theme templates and appearance
- Auth Manager - Controls authentication and permissions
- File Storage - Manages media uploads and file operations
- Settings Service - Stores and retrieves configuration options
5. Data Storage Layer
Persistent storage for content, settings, and files:
- Content Files - Markdown files with YAML frontmatter
- Theme Files - HTML templates, CSS, and JavaScript files
- Users & Sessions - Authentication and session data
- Uploaded Files - Images and other media
- Settings Files - System and site configuration
6. Output Layer
Generated static site files for deployment:
- HTML, CSS, JavaScript, and assets compiled for distribution
Key Data Flows
Content Management Flow
The core functionality of Aether CMS is content management. Here's how content data flows through the system:
Content Creation
Admin Interface β App.js β Content API β Content Manager β Content Files
- User Input: The admin interface collects post/page data through the editor.
- Request Routing: App.js directs the request to the Content API.
- API Processing: The Content API validates the request and passes it to ContentItemManager.
- Content Processing:
- The ContentItemManager generates an ID and adds timestamps.
- For posts, it processes frontmatter properties like category and tags.
- For pages, it handles pageType and parent relationships.
- Storage: Content is saved as Markdown files with YAML frontmatter.
Content Retrieval
Frontend Request β Routes β Hook System β App.js β Content API β ContentQueryManager β Content Files β Template Rendering
- URL Request: User visits a content URL (e.g.,
/post/my-post
). - Route Handling: Routes identify the content type and slug, passing through the Hook System.
- Request Processing: App.js directs the request to the Content API.
- Content Query: ContentQueryManager retrieves the content by property (e.g., slug).
- Content Processing:
- Content is parsed from Markdown to HTML.
- Related content (prev/next posts, category listings) is fetched if needed.
- Hook system filters may modify the content.
- Template Rendering: The content is passed to the theme template for rendering.
Theme System Flow
The theme system determines how content is presented to users:
Frontend Request β Routes β Hook System β App.js β Theme API β ThemeManager β Template Rendering
- Request Handling: A frontend request is received by Routes, processed through the Hook System.
- API Routing: App.js directs the request to the Theme API.
- Theme Discovery: During initialization, the system scans for available themes.
- Theme Selection: The active theme is determined from settings.
- Template Resolution: When rendering content, the appropriate template is selected following the resolution path:
- For posts:
custom/<slug>.html
βpost.html
βcontent.html
βlayout.html
- For pages:
custom/<slug>.html
βpage.html
βcontent.html
βlayout.html
- For taxonomies:
custom/<taxonomy>-<term>.html
βcustom/<taxonomy>.html
βtaxonomy.html
βlayout.html
- For posts:
- Template Data Preparation: Template data is assembled, including:
- Content data (title, body, metadata)
- Site settings
- Navigation menus
- Administrative bars (for logged-in users)
- Hook Processing: Template data passes through the hook system, allowing for customizations.
- HTML Rendering: The template is rendered with the prepared data.
File Storage Flow
Media files (images and documents) are managed through a dedicated subsystem:
Media Upload β App.js β Media API β FileManager β ImageHandler/DocumentHandler β File System
- File Upload: Files are uploaded via the admin interface.
- Request Routing: App.js directs the request to the Media API.
- File Processing:
- A unique filename is generated based on the original name and a random ID.
- Images may be processed for thumbnails or optimizations.
- Metadata is extracted (dimensions, file type, etc.).
- Storage: Files are saved to the appropriate directory (images or documents).
- Metadata Storage: A separate metadata JSON file is created alongside the media file.
- Reference Tracking: When media is embedded in content, references are tracked to maintain integrity.
Authentication Flow
User authentication follows a secure process:
Login Request β Routes β App.js β Auth API β UserManager β PasswordService β Session Creation
- Login Attempt: User submits credentials to the login form.
- Request Routing: Routes direct the request to App.js, which forwards it to the Auth API.
- Rate Limiting: RateLimiter checks for excessive login attempts.
- User Lookup: UserManager retrieves the user by username.
- Password Verification: PasswordService verifies the password hash using Argon2.
- Session Creation: Upon successful authentication, SessionManager creates a token.
- Cookie Storage: The token is stored as a secure HTTP-only cookie.
- Authorization: For subsequent requests, middleware extracts and verifies the token.
Static Site Generation Flow
Aether CMS can generate static sites for deployment:
Static Site Gen β Hook System β Routes β App.js β Static API β Service Layer β Data Storage β Static Output
- Generation Trigger: Admin initiates generation via UI or command line.
- Process Orchestration:
- Request flows through the Hook System and Routes
- App.js directs the request to the Static API
- Static API accesses multiple services simultaneously:
- Content Manager for all published content
- Theme Manager for rendering templates
- Auth Manager for permission validation
- File Storage for media assets
- Settings Service for configuration options
- Content Collection: The generator fetches all published content.
- Template Processing: Each content item is processed with its appropriate template.
- Asset Collection: Theme assets and uploaded media are copied to the output directory.
- SEO File Generation: Sitemap XML, RSS feed, and robots.txt are generated.
- URL Processing: URLs are formatted according to the configured pattern (clean or with extensions).
- File Output: All generated files are written to the specified output directory.
Data Storage
Aether CMS uses file-based storage for all data:
Content Storage
Content is stored as Markdown files with YAML frontmatter:
---
id: "1684319454298"
title: "Sample Post"
slug: "sample-post"
status: "published"
author: "admin"
createdAt: "2023-05-17T10:30:54.298Z"
updatedAt: "2023-05-17T11:45:12.456Z"
category: "development"
tags: ["javascript", "cms", "tutorial"]
---
# This is a sample post
Content goes here in Markdown format.
## Subheading
More content...
User Data
User accounts are stored in JSON format:
[
{
"id": "a1b2c3d4",
"username": "admin",
"email": "admin@example.com",
"passwordHash": "$argon2id$v=19$m=65536,t=3,p=2$...",
"role": "admin",
"createdAt": "2023-05-01T00:00:00.000Z",
"updatedAt": "2023-05-01T00:00:00.000Z"
}
]
Settings
Settings are stored in a central JSON file:
{
"siteTitle": "My Aether Site",
"siteDescription": "A site built with Aether",
"postsPerPage": 10,
"activeTheme": "default",
"siteUrl": "https://example.com",
"staticOutputDir": "_site",
"staticCleanUrls": true
}
Media Files
Media files are stored with accompanying metadata:
/content/uploads/images/my-image-a1b2c3d4.jpg
/content/uploads/images/my-image-a1b2c3d4.jpg.metadata.json
{
"alt": "Sample image",
"width": 800,
"height": 600,
"createdAt": "2023-05-17T10:30:54.298Z",
"updatedAt": "2023-05-17T10:30:54.298Z"
}
Hooks and Extensions
The Hook System provides a way to modify data as it flows through the system:
Action Hooks
Triggered at specific points but don't modify data:
hookSystem.doAction("post_created", post)
Filter Hooks
Allow modification of data as it passes through:
const filteredPosts = hookSystem.applyFilters("api_posts", posts, req)
Performance Considerations
Aether CMS optimizes data flow for performance:
- In-Memory Caching: Settings and frequently accessed data are cached in memory.
- Lazy Loading: Content is loaded only when needed.
- Pagination: Large collections are paginated to reduce memory usage.
- Query Parameters: Content can be optimized with parameters:
frontmatterOnly=true
- Returns only metadata without contentproperties=id,title,slug
- Returns only specified propertiessummaryView=true
- Returns truncated content previews
- Batch Processing: Bulk operations use batching to manage memory usage.
Security in Data Flow
Aether CMS implements several security measures:
- Input Validation: All user inputs are validated at the API layer.
- Password Security: Passwords are hashed using Argon2id with secure parameters.
- Rate Limiting: Login attempts are rate-limited to prevent brute force attacks.
- Token-Based Authentication: Secure HTTP-only cookies for authentication.
- Permission Checks: Role-based access control for administrative operations.
- Data Sanitization: Content is sanitized before storage and rendering.
Troubleshooting Common Data Flow Issues
Content Not Appearing
- Check the content status (must be "published").
- Verify the slug is properly formatted.
- Check template path resolution.
- Look for hook filters that might be affecting content display.
Theme Changes Not Reflected
- Verify the active theme in settings.
- Check template path resolution.
- Clear the theme cache using the refresh endpoint.
Media Reference Issues
- Check for correct URL references in content.
- Verify that the media file exists.
- Check media metadata for problems.
- Use the reference manager to identify and fix broken references.
Advanced Data Flow Customization
Custom Content Types
You can extend Aether CMS with custom content types by:
- Creating a new directory under
/content/data/
. - Implementing a custom ContentTypeManager.
- Adding API endpoints for the new type.
- Adding routes for frontend display.
Custom Data Storage
While Aether CMS uses file-based storage by default, you can implement custom storage:
- Create adapter classes that implement the same interfaces.
- Replace the default managers during initialization.
- Implement custom read/write methods.
Conclusion
The data flow in Aether CMS is designed to be modular, extensible, and performant. By understanding how data moves through the system, developers can effectively customize and extend the CMS to meet specific requirements while maintaining the integrity of the core architecture.
For further details on specific components, refer to the API documentation and the code comments in the relevant modules.