Skip to main content
View on YouTube to comment and like!

Syntax Video

Local First from Scratch - How to make a web app with local data

Chapter 1 0:00

Intro

hey what's up this is Scott with syntax and today we're going to be building a local first application now this is going to be based on an invoice application that I wrote that works entirely offline this works with local data stored in an index DB it works completely offline with a service worker and it even lets you export your data now since there's no data going to a server anywhere this thing is extremely fast it loads all of your invoices directly from your own computer so that data again is private it is on your computer and it doesn't need to make a network request to get it now I'll show you a quick demo here where we can have all of our different invoices these are stored inside of like I mentioned an index DB anytime we make an adjustment to this if I refresh you'll see this happens automatically it saves it

completely for us so this thing autosave as well and we can even export all of our invoices as Json now over the course of building this we're going to be getting into the nitty-gritty of what it takes to build an application like this using minimal dependencies we're just going to be using one which is called dexi it is an index DB wrapper that just makes working with index DB the local database in your browser a little bit easier other than that we will be building this in spelt kit but that is not going to be that important because I will call out anytime anything is different in react view Etc and if you know react if you know view you can still follow along to this because the framework is not really what's important here it's how we work with the data and how we work with the form and through that we'll have a real working app by the end of this although it's not going to be this pretty this source code is completely open source if you ever want

to take a look at this and potentially skip the rest of this video so let's get going like I mentioned we're going to be starting with a spelt kit application so from my terminal I'm going to create a new spelt kit project you can do that with npm create spelt at latest and then we can give this a name we can call this local invoice okay this is the name now again don't feel like you have to use felt kit for this it might even help if you follow along in your own framework of choice because over the course of this video what we'll be doing is we'll be diving into even some of the browser utilities that help you understand what's going on here so this is more than just building a thing in felt this is about core features okay so the way we do this is I'm going to say this is going to be a skeleton project for scaffolding and then we're going to say yes to typescript es lint prettier and I will

Chapter 2 2:06

Npm Install

select the spelt 5 preview if you're not familiar with spelt 5 or you don't care again you can use SP 4 and follow along just as easily okay so from there we're going to change directories into our local invoice uh I'm going to run code on this just to get this up in vs code I'm going to be using vs code to work on this so if you notice I'm going to be using what is called the level up official theme for this inside of vs code um you can use any text editor you'd like that doesn't matter okay let's run npm install and before we get anything else going I'm actually going to add a package and this is going to be dexi like I mentioned this is going to be the only package we add in this so we'll say npm install hyphen hyen save dexi DX iie this is a really commonly used utility so don't feel like you're installing some random plugin this thing

is definitely battle tested now from here we can run npm run de since this is a v site this is just going to pop open in our 5137 Port like you might be used to all right here we are now for a lot of this video I'm going to keep this open side by side but we'll do a lot of tabbing back and forth here like this I'll make sure that the font size is nice and big for you again I'm going to try to call out spelt specific things now the way that this works inside of a spelt app is you just have your routes inside of your routes is your main route now we're not going to have any routes in this application Beyond just the index page so I don't need to create any files I'm just going to go ahead and clear out the contents of this file now the first couple of things we'll want to do before we get into anything is we're going to create a couple of files one will be our db. Ts for our database creation and the other is going to be our data. TS which will which will

include like the initial state for our application and we can create those side by side in our routes folder simply creating a file in our routes folder isn't going to cause any issues so we can say db. TS and then another one which is data. TS like I mentioned and db. TS is going to be where we're going to start the first thing we're going to want to do is create our database so that way we have access to add and store and remove things right so we'll want to import dexi from uh dexi there we go and we'll eventually be importing some types and stuff but we'll also be doing that with Auto Imports I'll show you how we do that so the first thing we're going to do is say const DB is equal to new dexi and then dexi is going to take a string which will be our name of our database so we can call this anything we want we can say invoice

Chapter 3 4:58

Database Initialization

local and we don't need to do anything else there but we will in a second once we want to add some typescript to this next thing we're want to do is do db. verion and we're going to say the first version of this will have stores and to Define our stores here we don't actually need to Define any individual fields in our table we first say here's what our table is and then here's what the indexes are and here's what the primary key is so we're going to have a table named invoices and invoices is going to have a primary key which was defined by Plus+ and we'll say ID comma and then anytime we need to search on something and um load data we'll want to have an index as well the only other thing we're going to be doing on this is the date field in which we're going to be using okay now from here we can say

