- Go 1.18 or later
- Clone the repository
- Run
go mod downloadto download the dependencies - Run
go buildto build the binary - optionally pass
-o <binary_name>to specify the name of the binary - Run
./<binary_name>to start the server. - You might need to run
chmod +x <binary_name>to make the binary executable. - Alternatively, you can run
go run main.goto start the server
- The server will start on
port 8080by default, it can be changed by setting theSERVE_PORTenvironment variable. - If an environment variable
TLSis set totrue, the server will start with TLS enabled and will look for the following environment variables:CERT_PATH: The path to the certificate file, by default its set toinvoiceexchange.local.pemCERT_PRIVATE_KEY: The path to the key file, by default its set toinvoiceexchange.local-key.pem- The TLS port is set to
443by default, it can be changed by setting theTLS_PORTenvironment variable.
- By default, the server runs in
devmode, it can be changed by setting theENVIRONMENTenvironment variable toprod. - By default, the server starts looks for
POSTGRES_DSNenvironment variable to connect to the database. - In
local.yamltheENT-DRIVERenvironment variable is set tosqliteto use sqlite as the database driver. If theent-driverin the yaml or the environment variableENT_DRIVERis set topgx, the server will use postgres as the database driver. The sqlite uses postgres dialect so the database can be easily switched. - If the
ENT_DRIVERis set tosqlite, the server will not use thePOSTGRES_DSNenvironment variable to connect to the database. - The sqlite database starts with some preloaded data for testing purposes. The data is saved in a file called
local.dbin the root directory of the project. The file can be deleted to start with a fresh database. - The server uses
ent frameworkfor the database layer. The ent schema is defined inent/schemadirectory. To install ent follow the instructions here. The ent schema can be generated by runninggo generate tools.goin the root directory of the project. Alternatively, you can use theentbinary to generate the schema. - To see the ent schema description run
ent describe ./ent/schemain the root directory of the project.go generate tools.goprint the describe after generating the schema. - Alternatively, a generated ent schema describe has been provided at
tools/dump_ddl/ENT_DESCRIBE.
Please find the initial migration dump located in tools/dump_ddl/initial_dump
- Create a database in postgres.
- Set the
POSTGRES_DSNenvironment variable to your postgres dsn in the format ofuser=user password=password host=host port=port dbname=dbname sslmode=disable - Alternatively update the
PostgresDSNvariable intools/dump_ddl/main.goand rungo run tools/dump_ddl/main.goto print the migration dump, it will output the dump instdout. - Run the migration dump in the database to create the tables.
- If running with
devenvironment, set theent-drivervariable topgxto use the postgres driver instead of the sqlite driver. - Alternatively set the
ENT_DRIVERenvironment variable topgxto use the postgres driver. - Update the
postgres-dsninlocal.yamlwith the correct values.
- Run
go test ./...to run all unit tests - Run
go test -tags=e2e ./...to run test with all end-to-end scenarios - Alternatively
cd handlers && go test -tags=e2e ./...to run just the end-to-end scenario tests for the handlers
config: Contains the configuration files for the serverent: Contains the ent schema and generated ent codeeventhandler: Contains the event handlers for the server. Currently, it only contains the handler forbid.createdevent.handlers: Contains the HTTP handlers/ controllers for the serverinternal: Contains the internal packages, services, and typesrepos: Contains the repository layer for the serverrouter: Contains the router and middleware for the server. The router is built on top of gorilla mux. The routes can be found atrouter/routes.go. The middlewares can be found inside therouter/middlewaredirectory.services: Contains the services for the server, the services are responsible for the business logic of the server.tools: Contains the tools for the server, currently it only contains thedump_ddltool to generate the migration dump for the database and the postman collection json for the API.
- A
postmancollection can be found here. The collection contains all the endpoints and examples for the requests and responses. - Alternatively, you can import the collection to postman from the
tools/invoiceexchange.postman_collection.jsonfile in the root directory of the project. The collection is exported withCollection v2.1.
- Improve the balance schema and the relation between balance, issuers, and investors. Currently, the
balance.entity_idis set to unique which won't allow the issuer or investor to have multiple balance entry, but the edges areO2M. - Need ledger implementation for the available balance as well, currently the ledger is only implemented for the total balance.
- Properly assert param and returned values in test.
- More end to end scenarios and unit test cases should be tested to ensure that the system is working as expected.
- A better implementation for the eventbus.
- Proper setup and teardown for the end-to-end tests.
- Invoice items are currently not being saved, the invoice items should be saved in the database and the invoice should reference the invoice items.