Directory overview
A typical COSMOS RSC project has the following structure:The app/ directory
This is where all your application code lives.
Pages
Theapp/pages/ directory contains your page components. Each file maps to a route:
app/pages/index.js
Components
Theapp/components/ directory holds reusable components. Components are Server Components unless marked with 'use client':
app/components/button.js
Actions
Theapp/actions/ directory contains server actions - functions that run on the server and can be called from forms or client components:
app/actions/form-actions.js
Root layout
Theapp/root-layout.js file defines the HTML structure that wraps all pages:
app/root-layout.js
Global styles
Theapp/globals.css file contains your global CSS, including Tailwind imports:
app/globals.css
The core/ directory
The core/ directory contains the framework implementation. You typically don’t need to modify these files.
Build system
core/build/index.js- Build orchestrationcore/build/webpack.config.js- Webpack configuration for client bundle
Client runtime
core/client/index.js- Client entry pointcore/client/components/- Internal client componentscore/client/lib/- Client-side utilities (routing, RSC payload handling)
Server runtime
core/server/index.js- Express servercore/server/lib/- Server utilities (cookies, manifests, rendering)core/server/exports.js- Public server APIs
Build artifacts
When you runnpm run build, COSMOS RSC generates the .cosmos-rsc/ directory:
client.js- Bundled client-side JavaScriptstyle.css- Compiled CSS with Tailwind*.map- Source maps for debugging
Package configuration
Thepackage.json includes important configuration:
imports field creates the #cosmos-rsc/server alias for importing server utilities like cookies().