export DB that's it that's how we create our database using uh dexi here we'll come back to the this in a second so that way we get full typescript support on this but let's head to our data now I mentioned that we're going to be building an application based on this invoice application the invoice application is a lot of text Fields like a lot a lot of text fields and that's going to get confusing for you as we do this so we're going to keep it to two fields which is an invoice number and a name okay just a straightup name and that's going to allow us to focus on the local first techniques and then once you want to dive in deeper you can take a look at the invoice application that I built so we're going to say export const initial data and that's going to be equal to an object the object is going to have a single property of invoice which is going to be an empty

string eventually string of a number and name like this okay so that's our initial data now let's head back to our db. Ts that way we can use our initial data to inform the database what exactly the type of this thing is going to be so we're going to do types in a couple of ways so the first thing we're going to do is on our line three where we have our con DB we're going to say as dexi Amper sand like this and then we can Define what we have in here so we can say invoices now invoices is going to use a generic type entity table did I spell entity right yes I did entity table we can hover over this or select it with our Mouse and do command period and it's going to open up this quick fix where you can say update import from dexi otherwise you can

always just type type entity table in our import as well now this is going to take a couple of parameters one of which is going to be the primary key and another of which is going to be the shape of the data so let's define that shape of the data I'm going to export an interface invoice okay like so and this is going to have an ID property which is going to be a number and I have this as optionally undefined a date which is a string and a form data which is the type of initial data now once again let's select this and do a command period and import from the data you'll see this is import type initial data from data and we can say hey the form data is going to be in the shape of the initial data and likewise what we can do is now say in our entity table generic we can say it

will be the type of invoice with the primary key of A String of ID and just like that our database is going to now have knowledge about what the shape of our data will be the entire time okay I'll Linger on this you can pause it here if you'd like all right and same with this because now now it's time for the fun stuff we're going to start building our application and we to First do so where we get this data storing and saving into a database then we're going to be able to load the data from the database then we're going to set up automatic syncing then we're going to set up the export stuff and the service worker sound good let's get going okay so now let's get to the fun stuff the first thing I'm going to do here is add a script tag inside of our page . spelt this is just the main route I'm going to make sure this has a lang. TS on here that's going to make sure that we get typescript support in the file if you're a react fan this could be considered the body of the your function for the component right this is where we do the stuff inside of the

Chapter 4 10:26

Scripts and HTML

component now I'm going to be adding some State here and we're going to be using spelt 5 now I'm going to call out the the things that make spelt 5 State different so you can follow along with your use State and react the first thing we want to do is bring in our form data and have it be set to the initial data we created now form data is going to be equal to State and that state is going to be initial data now the initial data hasn't been imported so if we have it selected we can always do command period add import or just type that import ourself now one thing to know about this since we're using an object for our initial data this goes for any frend framework react felt whatever if you set this data into State and you modify that object it's actually going to be modifying the object reference so if you modify the state it's going to be modifying the initial data object which causes problems down the line so we're going to be running a structured clone on this thing structured clone is a function that's

built into the browser and the node and it allows you to create a clone now if you need support going back before you know 2022 or something uh you'll want to use something that is a little bit more robust for this application not too worried about using structured clone here you can always bring in a structured clone Library if you'd like for that more uh deep support now we're also going to be setting a status and status is going to be set to loading now I like using a status variable here for our state instead of like a is loading State I think it just works quite a bit better um we can say loading or ready for our potential types that way we don't try to do operations while the data is still being loaded next I'm going to also have um uh one more here which is going to be let

loaded ID which is going to be equal to um well the type is going to be either a number or undefined um and I'll even draw null in here since we'll have a default of null and this is going to be equal to state of null now in felt this dollar sign state is very very similar to The Ed State the only difference is it doesn't spit out a function and the state it just spits out the state and you mutate the state directly it's all done through proxies where react you do use State and have the function to update your state okay so that's going to be the the small caveat and the difference between how we approach state in react vers felt here okay so let's come down and let's write our HTML now to at least get this started I'm going to have a section here inside of our section will be an H1 that just says invoice voice I'm then going to have a div for each row of the form as well as a div to encapsulate them inside of the first form row is going to

