replit-reference-architecture
Implement Replit reference architecture with best-practice project layout. Use when designing new Replit integrations, reviewing project structure, or establishing architecture standards for Replit applications. Trigger with phrases like "replit architecture", "replit best practices", "replit project structure", "how to organize replit", "replit layout".
- License 许可
- MIT
- 最近更新
- 2026-03-20
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- replit-reference-architecture
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Implement Replit reference architecture with best-practice project layout. Use when designing new Replit integrations, reviewing project structure, or establishing architecture standards for Replit applications. Trigger with phrases like "replit architecture", "replit best practices", "replit project structure", "how to organize replit", "replit layout".
- allowed-tools
- Read, Grep
- compatible-with
- claude-code, codex, openclaw
03 SKILL.md 正文
Replit Reference Architecture
Overview
Production architecture for applications on Replit. Covers project structure for deployments, secrets management, database integration with Replit DB and PostgreSQL, and multi-environment configuration.
Prerequisites
- Replit account with deployment tier
- Understanding of
.replitandreplit.nix - Nix package manager basics
- PostgreSQL or Replit DB familiarity
Architecture Diagram
┌──────────────────────────────────────────────────────┐
│ Replit Workspace │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │
│ │ .replit │ │ replit │ │ Secrets │ │
│ │ (config) │ │ .nix │ │ (env vars) │ │
│ └──────────┘ └──────────┘ └──────────────────┘ │
├──────────────────────────────────────────────────────┤
│ Application │
│ ┌──────────────────────────────────────────────┐ │
│ │ Express/Fastify Server │ │
│ │ Routes │ Middleware │ WebSocket │ │
│ └──────────────────────┬───────────────────────┘ │
│ │ │
│ ┌──────────────────────┴───────────────────────┐ │
│ │ Data Layer │ │
│ │ Replit DB │ PostgreSQL │ Object Storage │ │
│ └──────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────┤
│ Deployment: Autoscale │ Reserved VM │ Static │
└──────────────────────────────────────────────────────┘
Instructions
Step 1: Project Structure
my-replit-app/
├── .replit # Run configuration
├── replit.nix # System dependencies
├── src/
│ ├── index.ts # Entry point
│ ├── routes/
│ │ ├── api.ts # API routes
│ │ └── health.ts # Health check
│ ├── services/
│ │ ├── database.ts # DB connection
│ │ └── cache.ts # Caching layer
│ └── middleware/
│ ├── auth.ts # Authentication
│ └── rateLimit.ts # Rate limiting
├── tests/
├── tsconfig.json
└── package.json
Step 2: Replit Configuration Files
# .replit
run = "npm start"
entrypoint = "src/index.ts"
[nix]
channel = "stable-24_05"
[env]
NODE_ENV = "production"
[deployment]
run = ["sh", "-c", "npm run build && npm start"]
build = ["sh", "-c", "npm ci && npm run build"]
deploymentTarget = "cloudrun"
[languages.typescript]
pattern = "**/*.ts"
# replit.nix
{ pkgs }: {
deps = [
pkgs.nodejs-20_x
pkgs.nodePackages.typescript
pkgs.postgresql
];
}
Step 3: Database Integration
// src/services/database.ts
import { Pool } from 'pg';
let pool: Pool | null = null;
export function getDB(): Pool {
if (!pool) {
pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
idleTimeoutMillis: 30000, # 30000: 30 seconds in ms
connectionTimeoutMillis: 5000, # 5000: 5 seconds in ms
});
}
return pool;
}
// Health check for database
export async function checkDBHealth(): Promise<boolean> {
try {
const result = await getDB().query('SELECT 1');
return result.rows.length > 0;
} catch {
return false;
}
}
Step 4: Application Entry Point
// src/index.ts
import express from 'express';
import { getDB, checkDBHealth } from './services/database';
const app = express();
app.use(express.json());
// Health endpoint (required for Replit deployments)
app.get('/health', async (req, res) => {
const dbOk = await checkDBHealth();
res.status(dbOk ? 200 : 503).json({ # 503: HTTP 200 OK
status: dbOk ? 'healthy' : 'degraded',
uptime: process.uptime(),
memory: process.memoryUsage().heapUsed,
});
});
app.get('/api/status', (req, res) => {
res.json({ version: process.env.npm_package_version });
});
const PORT = parseInt(process.env.PORT || '3000'); # 3000: 3 seconds in ms
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server running on port ${PORT}`);
});
Error Handling
| Issue | Cause | Solution |
|---|---|---|
| Cold start slow | Heavy imports at startup | Use lazy imports for non-critical modules |
| DB connection refused | PostgreSQL not started | Check Replit DB provisioning |
| Secrets undefined | Not set in Secrets tab | Configure in Replit workspace Secrets |
| Deploy fails | Build step error | Test build locally before deploying |
Examples
Quick Deployment Check
set -euo pipefail
# Test build locally before deploying
npm run build && npm start
# Verify health endpoint
curl http://localhost:3000/health # 3000: 3 seconds in ms
Resources
Output
- Configuration files or code changes applied to the project
- Validation report confirming correct implementation
- Summary of changes made and their rationale
04 同仓库更多 Skills
azure-apim-architecture
Analyzes and explains Azure API Management architecture decisions for enterprise API marketplace implementations using VNet Internal mode, Front Door, hybrid authentication, and multi-environment strategies. Use when discussing APIM component selection, network topology, cost optimization, or comparing alternatives like workspaces vs instances, VNet Internal vs External mode, or Front Door vs Application Gateway.
apiops-deployment
Guides deployment of Azure API Management infrastructure using Infrastructure as Code (Bicep/Terraform), CI/CD pipelines (GitHub Actions/Azure DevOps), and APIOps workflows. Use when deploying APIM, creating pipelines, or implementing dev→test→prod promotion strategies.
apim-policy-authoring
Creates production-ready Azure API Management policy XML for authentication (OAuth 2.0, JWT validation, subscription keys), rate limiting, CORS configuration, error handling, and API transformations. Use when implementing API security, access control, or request/response processing logic.
api-security-review
Reviews Azure API Management configurations for security vulnerabilities, OWASP API Security Top 10 compliance, VNet Internal mode validation, Private Link verification, and Azure Security Benchmark alignment. Use when performing security audits, pre-deployment validation, or compliance reviews.
jira-cli
Interact with Jira from the command line to create, list, view, edit, and transition issues, manage sprints and epics, and perform common Jira workflows. Use when the user asks about Jira tasks, tickets, issues, sprints, or needs to manage project work items.
calculator
Performs arbitrary-precision arithmetic calculations including addition, subtraction, multiplication, division, and exponents. Use when the user asks to calculate, compute, or evaluate math expressions, or when precise decimal arithmetic is needed to avoid floating-point errors.