Architecture Overview

Renewa One is a monorepo application deployed as a single Docker container running nginx, a Bun+Hono backend, and serving React static assets.

System Diagram

                        ┌─────────────────────────────┐
                        │         Fly.io              │
                        │                             │
  Browser ──────────────┤► nginx (:80)                │
                        │   ├── /api/*  ──► backend   │
                        │   │              (:3000)    │
                        │   └── /*      ──► static    │
                        │                  (React)    │
                        │                             │
                        │   backend ──────────────────┤──► PostgreSQL (Fly.io managed)
                        │              │              │        via PgBouncer
                        │              └──────────────┤──► Upstash Redis
                        └─────────────────────────────┘
                                       │
                              External Services:
                        HubSpot, DocuSign, Azure Entra,
                        Dataverse, Resend, MessageBird,
                        Sentry, Tigris (S3)

Request Flow

  1. All traffic enters through nginx on port 80
  2. Requests to /api/* are proxied to the Hono backend on port 3000
  3. All other requests serve the React SPA static bundle
  4. Backend connects to PostgreSQL (via PgBouncer) and Redis (via Upstash)

See Backend Middleware for the middleware stack processing order: security → CORS → sanitization → rate limiting → auth → routes.

Monorepo Structure

renewa-one/
├── backend/          # Bun + Hono API server
│   ├── src/
│   │   ├── routes/       # 164 route files (OpenAPI)
│   │   ├── services/     # 98 service files
│   │   ├── lib/          # 126 utility modules
│   │   ├── middleware/   # 10 middleware modules
│   │   ├── interfaces/   # 48 interface definitions
│   │   └── db/           # Schema, seeds, migrations
│   └── atlas/            # Atlas migration SQL files
├── frontend/         # React 19 + Vite SPA
│   ├── src/
│   │   ├── pages/        # 96 page components
│   │   ├── components/   # 623+ components
│   │   ├── hooks/        # 43 custom hooks
│   │   └── lib/          # API clients, queries, utils
│   └── public/
├── shared/           # Cross-cutting types and constants
├── scripts/          # Developer tooling
├── docker/           # Docker configuration
├── .github/          # 20 GitHub Actions workflows
└── infrastructure/   # Terraform / IaC

Key Architectural Decisions

DecisionChoiceRationale
RuntimeBunFast startup, native TypeScript, built-in test runner
FrameworkHonoLightweight, OpenAPI support, middleware-based
ORMDrizzleType-safe, thin abstraction, PostgreSQL-native
MigrationsAtlasDeclarative schema diffing, integrity checksums
FrontendReact 19 + ViteIndustry standard, fast HMR, large ecosystem
StateReact Query + ZustandServer state separated from client state
StylingTailwindCSS 4 + Shadcn/uiUtility-first, accessible component primitives
DeploymentFly.ioEdge deployment, managed Postgres, simple scaling

Configuration

FilePurpose
fly.development.tomlFly.io dev environment config
fly.staging.tomlFly.io staging config
fly.production.tomlFly.io production config
nginx.conf / nginx.dev.confnginx reverse proxy config
docker-compose.ymlLocal development stack
DockerfileMulti-stage production build
tsconfig.base.jsonShared TypeScript config