be a label and this is going to be for invoice and the label name is going to be invoice number from here we're going to have an in input input type of text and it's going to be an ID of invoice and this is where a little bit of this felt magic comes in we're going to bind the value so bind value form dat.

invoice takes that form data state that we have and it's going to automatically update that state anytime this changes uh react folks have to have an onchange function to update the state or use a form library of you're choosing okay we can copy and duplicate this row I did that by selecting it and hitting shift option and hitting the down key in case you've never done that I'm going to have name name name and then bind value name just change all the words invoice to name okay pretty simple now the last thing we're going to want to do here is have a section up top here for some controls I'm going to have a button that is just save because we're really getting to the point where we can start interacting with this thing now in fact in fact if we head to our invoice you can see it looks like this we can obviously type in here Scott

Chapter 5 14:47

Saving Data

there we go works right nothing crazy so let's get into actually saving this into our database which is really why we're here right so we're going to have an async function and this is save async function save this save function will undergo some changes so it's going to be a little primitive right now but the first thing we're going to want to do in our save function is we're going to say const new invoice ID is going to be equal to await db. invoices. add like this now the first property we're going to add on here remember that we needed a date field that date field is going to be equal to a new date. 2 ISO string and then the next one is going to be form data now you might be wondering why we're not getting autoc completion here that's because I didn't import the DB yet if we have this selected we can

always do command period import DB like this um and here you can see that typescript is saving us because I wrote data instead of date uh that's a classically the type of thing I would do now we're obviously going to be wanting to pass the form State into this uh method here the ad method but this is a spelt specific thing folks react you can just pass in the form sta with spelt because the state is a proxy we need to do this fancy dollar sign state.

snapshot which will grab a snapshot of the state at that second instead of using the proxy so we're going to get the snapshot of our state form data and save into the database next thing we're going to do is we're going to set the loaded ID is going to be equal to our is going to be equal to our new invoice ID like this nice next we can add the onclick and call Save on click now we now have a form that can work in our local DB and save this data so for instance if I say you know like this and before I click save on this let's head to our Dev tools we're going to be spending a lot of time in the application tab of the dev tools you'll see that we have our index DB here and none of them are the ones that we named so when we click save here fingers cross this gets saved to our data base and just like that you can see we do have an

invoice local and inside of here you can see the information we saved including all of the form data that's pretty amazing right that's super amazing but I refreshed the page and it's gone um let's in fact add another one just for just for fun I'm going to say name is Wes you can see it says our data is stale we can click the refresh here and now all of our data is here okay so we're now able to store in our local DP that's great what's next well we want to be able to load any individual invoice we have to do that we want to first load all of the invoices from the data put them in a select list and then we're going to be able to toggle that select list to choose which one we're loading okay it's going to be a lot of fun it's going to be super easy so let's go ahead the first thing we're going want to do is create one more State variable this will be the last one and this will be all invoices is equal to a empty array the type of this is

Chapter 6 18:11

Loading Data

going to be the invoice type that we made earlier on we can import that there we go type invoice and it's going to be an array of those so it's all invoices here next thing we want to do is create a function to async Lo uh function load oh load all invoices and this is going to be a really simple function all invoices is equal to await DB do and again this is where we get this awesome typescript help invoices Dot and this time we're going to do order by order them by the date dot to array that way we get them in an array pop them into our all invoices state next thing we want to do is write an effect so that way this load all invoices runs when the component mounts okay so we can do dollar sign effect like this

and load all invoices now react folks this is the exact same as a use effect with an empty dependency array that's it so if you do use effect empty dependency array load all invoices that's the same right cool so this is going to run now every single time our component mounts and that's great we'll also want it to run every single time we add a new or save an invoice to our dat into our database okay cool cool cool cool let's go ahead and now write the select list that shows all of our invoice numbers I'm going to do so in our controls area and in fact this is going to get a little crowded but some of this stuff will be removed eventually so we'll say select the name is going to be all invoices ID is going to be all invoices and we're going to do an um each Loop here so we're going to say each of the all

invoices as invoice is going to be an option with a value of the individual ID and the date is going to be what's displayed in the select list okay if we come here we can now see that select list of all of the invoices we have created toggling them does nothing so let's go ahead and add event here we're going to say on change and on change what we're going to want to do is load invoice okay load invoice is a function that does not exist so let's write it this is going to be how we load a single invoice function load invoice from the select event okay what we're going to want to be doing is using the actual event from the select list so we can Target the const select is equal to event. Target as an HTML select we're also going to want to say the const ID

