• Stars
    star
    1,132
  • Rank 41,129 (Top 0.9 %)
  • Language
    Clojure
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Server-side application framework for Clojure

Duct

Duct is a highly modular framework for building server-side applications in Clojure using data-driven architecture.

It is similar in scope to Arachne, and is based on Integrant. Duct builds applications around an immutable configuration that acts as a structural blueprint. The configuration can be manipulated and queried to produce sophisticated behavior.

Upgrading

See: UPGRADING.md.

Quick Start

To create a new Duct project with Leiningen:

lein new duct <your project name>

This will create a minimal Duct project. You can extend this by appending profile hints to add extra functionality.

  • +api adds API middleware and handlers
  • +ataraxy adds the Ataraxy router
  • +cljs adds in ClojureScript compilation and hot-loading
  • +example adds an example handler
  • +heroku adds configuration for deploying to Heroku
  • +postgres adds a PostgreSQL dependency and database component
  • +site adds site middleware, a favicon, webjars and more
  • +sqlite adds a SQLite dependency and database component

For example:

lein new duct foobar +site +example

As with all Leiningen templates, Duct will create a new directory with the same name as your project. For information on how to run and build your project, refer to the project's README.md file.

Concepts

The structure of the application is defined by an Integrant configuration map.

In development, Duct uses Stuart Sierra's Reloaded Workflow.

In production, Duct follows the Twelve-Factor App methodology.

Local state is preferred over global state.

Namespaces should group functions by purpose, rather than by layer.

Protocols should be used to wrap external APIs.

Structure

Duct adds a layer of abstraction on top of Integrant. In Integrant, a configuration map is initiated into a running system map.

┌────────┐   ┌────────┐
│ config ├──>│ system │
└────────┘   └────────┘

In Duct, the configuration is initiated twice. The configuration is first initiated into an intermediate configuration, which in turn is initiated into the system:

┌────────┐   ┌──────────────┐   ┌────────┐
│ config ├──>│ intermediate ├──>│ system │
└────────┘   └──────────────┘   └────────┘

In the same way that higher-order functions allow us to abstract common patterns of code, Duct's layered configurations allow us to abstract common patterns of configuration.

Keys in a Duct configuration are expected to initiate into functions that transform a configuration map. There are two broad types: profiles, which merge their value into the configuration, and modules, which provide more complex manipulation.

Documentation

Community

File structure

Duct projects are structured as below. Files marked with a * are kept out of version control.

{{project}}
├── README.md
├── dev
│   ├── resources
│   │   ├── dev.edn
│   │   └── local.edn *
│   └── src
│       ├── dev.clj
│       ├── local.clj *
│       └── user.clj
├── profiles.clj
├── project.clj
├── resources
│   └── {{project}}
│       └── config.edn
├── src
│   ├── duct_hierarchy.edn
│   └── {{project}}
│       └── main.clj
└── test
    └── {{project}}

License

Copyright © 2021 James Reeves

Distributed under the MIT license.

More Repositories

1

core

The core library of the Duct framework
Clojure
75
star
2

module.web

Duct module for running web applications
Clojure
21
star
3

docs

Documentation for Duct
21
star
4

scheduler.simple

A simple scheduler for Integrant
Clojure
19
star
5

duct-figwheel-component

A component for running Figwheel
Clojure
18
star
6

middleware.buddy

Integrant keys for Buddy middleware
Clojure
9
star
7

logger

Logging library for the Duct framework
Clojure
6
star
8

module.sql

Duct module for working with a SQL database
Clojure
6
star
9

migrator.ragtime

Integrant methods for running database migrations using Ragtime
Clojure
5
star
10

database.sql.hikaricp

Integrant methods for a SQL database connection pool
Clojure
5
star
11

module.ataraxy

Duct module and router for the Ataraxy routing library
Clojure
5
star
12

database.sql

Integrant methods for connecting to a SQL database
Clojure
4
star
13

server.figwheel

Integrant methods for running Figwheel
Clojure
4
star
14

module.logging

Logging module for Duct
Clojure
4
star
15

logger.clojure

Duct logger that uses tools.logging
Clojure
4
star
16

server.http.jetty

Integrant methods for running a Jetty web server
Clojure
3
star
17

handler.sql

Duct library for building simple database-driven handlers
Clojure
3
star
18

logger.timbre

Integrant methods for the Timbre logging library
Clojure
3
star
19

server.http.http-kit

Integrant methods for running a HTTP-Kit web server
Clojure
2
star
20

compiler.cljs

Integrant methods for compiling ClojureScript
Clojure
2
star
21

module.cljs

Duct module for developing and compiling ClojureScript
Clojure
2
star
22

database.redis.carmine

Integrant methods for connecting to a Redis database via Carmine
Clojure
2
star
23

server.http.aleph

Integrant methods for running an Aleph web server
Clojure
1
star
24

compiler.sass

Integrant methods for compiling Sass into CSS
Clojure
1
star