Internal operations management system for multi-unit restaurant chains.
FlowChain replaces manual WhatsApp and Excel-based workflows with a structured, traceable, and role-based REST API β covering weekly supply orders, warehouse stock control, distribution planning, daily chicken stock tracking, urgent inter-unit transfers, and supplier payment registration.
| Technology | Version | Purpose |
|---|---|---|
| Java | 21 (LTS) | Programming language |
| Spring Boot | 3.5.13 | Main framework |
| Spring Security + JWT (jjwt) | 0.12.6 | Authentication & authorization |
| Spring Data JPA + Hibernate | 3.x | Database ORM |
| PostgreSQL | 16 | Relational database |
| Docker + Docker Compose | Latest | Containerization |
| Maven | 3.x | Build & dependency management |
| JUnit 5 + Mockito | Latest | Unit & integration testing |
| Swagger / OpenAPI | 2.8.8 | API documentation |
| Lombok | Latest | Boilerplate reduction |
The system follows a Layered Architecture with clear separation of concerns:
Client (Mobile App / Browser)
β HTTP Request + JWT
JwtAuthenticationFilter β Validates the token, sets the security context
β Authenticated
Spring Security rules β Decides whether the request is allowed through
β Authorized
Controller Layer β Receives HTTP requests, validates DTOs
β
Service Layer β Business logic, validations, aggregations
β
Repository Layer β Spring Data JPA, database communication
β
PostgreSQL Database
Authentication is stateless: no sessions are created. Every request carries its own proof (the JWT), and the user's identity and role are read from the token itself β no database lookup is needed to identify the caller.
| Role | Description |
|---|---|
| ADMIN | Full access β consolidated lists, all units, user management |
| WAREHOUSE | Stock management, distributions, delivery confirmation |
| UNIT | Weekly orders, daily chicken stock, payment registration |
| COURIER | Urgent transfers between units |
The system manages 7 operational units:
| Unit | Type | Special Role |
|---|---|---|
| Alpha | Restaurant | Portioning center β bacalhau & entrecosto |
| Beta | Restaurant + Take Away | Operations hub β soups, rice, prepared dishes + courier base |
| Gamma | Restaurant + Take Away | β |
| Delta | Restaurant + Take Away | β |
| Epsilon | Take Away | β |
| Zeta | Take Away | β |
| Eta | Take Away | β |
| Day | Operation | Responsible |
|---|---|---|
| Monday | Charcoal distribution | Warehouse |
| Tuesday | Warehouse products distribution | Warehouse |
| Thursday | External supplier purchases + distribution | Admin + Warehouse |
| Friday | Meats & prepared dishes distribution | Warehouse |
| Daily | Chicken stock control | Each Unit |
| Any time | Urgent transfers between units | Courier |
- Requirements analysis
- Data model design (12 entities)
- System architecture diagram
- Spring Boot 3.x project setup
- GitHub repository initialization
- Docker Compose β PostgreSQL + pgAdmin
- Project folder structure
- Unit entity with JPA mappings
- UnitRepository, UnitService, UnitController
- First REST endpoint β GET /api/units
- Swagger UI integration
- Global exception handling with
@RestControllerAdvice
- User entity + Role enum (ADMIN, WAREHOUSE, UNIT, COURIER)
- UserRepository with email lookup
- BCrypt password hashing
- Spring Security enabled β stateless
SecurityFilterChain - Admin user seeding on startup (
CommandLineRunner) - JWT token generation with jjwt (
JwtService) - Login endpoint β
POST /api/auth/login - JWT authentication filter β token validated on every request
- End-to-end authentication working (protected endpoints accessible with a valid token)
- Role-based access control on endpoints
- Weekly order submission per unit (Supplier, Warehouse, Beira Sumos)
- Prepared dishes order (soup, rice, bacalhau, etc.)
- Automatic consolidated order list per supplier
- Order status tracking (PENDING β CONFIRMED β DELIVERED)
- Warehouse stock entries and exits
- Weekly distribution planning per unit
- Portioning registration (Alpha & Beta units)
- Delivery confirmation per unit
- Daily chicken stock control (per unit)
- Urgent product transfers between units
- Supplier payment registration with invoice photo
- Operations history and audit trail
- Unit tests with JUnit 5 + Mockito
- Integration tests
- Full Swagger / OpenAPI documentation
- API usage examples
- Input validation on all endpoints
- System logging
- Externalize secrets (environment variables)
- Security review
flowchain-api/
βββ docs/ # Project documentation (PDF)
β βββ FlowChain_Analise_Requisitos.pdf
β βββ FlowChain_Modelo_Dados.pdf
β βββ FlowChain_Arquitetura.pdf
β βββ FlowChain_UseCases.html
βββ src/
β βββ main/
β β βββ java/com/flowchain/api/
β β β βββ config/ # Startup configuration (DataSeeder)
β β β βββ controller/ # REST Controllers (Unit, Auth)
β β β βββ service/ # Business logic (Unit, Auth)
β β β βββ repository/ # Spring Data JPA repositories
β β β βββ entity/ # JPA entities (Unit, UnitType, User, Role)
β β β βββ dto/ # Data Transfer Objects
β β β βββ security/ # SecurityConfig, JwtService,
β β β β # JwtAuthenticationFilter
β β β βββ exception/ # GlobalExceptionHandler
β β βββ resources/
β β βββ application.yaml # App configuration
β βββ test/ # Unit & integration tests
βββ docker-compose.yml # PostgreSQL + pgAdmin containers
βββ pom.xml # Maven dependencies
βββ README.md
- Java 21
- Docker + Docker Compose
- Maven 3.x
1. Clone the repository
git clone https://github.com/CLopes86/flowchain-api.git
cd flowchain-api2. Start the database
docker compose up -d3. Run the application
./mvnw spring-boot:run4. Access Swagger UI
http://localhost:8080/swagger-ui/index.html
All endpoints are protected by default. Only /api/auth/** and the Swagger
paths are public.
On first startup, a default ADMIN user is automatically seeded:
| Field | Value |
|---|---|
admin@flowchain.com |
|
| Password | admin123 |
| Role | ADMIN |
1. Get a token
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@flowchain.com","password":"admin123"}'Response:
{
"token": "eyJhbGciOiJIUzM4NCJ9...",
"type": "Bearer",
"email": "admin@flowchain.com",
"name": "Patroa",
"role": "ADMIN"
}2. Call a protected endpoint
curl -X GET http://localhost:8080/api/units \
-H "Authorization: Bearer <token>"Without the header, the same request is rejected before it ever reaches the controller.
How it works
- The token is signed with an HMAC-SHA key and is valid for 24 hours
- Its payload carries
sub(email),role,iatandexp JwtAuthenticationFiltervalidates the signature on every request and places the authenticated user in the Spring Security context- Passwords are never stored β only their BCrypt hash, with a unique salt per user
β οΈ Development credentials only. Change them, and move the JWT secret to an environment variable, before any real deployment.
| Method | Endpoint | Role | Description | Status |
|---|---|---|---|---|
| POST | /api/auth/login |
Public | User login β returns JWT | β |
| GET | /api/units |
Authenticated | List all units | β |
| GET | /api/units/{id} |
Authenticated | Get unit by ID | β |
| POST | /api/units |
ADMIN | Create new unit | β |
| DELETE | /api/units/{id} |
ADMIN | Delete unit | β |
| POST | /api/orders |
UNIT | Submit weekly order | β³ |
| GET | /api/orders/consolidated |
ADMIN, WAREHOUSE | Consolidated order list | β³ |
| POST | /api/warehouse/stock |
WAREHOUSE | Register stock movement | β³ |
| POST | /api/distributions |
WAREHOUSE | Create distribution | β³ |
| PUT | /api/distributions/{id}/confirm |
WAREHOUSE | Confirm delivery | β³ |
| POST | /api/chicken-stock |
UNIT | Daily chicken stock | β³ |
| POST | /api/transfers |
COURIER | Register urgent transfer | β³ |
| POST | /api/payments |
UNIT | Register supplier payment | β³ |
Implemented endpoints currently require a valid token. The per-role restrictions listed above are the intended design β enforcing them is the remaining Phase 2 task.
Full project documentation is available in the /docs folder:
- π Requirements Analysis
- ποΈ Data Model
- ποΈ Architecture Diagram
- π Use Case Diagram
Cesaltino Lopes Computer Science Student @ IPCB β Castelo Branco, Portugal
This project is under active development. New features are added progressively following the roadmap above.
