|
| 1 | +# Independent Vercel Server Implementation |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Successfully created an independent `apps/server` package that separates the Vercel backend deployment from the console frontend, following the pattern from `objectstack-ai/framework/apps/server`. |
| 6 | + |
| 7 | +## What Was Created |
| 8 | + |
| 9 | +### Core Files |
| 10 | + |
| 11 | +1. **package.json** - Dependencies and scripts for the server |
| 12 | +2. **objectstack.config.ts** - Server configuration with plugin loading |
| 13 | +3. **server/index.ts** - Serverless function entrypoint with Hono adapter |
| 14 | +4. **api/[[...route]].js** - Vercel catch-all API handler |
| 15 | + |
| 16 | +### Build Infrastructure |
| 17 | + |
| 18 | +5. **scripts/build-vercel.sh** - Build script for Vercel deployment |
| 19 | +6. **scripts/bundle-api.mjs** - ESBuild bundler configuration |
| 20 | +7. **vercel.json** - Vercel deployment configuration |
| 21 | +8. **tsconfig.json** - TypeScript configuration |
| 22 | + |
| 23 | +### Supporting Files |
| 24 | + |
| 25 | +9. **.env.example** - Environment variable template |
| 26 | +10. **.gitignore** - Git ignore rules |
| 27 | +11. **.vercelignore** - Vercel ignore rules |
| 28 | +12. **README.md** - Usage and API documentation |
| 29 | +13. **DEPLOYMENT.md** - Detailed deployment guide |
| 30 | + |
| 31 | +## Architecture |
| 32 | + |
| 33 | +``` |
| 34 | +apps/server/ |
| 35 | +├── api/ |
| 36 | +│ ├── [[...route]].js # Vercel entry (committed) |
| 37 | +│ └── _handler.js # Bundled handler (generated) |
| 38 | +├── server/ |
| 39 | +│ └── index.ts # Server implementation |
| 40 | +├── scripts/ |
| 41 | +│ ├── build-vercel.sh # Build orchestration |
| 42 | +│ └── bundle-api.mjs # API bundler |
| 43 | +├── objectstack.config.ts # Kernel configuration |
| 44 | +└── vercel.json # Vercel config |
| 45 | +``` |
| 46 | + |
| 47 | +## Key Features |
| 48 | + |
| 49 | +### Plugin Loading Order |
| 50 | + |
| 51 | +Critical for proper initialization: |
| 52 | + |
| 53 | +1. **MemoryI18nPlugin** - Registers i18n service early |
| 54 | +2. **ObjectQLPlugin** - Provides query engine |
| 55 | +3. **DriverPlugin** (InMemoryDriver) - Database driver |
| 56 | +4. **AppPlugins** - CRM, Todo, Kitchen Sink examples |
| 57 | +5. **SetupPlugin** - Must precede AuthPlugin |
| 58 | +6. **AuthPlugin** - Authentication (uses setupNav) |
| 59 | +7. **ConsolePlugin** - Serves frontend UI |
| 60 | + |
| 61 | +### Build Process |
| 62 | + |
| 63 | +1. Builds console with `VITE_RUNTIME_MODE=server` |
| 64 | +2. Bundles `server/index.ts` → `api/_handler.js` with esbuild |
| 65 | +3. Copies console dist to `public/` for static serving |
| 66 | + |
| 67 | +### Runtime Flow |
| 68 | + |
| 69 | +1. Vercel calls `api/[[...route]].js` |
| 70 | +2. Delegates to bundled `api/_handler.js` |
| 71 | +3. Kernel boots on cold start (cached for warm requests) |
| 72 | +4. Hono app handles `/api/v1/*` requests |
| 73 | +5. Static files served from `public/` |
| 74 | + |
| 75 | +## Environment Variables |
| 76 | + |
| 77 | +**Required:** |
| 78 | +- `AUTH_SECRET` - Min 32 characters for production |
| 79 | + |
| 80 | +**Optional:** |
| 81 | +- `NEXT_PUBLIC_BASE_URL` - Auto-detected from VERCEL_URL |
| 82 | + |
| 83 | +## Deployment |
| 84 | + |
| 85 | +### Quick Deploy |
| 86 | + |
| 87 | +```bash |
| 88 | +cd apps/server |
| 89 | +vercel |
| 90 | +``` |
| 91 | + |
| 92 | +### Set Environment Variables |
| 93 | + |
| 94 | +```bash |
| 95 | +vercel env add AUTH_SECRET production |
| 96 | +``` |
| 97 | + |
| 98 | +### Production Deploy |
| 99 | + |
| 100 | +```bash |
| 101 | +vercel --prod |
| 102 | +``` |
| 103 | + |
| 104 | +## API Endpoints |
| 105 | + |
| 106 | +- **Discovery:** `/api/v1/discovery` |
| 107 | +- **Metadata:** `/api/v1/meta/objects` |
| 108 | +- **Data CRUD:** `/api/v1/data/:object` |
| 109 | +- **Console UI:** `/` (root) |
| 110 | + |
| 111 | +## Testing Locally |
| 112 | + |
| 113 | +```bash |
| 114 | +# Install dependencies |
| 115 | +pnpm install |
| 116 | + |
| 117 | +# Run dev server |
| 118 | +cd apps/server |
| 119 | +pnpm dev |
| 120 | + |
| 121 | +# Test API |
| 122 | +curl http://localhost:3000/api/v1/discovery |
| 123 | +``` |
| 124 | + |
| 125 | +## Differences from Framework Reference |
| 126 | + |
| 127 | +1. Serves ObjectUI Console (not separate Studio app) |
| 128 | +2. Console built from `apps/console` with server mode |
| 129 | +3. Uses `@object-ui/*` example apps instead of `@example/*` |
| 130 | +4. Imports ConsolePlugin from `@object-ui/console` package |
| 131 | +5. Same in-memory driver pattern for development |
| 132 | + |
| 133 | +## Next Steps |
| 134 | + |
| 135 | +For production deployment: |
| 136 | + |
| 137 | +1. Replace InMemoryDriver with persistent database (Turso, PostgreSQL) |
| 138 | +2. Configure environment variables in Vercel |
| 139 | +3. Set up monitoring and logging |
| 140 | +4. Enable Vercel Analytics |
| 141 | +5. Configure custom domain |
| 142 | + |
| 143 | +## Files Changed |
| 144 | + |
| 145 | +- Created `apps/server/` directory with 13 files |
| 146 | +- Updated `pnpm-lock.yaml` for new dependencies |
| 147 | + |
| 148 | +## Commit History |
| 149 | + |
| 150 | +1. `9928b2a` - Initial server app creation |
| 151 | +2. `2940933` - Fix TypeScript configuration and type errors |
| 152 | + |
| 153 | +## Status |
| 154 | + |
| 155 | +✅ **Complete** - Server app is ready for deployment to Vercel |
0 commit comments