ASTRO Tech and more
· Witness in the Machine
Integration to Modern Web Infrastructure.
Astro Web Development: Technical Architecture
From Industrial Systems Integration to Modern Web Infrastructure
Project Structure
Astro is Project-Level, Not System-Level
Astro lives in your project directory, not as a system service:
~/Projects/my-astro-site/
├── node_modules/
│ └── astro/
│ └── dist/
│ └── content/
│ └── loaders/
├── src/
│ ├── pages/
│ ├── components/
│ └── layouts/
├── public/
├── astro.config.mjs
└── package.json
Key commands:
npm run dev- Start development server (localhost:4321)npm run build- Compile to static files indist/npm install- Install dependencies
The Build Pipeline
From Code to Production
Development Phase
├── npm run dev
├── Edit files in src/
└── Hot reload (instant preview)
↓
Build Phase
├── npm run build
├── Astro compiles everything
└── Creates dist/ folder
↓
Deployment Phase
├── Push to Git (GitHub/GitLab)
├── Cloudflare Pages auto-builds
└── Deploys to edge CDN
↓
Production
└── Static files served globally
WordPress vs Astro Comparison
| WordPress | Astro |
|---|---|
| Database → PHP → HTML (every request) | Write once → Build → Serve static |
| Server processes each page load | Pre-rendered HTML |
| Plugin vulnerabilities | No backend to exploit |
| Slow (database queries) | Fast (static files) |
| Black box | Transparent architecture |
Dependencies and Node Modules
What’s in node_modules/?
The node_modules/ folder contains all project dependencies:
node_modules/
├── astro/ # Framework core
├── react/ # For interactive islands
├── sharp/ # Image optimization
├── vite/ # Build tool (bundler)
├── remark-*/ # Markdown processing
├── rehype-*/ # HTML transformation
└── [hundreds more...]
Dependency Philosophy
Modern approach: Small, focused packages (Unix philosophy for JavaScript)
Industrial parallel:
- SCADA needs: PLC drivers, database connectors, visualization libraries
- Web needs: Framework, build tools, content processors, UI libraries
In package.json (what YOU specify):
{
"dependencies": {
"astro": "^5.0.0",
"react": "^18.0.0"
}
}
npm install pulls in:
- Direct dependencies (astro, react)
- Their dependencies
- Dependencies of dependencies
- Result: 500+ packages in node_modules/
Import Resolution
How Import Paths Work
import { glob } from 'astro/loaders';
Resolves to:
node_modules/astro/dist/content/loaders/glob.js
The loaders directory contains:
loaders/
├── glob.js # Pattern-based file loading
├── glob.d.ts # TypeScript definitions
├── file.js # Individual file loading
├── file.d.ts
├── index.js # Main exports
├── index.d.ts
├── types.js # Type definitions
└── errors.js # Error handling
File types:
.jsfiles = Actual executable code.d.tsfiles = TypeScript type definitions (for IDE autocomplete)
Data Structures and OOP Patterns
Astro Uses Typed Data Structures
// Define schema (like a class definition)
const blogCollection = defineCollection({
loader: glob({
pattern: '*.md',
base: './src/content/blog'
}),
schema: z.object({
title: z.string(),
date: z.date(),
author: z.string(),
})
});
Data flow:
- Loader scans filesystem
- Parses frontmatter from markdown
- Returns array of objects
- Schema validates structure (Zod = runtime type checking)
- Build system processes data
- Pages query collection:
const posts = await getCollection('blog')
C++ Equivalent
class BlogPost {
string title;
date publishDate;
string author;
};
vector<BlogPost> posts = loader.loadPosts();
Same concept: strongly-typed data structures passed through a processing pipeline.
Edge Computing and IoT Architecture
The Parallel: Web Infrastructure = Industrial IoT
Industrial SCADA System:
Sensor (data source)
↓
PLC/Gateway (data acquisition)
↓
Validation/Filtering (data integrity)
↓
Processing (transformation)
↓
SCADA Edge Nodes (distributed monitoring)
↓
Central Dashboard (visualization)
Modern Web Stack (Astro + Cloudflare):
Content Source (markdown, API, CMS)
↓
Astro Loader (data acquisition)
↓
Schema Validation (data integrity)
↓
Build Process (transformation)
↓
Cloudflare Edge (distributed deployment)
↓
Browser (visualization)
Key Insight: Every IoT Device = Data Structure on Network
IoT Architecture:
- Device exposes API endpoint
- Returns JSON (data structure)
- Edge processes/validates
- Distributes to network
Web Architecture:
- Content source exposes data
- Loader returns structured data
- Build validates/transforms
- CDN distributes globally
Islands Architecture
Strategic Interactivity
Concept: Most of the page is static HTML, but specific components (“islands”) are interactive.
Static HTML (fast, cacheable)
+
Interactive Islands (React/Vue/Svelte components)
=
Optimal Performance
Example:
---
// Static at build time
const posts = await getCollection('blog');
---
<h1>Blog Posts</h1>
{posts.map(post => <article>{post.data.title}</article>)}
<!-- Interactive island -->
<Counter client:load />
Industrial parallel:
- Most infrastructure: Static, reliable, fast
- Sensors/actuators: Interactive, strategic placement
- Minimal overhead where not needed
Benefits
- Performance: Ship minimal JavaScript
- Reliability: Static = fewer failure points
- Cost: Less compute needed
- SEO: Full HTML available immediately
File System and Directory Structure
What You Work With
src/
├── pages/ # Routes (index.astro = homepage)
│ ├── index.astro
│ ├── about.astro
│ └── blog/
│ └── [slug].astro
├── components/ # Reusable UI pieces
│ ├── Header.astro
│ └── Footer.astro
├── layouts/ # Page templates
│ └── BaseLayout.astro
└── content/ # Content collections
└── blog/
├── post-1.md
└── post-2.md
public/ # Static assets (copied as-is)
├── images/
└── fonts/
astro.config.mjs # Configuration
package.json # Dependencies
tsconfig.json # TypeScript settings
What You Ignore
node_modules/ # Dependencies (never edit)
dist/ # Build output (generated)
.astro/ # Cache (generated)
Technical Advantages
Why Astro for Production
Performance:
- Pre-rendered HTML
- Minimal JavaScript shipped
- Edge CDN distribution
- Sub-second page loads
Security:
- No database
- No server-side code in production
- Static files only
- No plugin vulnerabilities
Reliability:
- No runtime dependencies
- Distributed edge network
- No database failures
- Predictable behavior
Developer Experience:
- Hot reload in development
- TypeScript support
- Component-based architecture
- Framework-agnostic (use React, Vue, Svelte, etc.)
Cost:
- Static hosting (cheap/free)
- No server maintenance
- Minimal compute needed
Build Process Details
What Happens During Build
-
File Discovery
- Scans
src/pages/for routes - Loads content collections
- Processes components
- Scans
-
Content Loading
- Loaders fetch data (filesystem, APIs, CMS)
- Schema validation
- Data transformation
-
Compilation
- Astro components → HTML
- CSS extraction and optimization
- JavaScript bundling (minimal)
- Image optimization
-
Output Generation
- Creates
dist/folder - Static HTML files
- Optimized assets
- Sitemap, RSS, etc.
- Creates
Build Output Example
dist/
├── index.html
├── about/
│ └── index.html
├── blog/
│ ├── post-1/
│ │ └── index.html
│ └── post-2/
│ └── index.html
├── _astro/
│ ├── styles.abc123.css
│ └── client.def456.js
└── images/
└── hero.optimized.webp
Integration Points
Cloudflare Pages Deployment
Git-based workflow:
- Push code to GitHub
- Cloudflare detects push
- Runs
npm run build - Deploys
dist/to edge network - Live in ~30 seconds
Environment variables:
- Set in Cloudflare dashboard
- Available during build
- For API keys, feature flags, etc.
Content Sources
Astro can load content from:
- Local files: Markdown, JSON, YAML
- APIs: REST, GraphQL
- CMS: Contentful, Sanity, WordPress (headless)
- Databases: At build time
System Comparison: Industrial → Web
| Industrial Systems | Web Infrastructure |
|---|---|
| PLC protocols (Modbus, Profibus) | APIs (REST, GraphQL) |
| SCADA data acquisition | Content loaders |
| Data validation | Schema validation (Zod) |
| Edge computing nodes | CDN edge servers |
| Real-time monitoring | Static + islands |
| System integration | Build pipeline |
| Deterministic behavior | Static generation |
| Documented architecture | Config files |
Key Takeaways
- Astro is project-based, not system-level
- Dependencies are libraries - modern web uses many small packages
- Build pipeline transforms source → static output
- Data structures flow through typed schemas
- Edge deployment = distributed, reliable infrastructure
- Islands architecture = strategic interactivity
- Same engineering principles as industrial systems integration
Resources
- Astro Documentation: https://docs.astro.build
- Loaders location:
node_modules/astro/dist/content/loaders/ - Package manager: npm (Node Package Manager)
- Build tool: Vite (fast, modern bundler)
- Deployment: Cloudflare Pages, Netlify, Vercel
Quick Command Reference
# Create new Astro project
npm create astro@latest
# Install dependencies
npm install
# Start dev server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Find Astro installation
find ~ -name "astro.config.mjs"
# View loaders
ls node_modules/astro/dist/content/loaders/