|
1 | 1 | # Elephant |
2 | | -Elephant – a privacy-first, open-source messenger. |
| 2 | +Elephant – a privacy-first, open-source messaging application made with Go and Flutter. Elephant supports secure authentication, user discovery, and real-time chat over WebSocket, with all communication TLS-protected between client and server. |
| 3 | + |
| 4 | +## Quick Start (Docker/Podman) |
| 5 | + |
| 6 | +The fastest way to run Elephant is by pulling the published image — no Go toolchain required. |
| 7 | + |
| 8 | +```bash |
| 9 | +# Log in to GitHub Container Registry |
| 10 | +docker login ghcr.io -u YOUR_GITHUB_USERNAME |
| 11 | +# or: podman login ghcr.io -u YOUR_GITHUB_USERNAME |
| 12 | + |
| 13 | +# Clone the repo for the compose file and .env template |
| 14 | +git clone https://github.com/commandlinecoding/elephant.git |
| 15 | +cd elephant |
| 16 | + |
| 17 | +# Copy and fill in environment variables |
| 18 | +cp .env.example .env |
| 19 | + |
| 20 | +# Start the stack |
| 21 | +docker compose up |
| 22 | +# or: podman-compose up |
| 23 | +``` |
| 24 | +Once running, verify the server is healthy: |
| 25 | + |
| 26 | +```bash |
| 27 | +curl http://localhost:8080/api/health |
| 28 | +``` |
| 29 | + |
| 30 | +You should see: |
| 31 | + |
| 32 | +```json |
| 33 | +{"success":true,"data":{"postgres":"up","timestamp":"..."}} |
| 34 | +``` |
| 35 | + |
| 36 | + ## Tech Stack |
| 37 | + |
| 38 | +| Layer | Technology | |
| 39 | +|---|---| |
| 40 | +| Backend | Go (chi, pgx, gorilla/websocket, golang-jwt, argon2) | |
| 41 | +| Mobile | Flutter (http, web_socket_channel, provider, sqflite) | |
| 42 | +| Database | PostgreSQL 16 | |
| 43 | +| CI/CD | GitHub Actions, Docker Compose, GHCR | |
| 44 | + |
| 45 | +## Local Development Setup |
| 46 | + |
| 47 | +If you're contributing to the backend and want to build from source instead of pulling the published image, use the dev compose override: |
| 48 | + |
| 49 | +```bash |
| 50 | +docker compose -f compose.yaml -f compose.dev.yaml up |
| 51 | +``` |
| 52 | + |
| 53 | +This builds the `server` image from `server/Dockerfile` on every run instead of pulling from GHCR, so your local changes are reflected immediately. |
| 54 | + |
| 55 | +### Running the backend without Docker |
| 56 | + |
| 57 | +```bash |
| 58 | +cd server |
| 59 | +go mod download |
| 60 | +go run main.go |
| 61 | +``` |
| 62 | + |
| 63 | +Make sure PostgreSQL is running and reachable using the values in your `.env` file (`POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`). |
| 64 | + |
| 65 | +### Running database migrations |
| 66 | + |
| 67 | +```bash |
| 68 | +cd server |
| 69 | +psql "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB" \ |
| 70 | + -f migrations/001_create_users_up.sql \ |
| 71 | + -f migrations/002_create_refresh_tokens_up.sql \ |
| 72 | + -f migrations/003_add_search_indexes_up.sql \ |
| 73 | + -f migrations/004_create_message_up.sql |
| 74 | +``` |
| 75 | + |
| 76 | +### Running the mobile app |
| 77 | + |
| 78 | +```bash |
| 79 | +cd mobile |
| 80 | +flutter pub get |
| 81 | +flutter run |
| 82 | +``` |
| 83 | + |
| 84 | +## Environment Variables |
| 85 | + |
| 86 | +| Variable | Description | Default | |
| 87 | +|---|---|---| |
| 88 | +| `HOST` | Server bind address | `127.0.0.1` | |
| 89 | +| `PORT` | Server port | `3000` | |
| 90 | +| `POSTGRES_USER` | Database username | `postgres` | |
| 91 | +| `POSTGRES_PASSWORD` | Database password | — | |
| 92 | +| `POSTGRES_DB` | Database name | `myapi_db` | |
| 93 | +| `POSTGRES_PORT` | Database port | `5432` | |
| 94 | +| `POSTGRES_HOST` | Database host | `localhost` | |
| 95 | +| `JWT_SECRET` | Secret key for signing JWTs | — | |
| 96 | +| `ARGON_MEMORY` | Argon2id memory cost (KB) | `65536` | |
| 97 | +| `ARGON_ITERATIONS` | Argon2id iteration count | `3` | |
| 98 | +| `ARGON_PARALLELISM` | Argon2id parallelism degree | `2` | |
| 99 | + |
| 100 | +See `.env.example` for a starting template. |
| 101 | + |
| 102 | + |
| 103 | +## API |
| 104 | + |
| 105 | +Checkout the [API document](docs/API_CONTRACTS.md) |
| 106 | + |
| 107 | +### Registration note |
| 108 | + |
| 109 | +Usernames are normalized to lowercase and assigned a random 4-digit discriminator on registration to avoid collisions, e.g. registering as `abc` may result in the stored username `abc.4821`. Use the full discriminated username returned in the registration response when logging in. |
| 110 | + |
| 111 | +## Testing |
| 112 | + |
| 113 | +Run the full backend test suite (unit + integration): |
| 114 | + |
| 115 | +```bash |
| 116 | +cd server |
| 117 | +go vet ./... |
| 118 | +go test -v ./... |
| 119 | +``` |
| 120 | + |
| 121 | +Integration tests under [server/tests/](server/tests/) expect a running server and database. Start the stack first, then run: |
| 122 | + |
| 123 | +```bash |
| 124 | +HOST=localhost PORT=8080 go test -v ./tests/... |
| 125 | +``` |
| 126 | + |
| 127 | +### CI/CD |
| 128 | + |
| 129 | +Tests, `go vet`, and `staticcheck` run automatically on every push and pull request via GitHub Actions (`.github/workflows/`). Docker images are built and published to GHCR via manual `workflow_dispatch` or on tagged pushes. |
| 130 | + |
| 131 | +## Project Structure |
| 132 | + |
| 133 | +``` |
| 134 | +elephant/ |
| 135 | +├── .github/ # GitHub Actions workflows |
| 136 | +├── docs/ # Project documentation |
| 137 | +├── mobile/ # Flutter client |
| 138 | +│ ├── android/ |
| 139 | +│ ├── ios/ |
| 140 | +│ ├── lib/ |
| 141 | +│ ├── assets/ |
| 142 | +│ ├── pubspec.yaml |
| 143 | +│ └── README.md |
| 144 | +├── server/ # Go backend |
| 145 | +│ ├── config/ # DB, JWT, Argon2, CORS configuration |
| 146 | +│ ├── controllers/ # HTTP handlers |
| 147 | +│ ├── env/ # Environment variable loading |
| 148 | +│ ├── errors/ # Sentinel error definitions |
| 149 | +│ ├── middlewares/ # Auth, CORS, logging, rate limiting |
| 150 | +│ ├── migrations/ # SQL migration files |
| 151 | +│ ├── models/ # Data models |
| 152 | +│ ├── repository/ # Database access layer |
| 153 | +│ ├── routes/ # Route definitions |
| 154 | +│ ├── services/ # Business logic (auth, users, JWT, WebSocket hub) |
| 155 | +│ ├── tests/ # Integration tests |
| 156 | +│ └── Dockerfile |
| 157 | +├── compose.yaml # Default: pulls published image |
| 158 | +├── compose.dev.yaml # Override: builds server from source |
| 159 | +├── .env.example # Environment variable template |
| 160 | +└── LICENSE |
| 161 | +``` |
| 162 | + |
| 163 | +## License |
| 164 | + |
| 165 | +See [LICENSE](LICENSE) for details. |
0 commit comments