Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copy to `.env` and fill in real values. Never commit `.env`.
#
# Convention: only variables prefixed `THEXJS_PUBLIC_` are safe to reference
# from client-shipped code. Everything else is server-only — reading it in a
# component, island, or action import fails the build.

# ---- Server ----
# Port the server listens on (default: 3000)
PORT=3000

# Set by the deploy platform; makes cookies `Secure` and picks production
# React builds. Don't set this to "development" in production.
NODE_ENV=production

# ---- Data layer (server-only) ----
# Used by connectPostgres / connectSQLite defaults.
DATABASE_URL=postgres://user:password@localhost:5432/mydb

# ---- Rate limiting (optional, multi-instance only) ----
# Used by createRedisRateLimitStore for cluster-wide rate limiting.
# REDIS_URL=redis://localhost:6379

# ---- Public (safe for client code) ----
# Example only: any THEXJS_PUBLIC_* variable may be read in the browser.
THEXJS_PUBLIC_API_URL=https://api.example.com

# ---- Secrets (server-only; never reference these in client code) ----
# STRIPE_SECRET_KEY=sk_live_...
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dependabot — automated dependency updates.

version: 2
updates:
# "bun" is the native ecosystem for bun.lock; "npm" can't parse bun.lock
# correctly and its versioning-strategy isn't supported for Bun.
- package-ecosystem: "bun"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
35 changes: 33 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ on:

jobs:
test:
runs-on: ubuntu-latest
name: Test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# Pinned for reproducible builds — bump deliberately.
bun-version: 1.3.14

- name: Install dependencies
run: bun install --frozen-lockfile
Expand All @@ -26,3 +34,26 @@ jobs:

- name: Test
run: bun test

audit:
name: Dependency audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.14

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Audit dependencies
run: bun audit

# Guard the production-only graph separately: anything in what's actually
# shipped must be clean with NO ignores.
- name: Audit production dependencies
run: bun audit --prod
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ x start

