129 lines
2.7 KiB
Markdown
129 lines
2.7 KiB
Markdown
# Network App API
|
|
|
|
Backend API for The Network App — an AI-powered CRM for wealth management advisors.
|
|
|
|
## Stack
|
|
|
|
- **Runtime:** Bun
|
|
- **Framework:** Elysia
|
|
- **Database:** PostgreSQL + Drizzle ORM
|
|
- **Auth:** BetterAuth
|
|
- **AI:** LangChain.js (Anthropic Claude)
|
|
- **Email:** Resend
|
|
|
|
## Quick Start
|
|
|
|
### Prerequisites
|
|
|
|
- [Bun](https://bun.sh/) v1.0+
|
|
- PostgreSQL 15+
|
|
|
|
### Setup
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
bun install
|
|
```
|
|
|
|
2. Copy environment file:
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
3. Configure `.env` with your values (database, API keys, etc.)
|
|
|
|
4. Push database schema:
|
|
```bash
|
|
bun run db:push
|
|
```
|
|
|
|
5. Start development server:
|
|
```bash
|
|
bun run dev
|
|
```
|
|
|
|
API runs at `http://localhost:3000`
|
|
|
|
## API Endpoints
|
|
|
|
### Auth (BetterAuth)
|
|
- `POST /api/auth/sign-up` — Register
|
|
- `POST /api/auth/sign-in/email` — Login
|
|
- `POST /api/auth/sign-out` — Logout
|
|
- `GET /api/auth/session` — Get current session
|
|
|
|
### Clients
|
|
- `GET /api/clients` — List clients
|
|
- `GET /api/clients/:id` — Get client
|
|
- `POST /api/clients` — Create client
|
|
- `PUT /api/clients/:id` — Update client
|
|
- `DELETE /api/clients/:id` — Delete client
|
|
- `POST /api/clients/:id/contacted` — Mark as contacted
|
|
|
|
### Emails
|
|
- `POST /api/emails/generate` — Generate AI email
|
|
- `POST /api/emails/generate-birthday` — Generate birthday message
|
|
- `GET /api/emails` — List emails
|
|
- `GET /api/emails/:id` — Get email
|
|
- `PUT /api/emails/:id` — Edit draft
|
|
- `POST /api/emails/:id/send` — Send email
|
|
- `DELETE /api/emails/:id` — Delete draft
|
|
|
|
### Events
|
|
- `GET /api/events` — List events
|
|
- `GET /api/events/:id` — Get event
|
|
- `POST /api/events` — Create event
|
|
- `PUT /api/events/:id` — Update event
|
|
- `DELETE /api/events/:id` — Delete event
|
|
- `POST /api/events/sync/:clientId` — Sync client birthdays/anniversaries
|
|
|
|
## Database
|
|
|
|
### Generate migrations
|
|
```bash
|
|
bun run db:generate
|
|
```
|
|
|
|
### Apply migrations
|
|
```bash
|
|
bun run db:migrate
|
|
```
|
|
|
|
### Push schema (development)
|
|
```bash
|
|
bun run db:push
|
|
```
|
|
|
|
### Open Drizzle Studio
|
|
```bash
|
|
bun run db:studio
|
|
```
|
|
|
|
## Docker
|
|
|
|
```bash
|
|
docker build -t network-app-api .
|
|
docker run -p 3000:3000 --env-file .env network-app-api
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
src/
|
|
├── index.ts # Entry point
|
|
├── routes/
|
|
│ ├── clients.ts # Client CRUD
|
|
│ ├── emails.ts # AI email generation
|
|
│ └── events.ts # Event tracking
|
|
├── services/
|
|
│ ├── ai.ts # LangChain integration
|
|
│ └── email.ts # Resend integration
|
|
├── db/
|
|
│ ├── schema.ts # Drizzle schema
|
|
│ └── index.ts # DB connection
|
|
├── lib/
|
|
│ └── auth.ts # BetterAuth config
|
|
└── types/
|
|
└── index.ts # TypeScript types
|
|
```
|