Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
update docs and accessibility
Brad Barbinbb1c26003780
diff --git a/README.md b/README.mdindex 9cb3733704..bc11289e8f 100644--- a/README.md+++ b/README.md@@ -1,6 +1,20 @@-# Carbon Applications and Packages+# Carbon ERP-This mono-repository contains the source code for the Carbon ERP.+Carbon is a high permformance, open-source, single tenant (incomplete) ERP written in Typescript.++It includes:++- Role-based access control (RBAC)+- Row-level security (RLS)+- Full-stack type safety (DB➡FE)+- Nested, file-based routing++## Project Status++- [ ] Alpha: Under heavy development+- [ ] Public Alpha: Ready for use. But go easy on us, there may be a few kinks.+- [ ] Public Beta: Stable enough for most non-enterprise use-cases+- [ ] Public: Production-ready### Apps@@ -27,7 +41,7 @@ This mono-repository contains the source code for the Carbon ERP.- [Turborepo](https://turbo.build)- [Remix](https://remix.run)- [Supabase](https://supabase.com/)-- [Postgres] (https://postgresql.org/)+- [Postgres](https://postgresql.org/)- [Chakra UI](https://chakra-ui.com/)- [Redis](https://redis.io)- [Prisma](https://prisma.io/)diff --git a/apps/carbon/app/components/Navigation/Topbar/AvatarMenu.tsx b/apps/carbon/app/components/Navigation/Topbar/AvatarMenu.tsxindex 155bcb3411..6fb812a3a0 100644--- a/apps/carbon/app/components/Navigation/Topbar/AvatarMenu.tsx+++ b/apps/carbon/app/components/Navigation/Topbar/AvatarMenu.tsx@@ -16,7 +16,13 @@ const AvatarMenu = () => {return (<Menu>- <MenuButton as={Avatar} name="" size="sm" cursor="pointer" />+ <MenuButton+ as={Avatar}+ role="button"+ name=""+ size="sm"+ cursor="pointer"+ /><MenuList fontSize="sm" boxShadow="xl" minW={48}><MenuItem>Signed in as {`${user.firstName} ${user.lastName}`}</MenuItem><MenuDivider />diff --git a/apps/carbon/app/components/Navigation/Topbar/Breadcrumbs.tsx b/apps/carbon/app/components/Navigation/Topbar/Breadcrumbs.tsxindex 64fde81aac..709706eb4c 100644--- a/apps/carbon/app/components/Navigation/Topbar/Breadcrumbs.tsx+++ b/apps/carbon/app/components/Navigation/Topbar/Breadcrumbs.tsx@@ -26,6 +26,7 @@ const Breadcrumbs = ({ links = [] }: BreadcrumbProps) => {color={linkColor}as={Link}to={link.to}+ aria-label={link.name}>{link.icon ? link.icon : link.name}</BreadcrumbLink>diff --git a/apps/carbon/app/components/Navigation/Topbar/useBreadcrumbs.tsx b/apps/carbon/app/components/Navigation/Topbar/useBreadcrumbs.tsxindex c973c4e218..8fea10e1b1 100644--- a/apps/carbon/app/components/Navigation/Topbar/useBreadcrumbs.tsx+++ b/apps/carbon/app/components/Navigation/Topbar/useBreadcrumbs.tsx@@ -8,7 +8,7 @@ export default function useBreadcrumbs(): Route[] {const result = matches.reduce<Route[]>((acc, match) => {switch (match.id) {case "root":- return acc.concat({ to: "/app", name: "", icon: <IoHomeSharp /> });+ return acc.concat({ to: "/app", name: "Home", icon: <IoHomeSharp /> });case "routes/app.parts":return acc.concat({name: "Parts",diff --git a/apps/carbon/app/components/Todo/Todo.tsx b/apps/carbon/app/components/Todo/Todo.tsxnew file mode 100644index 0000000000..a7cb92c1f5--- /dev/null+++ b/apps/carbon/app/components/Todo/Todo.tsx@@ -0,0 +1,18 @@+import { Box, Heading, ListItem, UnorderedList } from "@chakra-ui/react";++const Todo = ({ items }: { items: string[] }) => {+ return (+ <Box py={4} px={8}>+ <Heading size="md" py={4}>+ TODO+ </Heading>+ <UnorderedList>+ {items.map((item) => (+ <ListItem key={item}>{item}</ListItem>+ ))}+ </UnorderedList>+ </Box>+ );+};++export default Todo;diff --git a/apps/carbon/app/components/Todo/index.ts b/apps/carbon/app/components/Todo/index.tsnew file mode 100644index 0000000000..5b2fda1a61--- /dev/null+++ b/apps/carbon/app/components/Todo/index.ts@@ -0,0 +1,3 @@+import Todo from "./Todo";++export default Todo;diff --git a/apps/carbon/app/modules/Users/EmployeeTypesTable/EmployeeTypesTable.tsx b/apps/carbon/app/modules/Users/EmployeeTypesTable/EmployeeTypesTable.tsxindex c26533599e..ef66618aa1 100644--- a/apps/carbon/app/modules/Users/EmployeeTypesTable/EmployeeTypesTable.tsx+++ b/apps/carbon/app/modules/Users/EmployeeTypesTable/EmployeeTypesTable.tsx@@ -26,6 +26,7 @@ const EmployeeTypesTable = memo(({ data }: EmployeeTypesTableProps) => {h={6}borderRadius="md"bg={row.color ?? "#000000"}+ role="img"/>),actions: (diff --git a/apps/carbon/app/routes/app.users.customers.tsx b/apps/carbon/app/routes/app.users.customers.tsxindex cb7eefa9ba..0857abc451 100644--- a/apps/carbon/app/routes/app.users.customers.tsx+++ b/apps/carbon/app/routes/app.users.customers.tsx@@ -1,3 +1,13 @@+import Todo from "~/components/Todo";+export default function UsersCustomersRoute() {- return null;+ return (+ <Todo+ items={[+ "Add partners so that we can associate a customers with an organization",+ "Add customer account CRUD",+ "Add RLS such that customers can access things related to their orders",+ ]}+ />+ );}diff --git a/apps/carbon/app/routes/app.users.employees.tsx b/apps/carbon/app/routes/app.users.employees.tsxindex 2209a17a65..fd7a0c0697 100644--- a/apps/carbon/app/routes/app.users.employees.tsx+++ b/apps/carbon/app/routes/app.users.employees.tsx@@ -64,7 +64,6 @@ export default function UsersEmployeesRoute() {// @ts-ignoresize="sm"colorScheme="brand"- minW={180}defaultValue={employeeTypeOptions.filter((type) => type.value === params.get("type"))}@@ -73,6 +72,8 @@ export default function UsersEmployeesRoute() {onChange={(selected) => {setParams("type", selected?.value);}}+ aria-label="Employee Type"+ minW={180}placeholder="Employee Type"/></HStack>diff --git a/apps/carbon/app/routes/app.users.suppliers.tsx b/apps/carbon/app/routes/app.users.suppliers.tsxindex d7088a0426..d1b85f98ab 100644--- a/apps/carbon/app/routes/app.users.suppliers.tsx+++ b/apps/carbon/app/routes/app.users.suppliers.tsx@@ -1,3 +1,13 @@+import Todo from "~/components/Todo";+export default function UsersSuppliersRoute() {- return null;+ return (+ <Todo+ items={[+ "Add partners so that we can associate a supplier with an organization",+ "Add supplier account CRUD",+ "Add RLS such that suppliers can access things related to their orders",+ ]}+ />+ );}diff --git a/apps/docs/package.json b/apps/docs/package.jsonindex f958f7cf31..b3e0b9c9cd 100644--- a/apps/docs/package.json+++ b/apps/docs/package.json@@ -5,7 +5,7 @@"scripts": {"build": "next build","clean": "rm -rf .turbo rm -rf .next && rm -rf node_modules",- "dev": "next dev -p 411",+ "dev": "next dev -p 4111","lint": "TIMING=1 next lint","start": "next start "},diff --git a/apps/docs/pages/Permissions/_meta.json b/apps/docs/pages/Permissions/_meta.jsonnew file mode 100644index 0000000000..ab9da61a1d--- /dev/null+++ b/apps/docs/pages/Permissions/_meta.json@@ -0,0 +1,8 @@+{+ "overview": "Overview",+ "claims": "Claims",+ "permissions": "Permissions",+ "employee-types": "Employee Types",+ "groups": "Groups",+ "policies": "Policies"+}diff --git a/apps/docs/pages/Permissions/claims.mdx b/apps/docs/pages/Permissions/claims.mdxnew file mode 100644index 0000000000..01911c2b08--- /dev/null+++ b/apps/docs/pages/Permissions/claims.mdx@@ -0,0 +1,15 @@+## Claims++Permissions and roles are stored in a single `JSONB` column called `raw_app_meta_data` in the `auth.users` table. The reason for storing everything in one row is for faster performance when performing RLS lookups.++Each user has one role and many permissions is stored as key/value pairs, for example:++```json+{+ "role": "EMPLOYEE",+ "parts_view": true,+ "parts_create": false,+ "parts_update": false,+ "parts_delete": false+}+```diff --git a/apps/docs/pages/Permissions/employee-types.mdx b/apps/docs/pages/Permissions/employee-types.mdxnew file mode 100644index 0000000000..c3367d9d76--- /dev/null+++ b/apps/docs/pages/Permissions/employee-types.mdx@@ -0,0 +1 @@+# Employee Typesdiff --git a/apps/docs/pages/Permissions/groups.mdx b/apps/docs/pages/Permissions/groups.mdxnew file mode 100644index 0000000000..e97b3e912a--- /dev/null+++ b/apps/docs/pages/Permissions/groups.mdx@@ -0,0 +1 @@+# Groupsdiff --git a/apps/docs/pages/Permissions/overview.mdx b/apps/docs/pages/Permissions/overview.mdxnew file mode 100644index 0000000000..d59245c0d7--- /dev/null+++ b/apps/docs/pages/Permissions/overview.mdx@@ -0,0 +1,57 @@+import { Callout } from "nextra-theme-docs";++# Overview++The claims administrator can pull three levers to control what users can see and do. Because we use words that are used in different fashions in elsewhere, we'll define them here.++1. **Permissions** - user-specific boolean values for each feature/action++- `TABLE/FEATURE LEVEL`+- The user can view documents+- The user can delete parts++2. **Groups** - a shorthand identifier for a set of users that can access to a specific resource++- `ROW LEVEL`+- The group can view the document+- The group can view the post+- The group can modify the proposal++3. **Roles** - a single string from a predefined set used for row-level filters in the database++- `ROW LEVEL`+- The customer can view sales orders from his organization+- The supplier can view purchase orders from his organization++<Callout>+ Permissions grant broad access, while groups give more fine-grained control.+</Callout>++## Permissions++Each _feature_ (parts, job, timecards) has four corresponding permissions:++1. `*_view`+2. `*_create`+3. `*_update`+4. `*_delete`++So if there were 10 features, then each user would need 40 (4 ⨉ 10) permissions definitions. That's tedious work.++## Employee Types++To avoid checking 40 checkboxes for each user, we've created model we're calling an **Employee Type** which allow us to define a preset permissions-spec for a type of user (e.g. Engineer). The permissions can be modified at the individual level later, but it's a good starting point for user creation. Employee Types also serve as the users' first group.++## Groups++Users can belong to as many groups as you'd like. The basic gist is that a group is a set of users (or other groups). But ultimately, groups resolve to a set of people that can be used to filter database queries.++## Roles++There are currently only three roles:++1. `EMPLOYEE`+2. `CUSTOMER`+3. `SUPPLIER`++The `CUSTOMER` and `SUPPLIER` roles work to limit what a user can see through Row-Level Security (RLS).diff --git a/apps/docs/pages/Permissions/permissions.mdx b/apps/docs/pages/Permissions/permissions.mdxnew file mode 100644index 0000000000..b39acdb5ca--- /dev/null+++ b/apps/docs/pages/Permissions/permissions.mdx@@ -0,0 +1,51 @@+# Permissions++Permissions are coarse-grain controls that give or restrict access to a broad resource. Permissions are stored as `JSONB` claims in the `auth.users` table. They are parsed and made ready for use by the application. On the client we use the `usePermissions` hook, and on the server we use the `requirePermissions` function. Both of these functions are relative to the authenticated user.++import { Tabs, Tab } from "nextra-theme-docs";++<Tabs items={["Client Side", "Server Side", "Database"]}>+ <Tab>+```tsx+function Component () {+ const permissions = usePermissions();++ return+ (permissions.can('create', 'parts'))+ ? <Button>Create Part</Button>+ : null+}+```+ </Tab>+ <Tab>+```ts+export async function loader({request}: LoaderArgs) {+ // a client is needed to access the database+ const { client } = await requirePermission(request, {+ view: "users"+ });++return json(await getEmployees(client));+}++````+ </Tab>+ <Tab>+```sql+CREATE POLICY+"Only users with the parts_view permission can SELECT from Parts"+ON "Parts"+FOR SELECT+USING (coalesce(get_my_claim('parts_view'), false));+````++ </Tab>+</Tabs>++import { Callout } from "nextra-theme-docs";++<Callout>+ To bypass all policies and security, a server-side client can be created with+ the `getSupabaseAdmin()` method. This should be used with extreme caution and+ never on the client.+</Callout>diff --git a/apps/docs/pages/Permissions/policies.mdx b/apps/docs/pages/Permissions/policies.mdxnew file mode 100644index 0000000000..4be3163a37--- /dev/null+++ b/apps/docs/pages/Permissions/policies.mdx@@ -0,0 +1 @@+# Policiesdiff --git a/package.json b/package.jsonindex 758f3185f8..5597a620ba 100755--- a/package.json+++ b/package.json@@ -14,8 +14,12 @@"build:packages": "turbo run build --filter=./packages/*","clean": "turbo run clean && rm -rf node_modules && rm -rf supabase","db:init": "turbo run db:init",- "db:start": "turbo run db:start",- "db:kill": "turbo run db:kill",+ "db:start": "run-p db:start:database db:start:redis",+ "db:start:database": "yarn workspace @carbon/database supabase start",+ "db:start:redis": "yarn workspace @carbon/redis db:start",+ "db:kill": "run-p db:kill:supabase db:kill:redis",+ "db:kill:supabase": "yarn workspace @carbon/database supabase stop",+ "db:kill:redis": "yarn workspace @carbon/redis db:kill","db:types": "yarn workspace @carbon/database db:types","db:migrate": "yarn workspace @carbon/database db:migrate","db:migrate:new": "yarn workspace @carbon/database db:migrate:new",diff --git a/packages/carbon-react/src/Message/useNotification.tsx b/packages/carbon-react/src/Message/useNotification.tsxindex d17a0857cf..b78fe501bc 100644--- a/packages/carbon-react/src/Message/useNotification.tsx+++ b/packages/carbon-react/src/Message/useNotification.tsx@@ -73,7 +73,7 @@ export default function useNotification() {...defaultOptions,render: (/*props: RenderProps*/) => {return (- // TODO: do we need a client only here?+ // do we need a ClientOnly component here?<ClientOnlyfallback={<FakeCopyableErrorMessage message={message} />}>