# CircleCI {#circleci}


CircleCI pipelines for building, testing, and deploying the API and webapp.


## Configuration {#configuration}


Located at `.circleci/config.yml`.


## Pipeline Stages {#pipeline-stages}


```
1. Install Dependencies → yarn install
2. Lint → ESLint checks
3. Build → NX build api, webapp
4. Test → Unit tests, E2E tests
5. Docker → Build and push images
6. Deploy → Deploy to staging/production
```


## Key Jobs {#key-jobs}


| Job                 | Purpose                             |
| ------------------- | ----------------------------------- |
| `install-deps`      | Install and cache node_modules      |
| `lint`              | Run ESLint across affected projects |
| `build-api`         | Build NestJS API                    |
| `build-webapp`      | Build Angular webapp                |
| `test`              | Run unit tests                      |
| `docker-build`      | Build Docker images                 |
| `deploy-staging`    | Deploy to staging environment       |
| `deploy-production` | Deploy to production                |


## Caching {#caching}


CircleCI caches for faster builds:

```yaml
- restore_cache:
    keys:
      - yarn-deps-{{ checksum "yarn.lock" }}
      - yarn-deps-

- save_cache:
    key: yarn-deps-{{ checksum "yarn.lock" }}
    paths:
      - node_modules
      - ~/.cache/yarn
```


## Environment Variables {#environment-variables}


Configure in CircleCI project settings:

| Variable                | Purpose                     |
| ----------------------- | --------------------------- |
| `DOCKER_USERNAME`       | Container registry username |
| `DOCKER_PASSWORD`       | Container registry password |
| `NX_CLOUD_ACCESS_TOKEN` | NX remote caching           |
| `STAGING_SSH_KEY`       | SSH key for staging deploy  |


## Workflow Filters {#workflow-filters}


```yaml
workflows:
  build-and-deploy:
    jobs:
      - build-api:
          filters:
            branches:
              only: [main, develop]
      - deploy-staging:
          requires: [build-api, build-webapp]
          filters:
            branches:
              only: develop
      - deploy-production:
          requires: [build-api, build-webapp]
          filters:
            branches:
              only: main
```


## Related Pages {#related-pages}


- [CI/CD Overview](https://sourcey-gauzy.pages.dev/deployment/ci-cd/ci-cd-overview/index.md)
- [GitHub Actions](https://sourcey-gauzy.pages.dev/deployment/ci-cd/github-actions/index.md)