# x run dev also works (alias)
# x build --adapter vercel emits .vercel/output (requires @thexjs/adapter-vercel)
# x build --outDir dist writes the build to ./dist (Dockerfile/DEPLOY.md use this)
# --cwd <dir> run as if from another directory
```

## Build output

- `x build` writes to `.x/` (configurable via `outDir`)
- `x build` writes to `.x/` (configurable via `--outDir` or `outDir`)
- `.x/client/` — static HTML, island JS chunks, public assets
- `.x/server/index.ts` — generated server entry (run with `x start` or `bun .x/server/index.js`)
- `.x/server/index.ts` — generated server entry (run with `x start` or `bun .x/server/index.ts`)
- `x start` runs the production server from `.x/server/`
- The generated server entry handles `SIGTERM`/`SIGINT` gracefully (stops
accepting connections, flushes the error reporter, drains for 3s, exits)

## File-based routing conventions

Expand Down
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Changelog

All notable changes to x are documented here. Format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
uses [Calendar Versioning](https://calver.org/) with `YYYY.MM.DD` release
dates. This is a pre-1.0 project — expect breaking changes between releases.

## Unreleased

### Security

- Hardened `assertNoEnvLeakage`: it now also flags `import.meta.env["KEY"]`,
dynamic keys (`process.env[key]`), string-concatenated keys
(`process.env["ST"+"RIPE"]`), and aliased `process.env` access.
- Added a Redis-backed rate-limit store (`createRedisRateLimitStore`) for
multi-instance deployments, and rate-limiter buckets are now swept
automatically instead of only on explicit `sweep()` calls.
- CSRF and session cookies are now sent with `Secure` when
`NODE_ENV=production`.
- `connectPostgres` gained pool sizing (`max`), TLS enforcement (defaults to
`require` in production), and optional CA certs.
- Removed the per-request `[x][security] applied N header(s)` log line that
spammed stdout in production.

### Fixed

- **Docker build was broken**: the `Dockerfile`/`DEPLOY.md` referenced
`dist/` while `x build` wrote `.x/`. The CLI now supports
`x build --outDir <dir>` (and `x start --outDir <dir>`), and the Dockerfile
builds with `--outDir dist`. The generated server entry is `index.ts`, not
`index.js` — both docs and the image `CMD` were updated to match.
- **Dockerfile didn't copy all workspace `package.json` files**, so
`bun install --frozen-lockfile` failed. It now copies every workspace's
manifest before installing.
- `examples/basic` and `examples/saas` auth opened a new SQLite connection and
re-ran migrations on **every** call. Both now use a module-level singleton
connection and run migrations once (creating the `data/` dir if missing).
- The `saas` template login form was non-functional (no handler). It now
submits to a real `POST` route with client-side feedback, matching the
`basic` template.

### Docs

- Added `SECURITY.md`, `.env.example`, `CONTRIBUTING.md`, `CHANGELOG.md`, and
`CODE_OF_CONDUCT.md`.
- Templates' demo auth (hardcoded `admin`/`admin`) is now explicitly marked
DEMO ONLY in code and on the login pages.

### CI

- Pinned the Bun version (`1.3.14`) instead of `latest` for reproducible
builds, added a Linux + macOS matrix, and a separate `bun audit` job.
- Added Dependabot configuration for weekly dependency updates.

## 0.1.x — pre-release

See the git history for changes before this changelog existed.
72 changes: 72 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

- The use of sexualized language or imagery, and sexual attention or advances
of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for
moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at the email
address listed in the repository profile. All complaints will be reviewed and
investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.

[homepage]: https://www.contributor-covenant.org
87 changes: 87 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Contributing to x

Thanks for wanting to help. This is a small solo framework project, so a few
guidelines keep it reviewable and consistent.

## Project layout

```
packages/core framework runtime (router, SSR/SSG, islands, server functions, data layer)
packages/cli x dev / x build / x start
packages/env type-safe env validation
packages/adapter-vercel Vercel Build Output API adapter
packages/create-thexjs-app `bun create thexjs-app@latest` scaffolder
examples/* dogfood apps (basic, blog, default, landing, saas)
```

## Prerequisites

- [Bun](https://bun.sh) 1.3.x or later
- Node.js is **not** used at any point in this repo

## Setup

```sh
bun install # builds all packages (postinstall) and links the CLI
```

## Common commands

```sh
bun run dev # builds packages, then runs examples/basic in dev
bun run build:packages
bun run typecheck # strict TS across every package + example
bun run lint # biome check . (bun run lint:fix to autofix)
bun test # all tests
bun test <path> # a single test file
```

## Making changes

1. Branch off `main` and give the branch a short, descriptive name.
2. Make the change. Prefer small, focused commits; use the repo's commit style
(`feat:`, `fix:`, `docs:`, `chore:`).
3. Add or update tests for anything in `packages/core` — every feature has a
test file next to its source (`*.test.ts`), run with `bun test`.
4. Run `bun run lint`, `bun run typecheck`, and `bun test` before pushing.
CI runs the same three on both Ubuntu and macOS.
5. If you change templates in `packages/create-thexjs-app/templates/*`, also
update the matching `examples/*` app so they stay in sync (they're kept as
parallel dogfood copies).

## Code style

- **Biome** (double quotes, 2-space indent, semicolons, trailing commas).
- **TypeScript strict** — `strict`, `noUncheckedIndexedAccess`,
`exactOptionalPropertyTypes`, `verbatimModuleSyntax` (type-only imports must
use `import type`).
- No `any`. If a type is painful, cast narrowly with a comment explaining why.
- All packages are `"type": "module"`.

## Testing

Tests use `bun:test`. Fixtures are created in `beforeAll` and cleaned up in
`afterAll` under `__fixtures__/`. Run one file with:

```sh
bun test packages/core/src/router.test.ts
```

## Conventions & gotchas

- **`src/x-routes.ts` and `.x/`** are generated — never edit them by hand.
- **Env isolation**: never read a non-`THEXJS_PUBLIC_` env var in client code;
the build fails if you do.
- **postinstall** builds all packages; if it fails, run `bun run build:packages`.

## Code of conduct

Be respectful. This project follows the [Contributor Covenant][covenant] — see
`CODE_OF_CONDUCT.md`.

## Questions

Open a discussion or an issue. For security issues, see `SECURITY.md` — do not
file a public issue.

[covenant]: https://www.contributor-covenant.org/
Loading
Loading