Skip to main content

Project Structure - Core

Core is the main server for Openlane and where the majority of the backend code and business logic is located for the API.

cmd


Located in cmd/ this is a cobra cli that will start up the main core server. The Taskfile included in the repo provides the common commands but under the hood the serve command is what is being used

go run main.go serve --debug --pretty

config


Located in config/ this directory contains the generated config and example settings powered by koanf.

If changes are made to the config structure or dependent configs, you'll need to regenerate the config:

task config:generate
info

The first time you setup the server locally, you'll need to copy the config/config-dev.example.yaml into config/.config.yaml. This file is in the .gitignore to prevent accidentally committing secrets

internal


Located in internal/ent, this is the meat of the repo, if you are looking for something, it's probably in this directory somewhere. Everything in the internal directory is intended to only be used by packages within this repository, outside usage will be blocked by the go-compiler.

ent


Located in internal/ent this directory contains all the code related to the schemas and the interactions with the database

├── internal
│   ├── ent
│   │   ├── generated
│   │   ├── hooks
│   │   ├── interceptors
│   │   ├── mixin
│   │   ├── privacy
│   │   ├── schema
│   │   ├── templates
│   │   └── validator

graphapi


Located in internal/graphapi this directory contains all the code related to graphapi resolvers,

All graphapi resolvers require authentication, this is handled by the auth middleware and requires no updates to the resolvers themselves.

├── internal
│   ├── graphapi
│   │   ├── clientschema
│   │   ├── generate
│   │   ├── generated
│   │   ├── model
│   │   ├── query
│   │   ├── schema
│   │   └── testdata

httpserve


Located in internal/httpserve this directory contains the main http server and configuration as well as the REST api handlers and routes. Although the majority of the openlane API is a graphapi, there are several REST routes such as login, password-reset, etc.

├── internal
│   ├── httpserve
│   │   ├── authmanager
│   │   ├── config
│   │   ├── handlers
│   │   ├── route
│   │   ├── server
│   │   └── serveropts

pkg

middleware

Located in pkg/middleware this contains many commonly used middleware used by the core server.

note

These may move to internal if they are dependent on the schema, or to another repo at some point in the future.

├── pkg
│   ├── middleware
│   │   ├── auth
│   │   ├── cachecontrol
│   │   ├── cors
│   │   ├── debug
│   │   ├── mime
│   │   ├── ratelimit
│   │   ├── ratelimiter
│   │   ├── redirect
│   │   ├── secure
│   │   └── transaction

models

Located in pkg/models this includes all the model information for the REST api input and output. This is used to generate our openAPI specs.

All REST endpoints should include an entry in the models package with:

  • Request - the fields, noting omitempty if not required, that should be included with the POST request
  • Reply - the fields included in a response from the handler
  • Validate Request function - validation function for the Request
  • ExampleSuccessRequest - example request containing valid values for the fields
  • ExampleSuccessReply - example response that would be returned on a successful request

openlaneclient

Located in pkg/openlaneclient this includes the generated golang API client used to interact with the API. The queries added to internal/graphapi/query are used as input to gqlgenc for the graphclient. The restclient is manually maintained.