Skip to main content
This guide will help you install and configure CompanyFlow on your development machine or production server.

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

1

Clone the Repository

Clone the CompanyFlow repository from GitHub:
2

Install Dependencies

Download all required Go modules:
This will install all dependencies including:
  • github.com/gorilla/mux - HTTP router
  • github.com/jackc/pgx/v5 - PostgreSQL driver
  • github.com/golang-jwt/jwt/v5 - JWT authentication
  • github.com/swaggo/swag - Swagger documentation
  • golang.org/x/crypto - Password hashing
3

Configure PostgreSQL Database

Create a new PostgreSQL database for CompanyFlow:
You can use any database name you prefer. Just make sure to update the DB_NAME in your environment configuration.
4

Set Up Environment Variables

Create a .env file in the root directory with the following configuration:
Security Best Practices:
  • Use a strong, randomly generated JWT secret (minimum 32 characters)
  • Never commit the .env file to version control
  • In production, use environment variables instead of a .env file
  • Enable SSL mode (DB_SSLMODE=require) in production

Environment Variables Reference

5

Run the Application

Start the CompanyFlow server:
On startup, CompanyFlow will:
  1. Connect to the PostgreSQL database
  2. Automatically run database migrations
  3. Start the HTTP server
You should see output similar to:
6

Verify Installation

Test that the server is running correctly:
You should receive an ok response.Then open your browser and navigate to the Swagger documentation:

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_migrations table
  • 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:
This creates an executable binary called companyflow that you can deploy to your server.

Running the Production Binary

Production Checklist:
  • Use DB_SSLMODE=require for encrypted database connections
  • Set a strong, unique JWT secret
  • Configure CORS_ORIGIN to match your frontend domain
  • Use environment variables, not a .env file
  • Run behind a reverse proxy (nginx, Caddy, etc.)
  • Set up monitoring and logging

Running Tests

CompanyFlow includes a comprehensive test suite. To run tests:

Test Database Configuration

For running tests, configure a separate test database using the TEST_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

Solutions:
  • Verify PostgreSQL is running: systemctl status postgresql (Linux) or check Activity Monitor (macOS)
  • Check database credentials in .env file
  • Ensure the database exists: psql -l
  • Verify PostgreSQL is accepting connections on the specified port

Migration Failed

Solutions:
  • Drop and recreate the database for a clean slate
  • Check the schema_migrations table for inconsistencies
  • Ensure migration files are properly numbered

Port Already in Use

Solutions:
  • Change the PORT in your .env file
  • Find and stop the process using port 8080: lsof -ti:8080 | xargs kill -9

Missing JWT Secret

Solution:
  • Add JWT_SECRET to your .env file 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