Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Project Structure

This page documents the directory layout and key files in the Aero2 codebase.

Directory Tree

aero2/
+-- src/
|   +-- backend/
|   |   +-- index.ts              # Main Hono app, route mounting, global middleware
|   |   +-- rp.ts                 # Relying Party routes (external IdP OAuth flow)
|   |   +-- op.ts                 # OIDC Provider routes (authorize, token, userinfo, revoke)
|   |   +-- idp.ts                # Identity Provider CRUD API
|   |   +-- clients.ts            # OAuth client CRUD API
|   |   +-- roles.ts              # Role and permission management API
|   |   +-- jwks.ts               # JWKS Durable Object (key generation, rotation, signing)
|   |   +-- users.ts              # User management API
|   |   +-- sessions.ts           # Session management API
|   |   +-- audit.ts              # Audit log API
|   |   +-- middleware/
|   |   |   +-- auth.ts           # Authentication (JWT verification) and authorization (RBAC)
|   |   |   +-- ratelimit.ts      # Rate limiting middleware
|   |   +-- utils/
|   |       +-- token.ts          # JWT signing and verification utilities
|   |       +-- crypto.ts         # PBKDF2, AES-256-GCM, HMAC utilities
|   +-- frontend/
|       +-- App.tsx               # Root React component
|       +-- routes.tsx            # React Router configuration
|       +-- pages/                # React page components
|       |   +-- Login.tsx         # Login page
|       |   +-- Dashboard.tsx     # Main dashboard
|       |   +-- Admin*.tsx        # Admin management pages
|       |   +-- OAuthCallback.tsx # OAuth callback handler
|       +-- contexts/
|       |   +-- AuthContext.tsx    # Authentication context provider
|       +-- components/
|           +-- ui/               # Reusable UI components (Button, Card, Input, etc.)
+-- migrations/
|   +-- 0001_initial_schema.sql   # Initial database schema
+-- tests/
|   +-- *.test.ts                 # Vitest unit and integration tests
+-- docs/
|   +-- pages/                    # Documentation site (Nextra/MDX)
+-- wrangler.json                 # Cloudflare Worker configuration
+-- package.json                  # Dependencies and scripts
+-- tsconfig.json                 # TypeScript configuration
+-- vitest.config.ts              # Vitest configuration
+-- biome.json                    # Biome linter configuration
+-- .dev.vars                     # Local development secrets (gitignored)
+-- .github/
    +-- workflows/                # GitHub Actions CI/CD

Key Files Explained

Backend

FilePurpose
src/backend/index.tsEntry point. Creates the Hono app, mounts all middleware (security headers, CSRF, CORS, rate limiting), mounts route sub-apps (OP, RP, API), and exports the Worker default handler plus the JWKS Durable Object class.
src/backend/op.tsOIDC Provider implementation. Handles /oauth2/authorize, /oauth2/token, /oauth2/userinfo, /oauth2/revoke, /oauth2/jwks.json, and /.well-known/openid-configuration.
src/backend/rp.tsRelying Party implementation. Handles /rp/authorize/:idp (start external OAuth flow) and /rp/callback/:idp (handle callback, create/link user, create session).
src/backend/idp.tsIdentity Provider CRUD. Endpoints for listing, creating, updating, and deleting IdP configurations.
src/backend/clients.tsOAuth Client CRUD. Endpoints for managing OAuth clients (create with hashed secret, list, update, delete).
src/backend/roles.tsRBAC management. Endpoints for roles, permissions, role-permission mappings, and user-role assignments.
src/backend/users.tsUser management. List users with pagination/filtering, get user details, update user, disable/enable user.
src/backend/sessions.tsSession management. List active sessions, revoke sessions, cleanup expired sessions.
src/backend/audit.tsAudit log. Log security events, query audit logs with filtering and pagination.
src/backend/jwks.tsJWKS Durable Object. Manages RSA key pairs for JWT signing. Handles key generation, rotation (every 24 hours), bounded storage (MAX_KEYS=3), and exposes the JWKS endpoint.
src/backend/middleware/auth.tsAuthentication middleware that verifies JWTs (session or bearer tokens) and authorization middleware that checks RBAC permissions.
src/backend/utils/token.tsJWT utilities: sign tokens via the Durable Object, verify tokens against JWKS, build claims objects.
src/backend/utils/crypto.tsCryptographic utilities: PBKDF2 password hashing, AES-256-GCM encryption/decryption, HMAC hashing, constant-time comparison.

Frontend

FilePurpose
src/frontend/App.tsxRoot component. Sets up AuthContext provider and React Router.
src/frontend/routes.tsxRoute definitions. Maps URL paths to page components, applies auth guards.
src/frontend/contexts/AuthContext.tsxAuthentication context. Provides user, isAuthenticated, isLoading, signOut() to all components.
src/frontend/pages/Page components for login, dashboard, admin panels, profile, etc.
src/frontend/components/ui/Reusable UI components: Button, Card, Input, Modal, Spinner, Toast, etc.

Configuration

FilePurpose
wrangler.jsonCloudflare Worker config: bindings (D1, Durable Objects), routes, environment variables, compatibility settings.
vitest.config.tsTest config using @cloudflare/vitest-pool-workers for Workers-compatible test execution.
biome.jsonLinting and formatting rules for TypeScript and CSS.

Where to Add New Features

What you are addingWhere to put it
New API endpointCreate a Hono sub-app in src/backend/ and mount it in index.ts
New middlewareAdd to src/backend/middleware/ and apply in index.ts
New utility functionAdd to src/backend/utils/
New database tableCreate a migration file in migrations/
New React pageAdd to src/frontend/pages/ and register in routes.tsx
New UI componentAdd to src/frontend/components/ui/
New testAdd to tests/ following existing naming conventions
New documentationAdd MDX file to docs/pages/