is equal to and the first thing we're want to do is check to see if select. value exists it should exist but we you know doesn't hurt to check we're going to say parse in selected value or none so if uh the selected value exists parse it as an INT or set it to null that way we can do if ID is truthy then what we'll want to do is one get the selected invoice selected invoice invoice is going to be equal to await and then we can grab the latest one dot getet dot ID okay now we'll check to see if selected invoice actually exists in the database right if the it actually existed what we're going to want to do is we're going to first set our

form underscore data is equal to the selected do form data and I'll run through this again once we're done um sorry not selected selected invoice there we go and then also the loaded ID is going to be equal to the selected invoice ID now to top this all off let's go ahead and add our status so before we do anything we're going to set to loading and then after we're done we're going to set to status of ready now there's other states you could have like an error State and stuff like that this is going to be kind of naive okay so this is going to run every single time this um every single time the select list has changed it's going to look at the select list itself it's going to grab the value if that value exist parse it as an integer if that exists grab it from the database if the database record exists update our state with a new data so let's go ahead and

change this you can see Wes and Scott nice it's now loading our state directly from index DB and it's instant so not even to hit the network for this now one addition to this that I want to make is that when we refresh I want it to always load the most recent invoice so we can create another async function load recent invoice now this is going to be a somewhat simple function as well although we want the loading state in here here so we're going to say status is equal to loading first and foremost and then we're going to do const most recent invoice is going to be equal to await db.

invoices. order by and we're going to order them by date and get the last one get the most recent one okay co-pilot helping me out here if most recent invoice actually exists then set the form data to the most invoice. formdata loaded ID to the most recent invoice ID now just like our load all invoices in the effect we'll want this to run on Mount when we make that change you can see it always loads the most recent one however one thing you'll notice is that the select list state is out of sync from what's actually loaded so we'll want to set the initial value of the select list to be the loaded ID notice how we're not binding this value we don't want it to update the value we just want it to set the initial value okay now now when we use this thing it's actually the correct one perfect so good cool awesome okay so this is really

great we now have the ability to load new invoices and load all of the invoices and select a new one that's really amazing but how do we create a new invoice now because you'll see here we're kind of stuck in this trap and if we were to click save actually one of these what would happen well check this out in fact if we click save on Scott now we end up having three invoices two of which are the exact same so we'll want to adjust that functionality so the next thing we're going to want to be doing here is we're going to be able to create a new invoice update the invoices we have get Autos saving working then get the export data and the offline stuff going so a lot of stuff to do here but you can already see the potential of working with this local data and how easy it can be okay so let's get going on all of that the first thing we want to have is a new invoice so we can say new invoice and this is actually sorry

function new invoice this is the first one that doesn't need to be an async function and all we're going to do is simply set loaded ID to null and the form data is going to be once again a structured clone of our initial data and then we're going to want to have a button down here button new invoice this is going to have an onclick of running the new invoice function so now you'll see that any given time we click new invoice it resets the form I can put in my number here and I can say CJ and click save from there you can see I now have Scott Wes and CJ I click new invoice let's do one more who cares and we can say Caitlyn and we can say save brilliant right it's now creating a new invoice every single time we tell it to and each time it saves it it well right now it will actually create a new invoice if we save it so let's go ahead

and fix that in our save function now the save function is going to be kind of what you imagine it to be where we're going to check to see if the ID exists in fact if loaded ID exist if we currently have one loaded we don't want to create one we want to update it otherwise we'll want to go ahead here and create a new one and then run load all invoices so loaded ID if loaded ID exists already we'll want to do a simple db.

invoices. update where we're going to pass in the loaded ID as the Pam we're going to grab the data as a snapshot and then the date since this is going to be considered an updated Act is going to be named the new date ISO string so just like if we were creating a new one we'll update the date so we're going to take a snapshot of the data just like we had if the loaded ID exists otherwise will we create a new one so let's go ahead and change Caitlyn's to 111222 click save and hopefully it has not created a new one which you can see it hasn't and Caitlyn has been updated now this sets us up really nicely for for the autosave functionality that we want to do so let's get the Autos saving working now Autos saving is going to be kind of interesting because we are going to be using a use effect inside of this and the use effect is going to be a little bit different than how react does it but I I'll tell you about it we're going to

