@wizecorp/stratusjs
Version:
Stratus React Framework
331 lines (264 loc) ⢠8.74 kB
Markdown
# ā” Stratus - Lightweight React Framework
A modern, lightweight React framework inspired by Next.js but designed for simplicity and performance. Build fast, scalable applications with file-based routing, service injection, middleware system, and powerful SSR capabilities.
## š Quick Start
```bash
# Install CLI globally
npm install -g @wizecorp/stratusjs
# Create a new project (interactive)
stratusjs create my-app
# Or create with specific template
stratusjs create my-blog --template ssr # Full SSR
stratusjs create my-site --template hybrid # Universal routing
stratusjs create my-mvp --template default # Services + middleware
# Start development
cd my-app
npm install
npm run dev
```
Open [http://localhost:5173](http://localhost:5173) to view your application.
## ⨠Features
- **šļø File-Based Routing** - Automatic routing based on file structure
- **āļø Service Container** - Dependency injection with clean architecture
- **š”ļø Middleware System** - HOC-based middleware for cross-cutting concerns
- **š SSR & Hybrid Routing** - Full SSR, hybrid rendering, or client-side only
- **šØ TailwindCSS** - Modern utility-first styling with dark mode
- **š§ TypeScript First** - Full TypeScript support with excellent DX
- **š¦ Lightweight** - Minimal bundle size, maximum performance
- **š ļø Modern Tooling** - Vite-powered development and building
- **š¢ Easy Deployment** - One-click deployment to Vercel, Netlify, Docker
## šļø Architecture
```
src/
āāā app/ # File-based routes
ā āāā layout.tsx # Root layout
ā āāā page.tsx # Home page (/)
ā āāā about/
ā āāā page.tsx # About page (/about)
āāā services/ # Service layer with DI
ā āāā ApiService.ts # HTTP service example
āāā middleware/ # HOC middleware system
ā āāā auth.tsx # Authentication middleware
āāā main.tsx # App entry point with service registration
```
## š Core Concepts
### File-Based Routing
Routes are automatically created based on file structure:
```
src/app/page.tsx ā /
src/app/about/page.tsx ā /about
src/app/products/[id]/page.tsx ā /products/:id
src/app/(dashboard)/layout.tsx ā Layout for dashboard pages
```
## Services & Dependency Injection
```tsx
// src/services/ApiService.ts
export class HttpService {
private baseUrl: string;
constructor(baseUrl: string = 'https://api.example.com') {
this.baseUrl = baseUrl;
}
async get<T>(endpoint: string): Promise<T> {
const response = await fetch(`${this.baseUrl}${endpoint}`);
if (!response.ok) {
throw new Error(`HTTP Error: ${response.status}`);
}
return await response.json();
}
}
// src/main.tsx - Register services
const serviceContainer = new ServiceContainer();
serviceContainer.register('httpService', () => new HttpService());
// Use in components
function UsersPage() {
const httpService = useService<HttpService>('httpService');
const [users, setUsers] = useState([]);
useEffect(() => {
httpService.get('/users').then(setUsers).catch(console.error);
}, [httpService]);
return <div>{/* render users */}</div>;
}
```
### Server-Side Rendering
Full SSR support with data fetching:
```typescript
import { GetServerSideProps } from 'stratus';
export const getServerSideProps: GetServerSideProps = async (context) => {
const data = await fetchDataFromAPI();
return {
props: {
data,
serverTimestamp: new Date().toISOString()
}
};
};
export default function Page({ data, serverTimestamp }) {
return (
<div>
<h1>{data.title}</h1>
<p>Generated at: {serverTimestamp}</p>
</div>
);
}
```
### Middleware System
Higher-Order Components for cross-cutting concerns:
```typescript
// src/middleware/auth.tsx
interface AuthOptions {
redirectTo?: string;
requireAuth?: boolean;
}
export function withAuth<P extends {}>(
Component: React.ComponentType<P>,
options: AuthOptions = {}
) {
return function AuthenticatedComponent(props: P) {
if (options.requireAuth && !isAuthenticated()) {
return <LoginPage />;
}
return <Component {...props} />;
};
}
// Usage
export default withAuth(MyProtectedPage, { redirectTo: '/login' });
```
## šÆ Templates
Choose from pre-built templates to kickstart your project:
### šļø Default
**Perfect for:** Most applications, MVPs, client projects
- ā
Service container with dependency injection
- ā
Authentication middleware example
- ā
TailwindCSS with dark mode support
- ā
TypeScript configuration
- ā
Modern component architecture
### š Hybrid
**Perfect for:** Universal applications with SSR needs
- ā
HybridRouter with client-side and server-side rendering
- ā
Automatic hydration support
- ā
All default template features
- ā
Optimized for SEO and performance
- ā
Supports both SSR and CSR pages
### š SSR
**Perfect for:** Content-heavy sites, blogs, e-commerce
- ā
Full server-side rendering with `getServerSideProps`
- ā
Demo SSR page with server data fetching
- ā
Production server configuration
- ā
Enhanced SEO capabilities
- ā
All default template features
## š ļø CLI Commands
```bash
# Create project
stratusjs create <name> # Interactive project creation
stratusjs create my-app --template ssr --js
# Available templates: default, hybrid, ssr
# Development
stratusjs dev # Start dev server
stratusjs dev --port 8080 # Custom port
# Building
stratusjs build # Production build
stratusjs build --ssr # Build with SSR (ssr template)
# Code Generation
stratusjs generate page about # Create page
stratusjs g service user # Create service
stratusjs g layout dashboard # Create layout
# Deployment
stratusjs deploy # Interactive deployment
stratusjs deploy --platform vercel # Deploy to Vercel
```
## š¢ Deployment
### Vercel (Recommended for SSR)
```bash
stratusjs deploy --platform vercel
```
### Netlify (Great for static sites)
```bash
stratusjs deploy --platform netlify
```
### Docker
```bash
stratusjs deploy --platform docker
```
### Node.js Server
```bash
stratusjs deploy --platform node
```
## File Structure
```
src/
app/
page.tsx # ā /
about/
page.tsx # ā /about
layout.tsx # Layout for /about
users/
[id]/
page.tsx # ā /users/:id
blog/
[...slug]/
page.tsx # ā /blog/*slug
layouts/
main.tsx # Reusable layouts
services/
userService.ts # Business logic services
```
## š Documentation
- [CLI Documentation](./CLI.md) - Complete CLI reference
## š§ Configuration
Configure your project in `stratus.config.json`:
```json
{
"name": "my-app",
"template": "default",
"features": {
"ssr": false,
"hybrid": false,
"typescript": true,
"services": true,
"middleware": true,
"tailwindcss": true
},
"routing": {
"routesDir": "src/app",
"layoutsDir": "src/layouts",
"pageExtensions": ["tsx", "ts", "jsx", "js"]
},
"build": {
"outDir": "dist",
"assetsDir": "assets",
"ssr": false
},
"dev": {
"port": 5173,
"open": true,
"host": "localhost"
}
}
```
## š¤ Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests and linting
5. Submit a pull request
## š License
MIT License - see [LICENSE](LICENSE) for details.
## š Why Stratus?
| Feature | Stratus | Next.js | Create React App |
|---------|---------|---------|------------------|
| Bundle Size | ā” Minimal | š¦ Large | š¦ Medium |
| Learning Curve | š Easy | š Moderate | š Easy |
| SSR Support | ā
3 Options | ā
Built-in | ā No |
| File Routing | ā
Yes | ā
Yes | ā No |
| Services DI | ā
Built-in | ā Manual | ā Manual |
| Middleware | ā
HOC System | ā ļø Route-based | ā No |
| TailwindCSS | ā
Pre-configured | ā ļø Manual setup | ā ļø Manual setup |
| CLI Tools | ā
Rich | ā
Rich | ā ļø Basic |
| TypeScript | ā
First-class | ā
Good | ā ļø Setup required |
## šÆ Perfect For
- **Startups** building MVPs quickly
- **Agencies** delivering client projects
- **Developers** who want Next.js simplicity without complexity
- **Teams** needing clean architecture with services
- **Projects** requiring lightweight, fast applications
---
Built with ā¤ļø for the React community. Start building amazing applications today!