Clojure microservice implementing: Components, Reitit, Pedestal, Schema, PostgreSQL and Tests.
-
school-module: With ports and adapters architecture, this project is a simple school module that allows you to register and manipulate accounts payable (and receivable in the future - if possible).
-
parenthesin/components: Helpers and component wrappers to give a foundation to create new services in clojure, you can find components for database, http, webserver and tools for db migrations.
Verb | URL | Description |
---|---|---|
GET | /swagger.json | Fetch Swagger API documentation |
POST | /login | Login with your username and password |
GET | /courses | Get all courses transactions |
POST | /courses | Add a new course entry |
GET | /courses/:id | Get course transactions by ID |
PUT | /courses/:id | Update a course entry by ID |
DELETE | /courses/:id | Remove a course entry by ID |
GET | /students | Get all students transactions |
POST | /students | Add a new student entry |
GET | /students/:id | Get student transactions by ID |
PUT | /students/:id | Update a student entry by ID |
DELETE | /students/:id | Remove a student entry by ID |
GET | /subjects | Get all subjects transactions |
POST | /subjects | Add a new subject entry |
GET | /subjects/:id | Get subject transactions by ID |
PUT | /subjects/:id | Update a subject entry by ID |
DELETE | /subjects/:id | Remove a subject entry by ID |
GET | /attending | Get all attending transactions |
POST | /attending | Add a new attending entry |
GET | /attending/:id | Get attending transactions by ID |
PUT | /attending/:id | Update an attending entry by ID |
DELETE | /attending/:id | Remove an attending entry by ID |
To open a nrepl
clj -M:nrepl
To open a nrepl with all test extra-deps on it
clj -M:test:nrepl
To run unit tests inside ./test/unit
clj -M:test :unit
To run integration tests inside ./test/integration
clj -M:test :integration
To run all tests inside ./test
clj -M:test
To generate a coverage report
clj -M:test --plugin kaocha.plugin/cloverage
clj -M:clojure-lsp format
clj -M:clojure-lsp clean-ns
clj -M:clojure-lsp diagnostics
To create a new migration with a name
clj -M:migratus create migration-name
To execute all pending migrations
clj -M:migratus migrate
To rollback the latest migration
clj -M:migratus rollback
See Migratus Usage for documentation on each command.
Start containers with postgres user: postgres, password: postgres, hostname: db, port: 5432
and pg-admin email: pg@pg.cc, password: pg, port: 5433
docker-compose -f docker/docker-compose.yml up -d
Stop containers
docker-compose -f docker/docker-compose.yml stop
First you need to have the database running, for this you can use the docker command in the step above.
You can start a repl open and evaluate the file src/school_module/server.clj
and execute following code:
(start-system! (build-system-map))
You can generate an uberjar and execute it via java in the terminal:
# genarate a target/service.jar
clj -T:build uberjar
# execute it via java
java -jar target/service.jar
- schema Types and Schemas
- component System Lifecycle and Dependencies
- pedestal Http Server
- reitit Http Routes System
- clj-http Http Client
- cheshire JSON encoding
- aero Configuration file and enviroment variables manager
- timbre Logging library
- next-jdbc JDBC-based layer to access databases
- hikaricp A solid, high-performance, JDBC connection pool at last
- tools.build Clojure builds as Clojure programs
- kaocha Test runner
- kaocha-cloverage Kaocha plugin for code coverage reports
- schema-generators Data generation and generative testing
- state-flow Testing framework for integration tests
- matcher-combinators Assertions in data structures
- pg-embedded-clj Embedded PostgreSQL for integration tests
- clojure-lsp Code Format, Namespace Check and Diagnosis
erDiagram
COURSES {
uuid id PK "Primary key, unique identifier"
boolean removed "Indicates if the course is removed"
varchar name "Course name, max 255 chars"
text description "Course description"
timestamp created_at "Timestamp of course creation"
}
STUDENTS {
uuid id PK "Primary key, unique identifier"
boolean removed "Indicates if the student is removed"
varchar name "Student name, max 255 chars"
varchar document "Student document identifier"
varchar email "Student email"
varchar phone "Student phone number"
timestamp created_at "Timestamp of student registration"
}
SUBJECTS {
uuid id PK "Primary key, unique identifier"
boolean removed "Indicates if the subject is removed"
varchar name "Subject name, max 255 chars"
text description "Subject description"
uuid courses_id FK "References COURSES(id)"
timestamp created_at "Timestamp of subject creation"
}
ATTENDING {
uuid id PK "Primary key, unique identifier"
boolean removed "Indicates if the attendance is removed"
uuid students_id FK "References STUDENTS(id)"
uuid subjects_id FK "References SUBJECTS(id)"
timestamp created_at "Timestamp of attendance creation"
}
COURSES ||--o{ SUBJECTS : "contains"
SUBJECTS ||--o{ ATTENDING : "has"
STUDENTS ||--o{ ATTENDING : "attends"
./
├── .clj-kondo -- clj-kondo configuration and classes
├── .lsp -- clojure-lsp configuration
├── .github
│ └── workflows -- Github workflows folder.
├── docker -- docker and docker-compose files for the database
├── resources -- Application resources assets folder and configuration files.
│ └── migrations -- Current database schemas, synced on service startup.
├── src -- Library source code and headers.
│ └── school_module -- Source for the service example.
└── test -- Test source code.
├── integration -- Integration tests source (uses state-flow).
│ └── school_module -- Tests for service example.
└── unit -- Unity tests source (uses clojure.test).
└── school_module -- Tests for service example.
This is free and unencumbered software released into the public domain.
For more information, please refer to http://unlicense.org