Chapter 7 28:30

Auto Save

create another effect and this effect is going to call our save function anytime there's been a modification to our state so in react you could think of this as if we had our state in the dependency array then this function would run so if our status is equal to ready okay so we want to make sure that this it's not in the loading State before calling this we're going to want to call Save and we're going to want to call Save if the form data has changed now this gives us an opportunity to optimize here because we can do state. snapshot as well in here and snapshot our data at this point that way we won't have to do it later now we get the squiggly cuz save is not looking for any sort of data okay that's fine we'll fix that in a second but now what this is essentially saying is anytime form data has updated run this

function and that function is safe just like we had with the button and we'll take a form actually let's just call this data like this and it's going to be the type of form data I'm sorry type of initial data here we go there we go type of initial data and this data we're going to be using instead of snate state. snapshot form data this is already the snapshot so we can just replace both of those like that and that's it folks every single time we update this data inside of here it's going to save so you can see 333 I'm not going to have to click save I'm going to go to another invoice CJ's I'm going to come back and you can see that 333 has been updated again I can say CJ is is dope I can come back to Caitlyn I can come back to CJ and it maintains that and likewise if I refresh CJ is dope has now been the most updated one and

therefore it is loading first so anytime you make a modification just like that there's no network request that you have to worry about so you don't have to sit and wait for this stuff to happen it just happens on Save that's incredible this is really amazing and we now have ourselves into a really nice state where this data is always being saved and synced locally so what else is left to do right we've created invoices they save automatically we can load new ones we can create new ones what else do we have to do here well we want to get ourselves working offline and we want to be able to export the data as well so let's first get the working offline working now I will say this is going to be different no matter what platform you are working in and even if you're working in v in other their applications this might be different I'm going to be grabbing the default service worker directly from spel Kit's website if you're using nextjs or using V and

Chapter 8 31:00

Offline

different capacity there's a pwa plugin um I know uh there's a lot of documentation on how to get a service worker working and the basic service worker because that's all we really need right now we just need the ability to run these files cached when we're not online now this copy button is kind of broken on here or at least is for me so I'm going to zoom out and just copy this entire service worker from these felt kit docs you can grab this on the kit.

felt. deev service worker if you're following along and what we need to do is save this in fact let me grab the whole thing I'm going to put it into ajs file even though we're doing TS just so I don't have to worry about our types and I'm going to copy it like this from here I'm going to head into our source folder and I'm going to create a new file service hyphen worker.

JS paste this in here and again you'll want to find how to make a service worker or even a generic service worker for your application to get this up and running now when I come back here you can see it's already kind of doing something because when I select service workers for my application you can see that a service worker has been loaded okay that's that's it all the service worker is doing and this might look mysterious to you you can get in here what it's essentially doing is it's finding all of the assets that your application normally has to download from the network or even from your local file system and it's caching those individual files as individual paths that way when the network tab comes in and this stuff loads in fact let's turn off this disable cache first so this make sure this is not selected now before we do anything else you want to make sure that this says status active and running if it's not one thing you can try to do is hit unregister and refresh this page if you're not getting a full green light here because that

means that it uh for whatever reason you know sometimes multiple service workers can get installed on a specific URL it there's it's kind of a mess sometimes with service workers but as long as we have this active and running right here it's working for that said if we head to our Network here and we now refresh make sure your disabled cash has been turned off what you want to see before this is working is down here in the size you want to see it says service worker right here okay if it says service worker right here you know you're ready to go offline we can change that by up top here where it says no throttling we can select offline we can now refresh and check it out our application works not only does it work but it loads every bit of data that we wanted it to from the very start you can modify anything I don't even have to click save in fact we can remove that save button entirely now and this whole thing works the exact same way it does offline as it

does online and if we turn the application back to online nothing changes the data is all being stored locally nothing is being hitting the network the only thing the service worker is doing for us is saving the files that we typically load from the well potentially from the network but loading them from your browser's cach instead it's incredible so we now have this working offline we have it saving automatically uh last step is to get this exporting data and we're good to go okay so let's do that and this is going to be easier than you might expect essentially what we're going to be doing here is creating a fictional button and we're going to be creating a blob and then passing that blob into a click so that way we can save this as Json I mean we already have the data as a JavaScript object getting it into a Json shouldn't be too tough um actually one thing I'm going to do before we do that is remove this save button entirely that way we don't get it confused considering it's nonfunctional anyways okay let's get

