1f7366fb1e674dcdd6e8b130fa1578f87a4235db
Fiscal Clone 2.0
Ground-up rebuild of a fiscal.ai-style platform with:
- Better Auth for session-backed auth
- Next.js frontend
- high-throughput API service
- durable long-running task worker
- OpenClaw/ZeroClaw AI integration
- futuristic terminal UI language
Feature Coverage
- Authentication (email/password via Better Auth)
- Watchlist management
- SEC filings ingestion (10-K, 10-Q, 8-K)
- Filing analysis jobs (async AI pipeline)
- Portfolio holdings and summary analytics
- Price refresh jobs (async)
- AI portfolio insight jobs (async)
- Task tracking endpoint and UI polling
Architecture
frontend/: Next.js App Router UIbackend/: Elysia API + Better Auth + domain routesbackend/src/worker.ts: durable queue workerdocs/REBUILD_DECISIONS.md: one-by-one architecture decisions
Runtime topology:
- Frontend web app
- Backend API
- Worker process for long tasks
- PostgreSQL
Local Setup
cp .env.example .env
1) Backend
cd backend
bun install
bun run db:migrate
bun run dev
2) Worker (new terminal)
cd backend
bun run dev:worker
3) Frontend (new terminal)
cd frontend
npm install
npm run dev
Frontend: http://localhost:3000
Backend: http://localhost:3001
Swagger: http://localhost:3001/swagger
Docker Compose
docker compose up --build
This starts: postgres, backend, worker, frontend.
Coolify
Deploy using the root compose file and configure separate public domains for:
frontendon port3000backendon port3001
Use the full guide in COOLIFY.md.
Critical variables for Coolify:
FRONTEND_URL= frontend public URLBETTER_AUTH_BASE_URL= backend public URLNEXT_PUBLIC_API_URL= backend public URL (build-time in frontend)
Core API Surface
Auth:
ALL /api/auth/*(Better Auth handler)GET /api/me
Watchlist:
GET /api/watchlistPOST /api/watchlistDELETE /api/watchlist/:id
Portfolio:
GET /api/portfolio/holdingsPOST /api/portfolio/holdingsPATCH /api/portfolio/holdings/:idDELETE /api/portfolio/holdings/:idGET /api/portfolio/summaryPOST /api/portfolio/refresh-prices(queues task)POST /api/portfolio/insights/generate(queues task)GET /api/portfolio/insights/latest
Filings:
GET /api/filings?ticker=&limit=GET /api/filings/:accessionNumberPOST /api/filings/sync(queues task)POST /api/filings/:accessionNumber/analyze(queues task)
Task tracking:
GET /api/tasksGET /api/tasks/:taskId
OpenClaw / ZeroClaw Integration
Set these in .env:
OPENCLAW_BASE_URL=http://localhost:4000
OPENCLAW_API_KEY=...
OPENCLAW_MODEL=zeroclaw
The backend expects an OpenAI-compatible /v1/chat/completions endpoint.
Decision Log
See docs/REBUILD_DECISIONS.md for the detailed rationale and tradeoffs behind each major design choice.
Description
Languages
TypeScript
72.7%
Rust
26.8%
CSS
0.3%
Dockerfile
0.1%