Prerequisites
Before you begin, ensure you have the following installed:Go 1.24+
Download from golang.org
PostgreSQL 14+
Download from postgresql.org
Git
Download from git-scm.com
CompanyFlow requires Go version 1.24.0 or higher and PostgreSQL version 14 or higher.
Installation Steps
Install Dependencies
Download all required Go modules:This will install all dependencies including:
github.com/gorilla/mux- HTTP routergithub.com/jackc/pgx/v5- PostgreSQL drivergithub.com/golang-jwt/jwt/v5- JWT authenticationgithub.com/swaggo/swag- Swagger documentationgolang.org/x/crypto- Password hashing
Set Up Environment Variables
Create a
.env file in the root directory with the following configuration:Environment Variables Reference
| Variable | Description | Required | Default |
|---|---|---|---|
DB_HOST | PostgreSQL host address | Yes | - |
DB_PORT | PostgreSQL port | Yes | - |
DB_USER | Database username | Yes | - |
DB_PASSWORD | Database password | Yes | - |
DB_NAME | Database name | Yes | - |
DB_SSLMODE | SSL mode (disable/require/verify-full) | Yes | - |
PORT | Server port | No | 8080 |
CORS_ORIGIN | Allowed CORS origin | No | http://localhost:3000 |
JWT_SECRET | Secret key for JWT signing | Yes | - |
Run the Application
Start the CompanyFlow server:On startup, CompanyFlow will:
- Connect to the PostgreSQL database
- Automatically run database migrations
- Start the HTTP server
Database Migrations
CompanyFlow uses an automatic migration system that runs on startup.How Migrations Work
- Migration files are stored in
database/migration/as SQL files - Files are executed in alphabetical order based on their prefix (
000_,001_, etc.) - The system tracks executed migrations in a
schema_migrationstable - Each migration runs only once, even if you restart the server
Migrations are automatically executed when you run
go run main.go. You don’t need to run them manually.Migration File Structure
Migration files follow this naming pattern:Building for Production
To build a production-ready binary:companyflow that you can deploy to your server.
Running the Production Binary
Running Tests
CompanyFlow includes a comprehensive test suite. To run tests:Test Database Configuration
For running tests, configure a separate test database using theTEST_DATABASE_URL environment variable or use the same DB_* variables with a different database name.
Docker Installation (Optional)
If you prefer using Docker, you can run PostgreSQL in a container:Troubleshooting
Connection Failed
- Verify PostgreSQL is running:
systemctl status postgresql(Linux) or check Activity Monitor (macOS) - Check database credentials in
.envfile - Ensure the database exists:
psql -l - Verify PostgreSQL is accepting connections on the specified port
Migration Failed
- Drop and recreate the database for a clean slate
- Check the
schema_migrationstable for inconsistencies - Ensure migration files are properly numbered
Port Already in Use
- Change the
PORTin your.envfile - Find and stop the process using port 8080:
lsof -ti:8080 | xargs kill -9
Missing JWT Secret
- Add
JWT_SECRETto your.envfile with a secure random string
Next Steps
Now that CompanyFlow is installed and running, you’re ready to start using the API!Quick Start
Make your first API calls and learn the basics
API Reference
Explore all available endpoints and schemas
Authentication
Learn about JWT authentication and security
Multi-Tenant Setup
Configure multiple companies in your instance