Chapter 9 34:50

Exporting Data As JSON

this going here we're going to write a new function called e export and so this is going to be async export um sorry async function export okay like this now this function is going to be fun we're going to throw this into a tri catch right um just because and I'll put an error in case there is one okay so inside of this try catch the very first thing we're going to want to do is we're going to grab the latest all invoices from our database just so we get fresh data no matter what so we say const all invoices export is equal to let me remove that sidebar and we can do DB invoices to array now I'm not worrying about the order in which they're coming out of here but if you want to you can next thing we're going to do is create a

Json string is is going to be equal to json. stringify all invoices export if you want this to look like actual Json and be structured you want to say comma null comma 2 this allows it to be indented by two so you'll get an indented file okay next thing we'll want is a blob that blob is going to be equal to a new blob that new blob is going to take in an array where we have Json string as the first param here and then the type of it is going to be application. Json so we're creating a actual Json file let me make this full screen so we can see it then we're going to create a URL for this using URL create object URL and pass in the blob it seems like co-pilot wants to do this for me but we're going to do it together next we're going to create a link which is going to be a document.createelement and that's going to be an anchor we're going to add the

URL the one that we created for the blob to the link href then we're going to set link. download equal to invoices. Json that way it knows how to name this file and also it'll initiate a download for this instead of linking to the file then we're going to document.body aen child link. click document body remove child and then simply URL revoke URL so what are we doing and actually I noticed something stupid I call this export let's call it something export data exports a reserved word in JavaScript that's why we're getting those red underlines okay so we're getting all the data we're setting it to Json we're creating a blob out of that Json we're turning that into a URL we're then creating a link for the Dom we're setting the URL we're making sure it

downloads to a Json file then we're appending that to the body we're clicking it and then immediately removing it from the body and then nuking that URL from existence okay that's it so I'm going to head now and uh down here we're going to create a new button called export and this is going to be onclick export data this is the last thing we need to do and then we're done uh it's going to be pretty amazing here so if we head to our browser and we click export you'll see it seems like it worked okay now before I I conclude that it works let's go ahead and load it up in VSS code and make sure that this worked so I have my invoices file I'm going to open it up and just like that I have a valid Json file with all of the data now you can see how this could work where you then write an import function that takes this Json and loads it into your state and then saves it into the database that wouldn't be too hard and in fact I want

to issue you a challenge I want to see what you can do with this can you build the rest of the invoice functionality out in fact you can take a look at mine if you want any helpers or also you can also choose to try to have the opportunity to write an importer function for this as well those are great ways to practice working with local data now in further videos what I'm going to be talking about in the local first world here are some of the things that we're going to be doing we're going to be talking about using replic cache to store not only data but messages is about how that data should be updated and synced in the back end and then we're going to be writing a real backend server for that where we can store things in a legitimate real database and get control over that how that data is syncing what updates what and versioning that data so that way we can sync our data offline to a database that will always update what we're

actually loading so anytime you refresh or modify anything you'll get fresh data when you come back online and that way it's not all just local now one last thing before we get going there's an opportunity where your data can become well wrong and the data in the database is now off from what you actually wanted to have I want to show you just really quick anytime we're working with an index DB you can select that index DB and select delete database that's it and in fact once we do the syncing system you'll be able to delete that database refresh and the application will recreate it on its own so if you're interested in more local first content let me know I'm doing a ton of this stuff from Full stack local first platforms to writing your own to the fullest extent to just working on offline only like we did here I think this is a really awesome way to write software and you now have an application that is private offline Works Lightning Fast every single time and will work

under any network conditions as always this is Scott from syntax thank you so much for for watching if you enjoyed this let me know leave a comment below everything you thought about this video this content and more happy to hear from you and I can't wait to create more local first content for you and if you want to see this in any other language for instance interpolating this to react might be a little bit too hard I can go ahead and work on this exact same tutorial in a full react system if you would like as well thanks so much for watching and I'll see you in the next one

Quote it with credit and a link. Quoting Syntax